Skip to content

Commit 5865743

Browse files
committed
Merge commit '006dc256ca772ed837496f81b55d15038924b679' as '.scripts/X2ModBuildCommon'
2 parents d9d17fc + 006dc25 commit 5865743

File tree

9 files changed

+2069
-0
lines changed

9 files changed

+2069
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Next
2+
3+
## 1.1.1 (2021-08-11)
4+
5+
* Support Rebuild ModBuddy target
6+
* Internal improvements and fixes to asset cooking functionality
7+
* Support projects with spaces in path (#55)
8+
* Fix cryptic error about `SteamPublishID` for some projects (#56)
9+
* Fail the build in case cooking cleanup fails, preventing silent SDK corruption (#54)
10+
* Properly rewrite error messages originating from `IncludeSrc`-ed files (#45)
11+
12+
13+
## 1.1.0 (2021-06-15)
14+
15+
* Remove compiled script packages when switching between debug and release mode to prevent compiler error (#16)
16+
* Remove compiled script packages when modifying macros (#20)
17+
* Overridden Steam UGC IDs can now be `long` (`int64`) (#22)
18+
* Use error syntax `file(line)` for compiler errors to be compatible with both ModBuddy and VS Code (#26)
19+
* Add a `clean.ps1` script, ModBuddy configuration and VS Code example task to remove all cached build artifacts (#24)
20+
* Remove project file verification. Consider using [Xymanek/X2ProjectGenerator](https://github.com/Xymanek/X2ProjectGenerator) instead (#28)
21+
* Catch macro name clashes through `extra_globals.uci` (#30)
22+
* Add debugging option to profile build times (#35)
23+
24+
## 1.0.0 (2021-05-22)
25+
26+
* Initial release
5.08 KB
Binary file not shown.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading;
4+
using System.Management.Automation;
5+
6+
using Microsoft.Build.Framework;
7+
using Microsoft.Build.Utilities;
8+
9+
public class InvokePowershellTask : Task, ICancelableTask
10+
{
11+
[Required] public string EntryPs1 { get; set; }
12+
[Required] public string SolutionRoot { get; set; }
13+
[Required] public string SdkInstallPath { get; set; }
14+
[Required] public string GameInstallPath { get; set; }
15+
[Required] public ITaskItem[] AdditionalArgs { get; set; }
16+
17+
private PowerShell _ps;
18+
19+
private ManualResetEventSlim _startingMre = new ManualResetEventSlim(false);
20+
21+
public override bool Execute()
22+
{
23+
bool isSuccess = false;
24+
25+
try
26+
{
27+
_ps = PowerShell.Create();
28+
29+
_ps
30+
.AddCommand("Set-ExecutionPolicy")
31+
.AddArgument("Unrestricted")
32+
.AddParameter("Scope","CurrentUser");
33+
34+
_ps
35+
.AddStatement()
36+
.AddCommand(EntryPs1)
37+
.AddParameter("srcDirectory", TrimEndingDirectorySeparator(SolutionRoot))
38+
.AddParameter("sdkPath", TrimEndingDirectorySeparator(SdkInstallPath))
39+
.AddParameter("gamePath", TrimEndingDirectorySeparator(GameInstallPath));
40+
41+
foreach (ITaskItem Arg in AdditionalArgs)
42+
{
43+
string Val = Arg.GetMetadata("Value");
44+
if (string.IsNullOrEmpty(Val))
45+
{
46+
_ps.AddParameter(Arg.ItemSpec);
47+
}
48+
else
49+
{
50+
_ps.AddParameter(Arg.ItemSpec, Val);
51+
}
52+
}
53+
54+
BindStreamEntryCallback(_ps.Streams.Debug, record => LogOutput(record.ToString()));
55+
BindStreamEntryCallback(_ps.Streams.Information, record => LogOutput(record.ToString()));
56+
BindStreamEntryCallback(_ps.Streams.Verbose, record => LogOutput(record.ToString()));
57+
BindStreamEntryCallback(_ps.Streams.Warning, record => LogOutput(record.ToString())); // TODO: More flashy output?
58+
59+
BindStreamEntryCallback(_ps.Streams.Error, record =>
60+
{
61+
// TODO: Less info than when from console
62+
// TODO: More flashy output?
63+
LogOutput(record.ToString());
64+
Log.LogError(record.ToString());
65+
isSuccess = false;
66+
});
67+
68+
_ps.InvocationStateChanged += (sender, args) =>
69+
{
70+
if (args.InvocationStateInfo.State == PSInvocationState.Running)
71+
{
72+
_startingMre.Set();
73+
}
74+
};
75+
76+
isSuccess = true;
77+
_ps.Invoke();
78+
}
79+
catch (System.Exception e)
80+
{
81+
Log.LogError(e.Message);
82+
isSuccess = false;
83+
}
84+
85+
return isSuccess;
86+
}
87+
88+
public void Cancel()
89+
{
90+
// Log.LogMessage(MessageImportance.High, "Got cancel");
91+
92+
// Do not call Stop() until we know that we've actually started
93+
// This could be more elaborate, but the time interval between Execute() and Invoke() being called is extremely small
94+
95+
_startingMre.Wait();
96+
_ps.Stop();
97+
}
98+
99+
private void LogOutput (string output)
100+
{
101+
// This is required to keep the empty lines in the output
102+
if (string.IsNullOrEmpty(output)) output = " ";
103+
104+
Log.LogMessage(MessageImportance.High, output);
105+
}
106+
107+
private static readonly char[] DirectorySeparatorsForTrimming = new char[]
108+
{
109+
Path.DirectorySeparatorChar,
110+
Path.AltDirectorySeparatorChar
111+
};
112+
113+
private static string TrimEndingDirectorySeparator(string path)
114+
{
115+
return path.TrimEnd(DirectorySeparatorsForTrimming);
116+
}
117+
118+
private static void BindStreamEntryCallback<T>(PSDataCollection<T> stream, Action<T> handler)
119+
{
120+
stream.DataAdded += (object sender, DataAddedEventArgs e) => handler(stream[e.Index]);
121+
}
122+
}

.scripts/X2ModBuildCommon/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 X2CommunityCore
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)