Skip to content

Commit

Permalink
Merge commit '006dc256ca772ed837496f81b55d15038924b679' as '.scripts/…
Browse files Browse the repository at this point in the history
…X2ModBuildCommon'
  • Loading branch information
Iridar committed Nov 17, 2021
2 parents d9d17fc + 006dc25 commit 5865743
Show file tree
Hide file tree
Showing 9 changed files with 2,069 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .scripts/X2ModBuildCommon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Next

## 1.1.1 (2021-08-11)

* Support Rebuild ModBuddy target
* Internal improvements and fixes to asset cooking functionality
* Support projects with spaces in path (#55)
* Fix cryptic error about `SteamPublishID` for some projects (#56)
* Fail the build in case cooking cleanup fails, preventing silent SDK corruption (#54)
* Properly rewrite error messages originating from `IncludeSrc`-ed files (#45)


## 1.1.0 (2021-06-15)

* Remove compiled script packages when switching between debug and release mode to prevent compiler error (#16)
* Remove compiled script packages when modifying macros (#20)
* Overridden Steam UGC IDs can now be `long` (`int64`) (#22)
* Use error syntax `file(line)` for compiler errors to be compatible with both ModBuddy and VS Code (#26)
* Add a `clean.ps1` script, ModBuddy configuration and VS Code example task to remove all cached build artifacts (#24)
* Remove project file verification. Consider using [Xymanek/X2ProjectGenerator](https://github.com/Xymanek/X2ProjectGenerator) instead (#28)
* Catch macro name clashes through `extra_globals.uci` (#30)
* Add debugging option to profile build times (#35)

## 1.0.0 (2021-05-22)

* Initial release
Binary file added .scripts/X2ModBuildCommon/EmptyUMap
Binary file not shown.
122 changes: 122 additions & 0 deletions .scripts/X2ModBuildCommon/InvokePowershellTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.IO;
using System.Threading;
using System.Management.Automation;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

public class InvokePowershellTask : Task, ICancelableTask
{
[Required] public string EntryPs1 { get; set; }
[Required] public string SolutionRoot { get; set; }
[Required] public string SdkInstallPath { get; set; }
[Required] public string GameInstallPath { get; set; }
[Required] public ITaskItem[] AdditionalArgs { get; set; }

private PowerShell _ps;

private ManualResetEventSlim _startingMre = new ManualResetEventSlim(false);

public override bool Execute()
{
bool isSuccess = false;

try
{
_ps = PowerShell.Create();

_ps
.AddCommand("Set-ExecutionPolicy")
.AddArgument("Unrestricted")
.AddParameter("Scope","CurrentUser");

_ps
.AddStatement()
.AddCommand(EntryPs1)
.AddParameter("srcDirectory", TrimEndingDirectorySeparator(SolutionRoot))
.AddParameter("sdkPath", TrimEndingDirectorySeparator(SdkInstallPath))
.AddParameter("gamePath", TrimEndingDirectorySeparator(GameInstallPath));

foreach (ITaskItem Arg in AdditionalArgs)
{
string Val = Arg.GetMetadata("Value");
if (string.IsNullOrEmpty(Val))
{
_ps.AddParameter(Arg.ItemSpec);
}
else
{
_ps.AddParameter(Arg.ItemSpec, Val);
}
}

BindStreamEntryCallback(_ps.Streams.Debug, record => LogOutput(record.ToString()));
BindStreamEntryCallback(_ps.Streams.Information, record => LogOutput(record.ToString()));
BindStreamEntryCallback(_ps.Streams.Verbose, record => LogOutput(record.ToString()));
BindStreamEntryCallback(_ps.Streams.Warning, record => LogOutput(record.ToString())); // TODO: More flashy output?

BindStreamEntryCallback(_ps.Streams.Error, record =>
{
// TODO: Less info than when from console
// TODO: More flashy output?
LogOutput(record.ToString());
Log.LogError(record.ToString());
isSuccess = false;
});

_ps.InvocationStateChanged += (sender, args) =>
{
if (args.InvocationStateInfo.State == PSInvocationState.Running)
{
_startingMre.Set();
}
};

isSuccess = true;
_ps.Invoke();
}
catch (System.Exception e)
{
Log.LogError(e.Message);
isSuccess = false;
}

return isSuccess;
}

public void Cancel()
{
// Log.LogMessage(MessageImportance.High, "Got cancel");

// Do not call Stop() until we know that we've actually started
// This could be more elaborate, but the time interval between Execute() and Invoke() being called is extremely small

_startingMre.Wait();
_ps.Stop();
}

private void LogOutput (string output)
{
// This is required to keep the empty lines in the output
if (string.IsNullOrEmpty(output)) output = " ";

Log.LogMessage(MessageImportance.High, output);
}

private static readonly char[] DirectorySeparatorsForTrimming = new char[]
{
Path.DirectorySeparatorChar,
Path.AltDirectorySeparatorChar
};

private static string TrimEndingDirectorySeparator(string path)
{
return path.TrimEnd(DirectorySeparatorsForTrimming);
}

private static void BindStreamEntryCallback<T>(PSDataCollection<T> stream, Action<T> handler)
{
stream.DataAdded += (object sender, DataAddedEventArgs e) => handler(stream[e.Index]);
}
}
21 changes: 21 additions & 0 deletions .scripts/X2ModBuildCommon/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 X2CommunityCore

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 5865743

Please sign in to comment.