Compare commits

..

No commits in common. "3fd8f41b351fb869c137febaf6a2ce038a3bca3d" and "1373859a13c9f265ed7a0b76234ae98e8e5513d7" have entirely different histories.

5 changed files with 34 additions and 64 deletions

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<Authors>Ellpeck</Authors> <Authors>Ellpeck</Authors>
<Description>A tool to package MonoGame and other .NET Core applications into several distributable formats</Description> <Description>A tool to package MonoGame and other .NET Core applications into several distributable formats</Description>
@ -14,7 +14,7 @@
<PackageIcon>Logo.png</PackageIcon> <PackageIcon>Logo.png</PackageIcon>
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>
<ToolCommandName>gamebundle</ToolCommandName> <ToolCommandName>gamebundle</ToolCommandName>
<VersionPrefix>1.5.0</VersionPrefix> <VersionPrefix>1.4.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -24,22 +24,9 @@ namespace GameBundle {
public string LinuxRid { get; set; } public string LinuxRid { get; set; }
[Option("mac-rid", Default = "osx-x64", HelpText = "The RID to use for mac builds")] [Option("mac-rid", Default = "osx-x64", HelpText = "The RID to use for mac builds")]
public string MacRid { get; set; } public string MacRid { get; set; }
[Option('W', "win-arm", HelpText = "Bundle for windows arm")]
public bool BuildWindowsArm { get; set; }
[Option('L', "linux-arm", HelpText = "Bundle for linux arm")]
public bool BuildLinuxArm { get; set; }
[Option('M', "mac-arm", HelpText = "Bundle for mac arm")]
public bool BuildMacArm { get; set; }
[Option("win-arm-rid", Default = "win-arm64", HelpText = "The RID to use for windows arm builds")]
public string WindowsArmRid { get; set; }
[Option("linux-arm-rid", Default = "linux-arm64", HelpText = "The RID to use for linux arm builds")]
public string LinuxArmRid { get; set; }
[Option("mac-arm-rid", Default = "osx-arm64", HelpText = "The RID to use for mac arm builds")]
public string MacArmRid { get; set; }
[Option('z', "zip", HelpText = "Store the build results in zip files instead of folders")] [Option('z', "zip", HelpText = "Store the build results in zip files instead of folders")]
public bool Zip { get; set; } public bool Zip { get; set; }
[Option('b', "mac-bundle", HelpText = "Create an app bundle for mac")] [Option('b', "mac-bundle", HelpText = "Create an app bundle for mac")]
public bool MacBundle { get; set; } public bool MacBundle { get; set; }
[Option("mac-bundle-resources", Default = new[] {"Content", "*.icns"}, HelpText = "When creating an app bundle for mac, things that should go into the Resources folder rather than the MacOS folder")] [Option("mac-bundle-resources", Default = new[] {"Content", "*.icns"}, HelpText = "When creating an app bundle for mac, things that should go into the Resources folder rather than the MacOS folder")]

View file

@ -32,40 +32,43 @@ namespace GameBundle {
Console.WriteLine($"Bundling project {proj.FullName}"); Console.WriteLine($"Bundling project {proj.FullName}");
var builtAnything = false; var builtAnything = false;
var toBuild = new List<BuildConfig> { if (options.BuildWindows) {
// regular builds Console.WriteLine("Bundling for windows");
new("windows", "win", options.WindowsRid, options.BuildWindows), var res = Publish(options, proj, GetBuildDir(options, "win"), options.WindowsRid);
new("linux", "linux", options.LinuxRid, options.BuildLinux), if (res != 0)
new("mac", "mac", options.MacRid, options.BuildMac, false, d => options.MacBundle ? CreateMacBundle(options, d) : 0), return res;
// arm builds builtAnything = true;
new("windows arm", "win-arm", options.WindowsArmRid, options.BuildWindowsArm, true),
new("linux arm", "linux-arm", options.LinuxArmRid, options.BuildLinuxArm, true),
new("mac arm", "mac-arm", options.MacArmRid, options.BuildMacArm, true, d => options.MacBundle ? CreateMacBundle(options, d) : 0)
};
foreach (var config in toBuild) {
if (config.ShouldBuild) {
Console.WriteLine($"Bundling for {config.DisplayName}");
var res = Publish(options, proj, config);
if (res != 0)
return res;
builtAnything = true;
}
} }
if (options.BuildLinux) {
Console.WriteLine("Bundling for linux");
var res = Publish(options, proj, GetBuildDir(options, "linux"), options.LinuxRid);
if (res != 0)
return res;
builtAnything = true;
}
if (options.BuildMac) {
Console.WriteLine("Bundling for mac");
var dir = GetBuildDir(options, "mac");
var res = Publish(options, proj, dir, options.MacRid,
() => options.MacBundle ? CreateMacBundle(options, dir, proj) : 0);
if (res != 0)
return res;
builtAnything = true;
}
if (!builtAnything) if (!builtAnything)
Console.WriteLine("No build took place. Supply -w, -l or -m arguments or see available arguments using --help."); Console.WriteLine("No build took place. Supply -w, -l or -m arguments or see available arguments using --help.");
Console.WriteLine("Done"); Console.WriteLine("Done");
return 0; return 0;
} }
private static int Publish(Options options, FileInfo proj, BuildConfig config) { private static int Publish(Options options, FileInfo proj, DirectoryInfo buildDir, string rid, Func<int> additionalAction = null) {
var buildDir = GetBuildDir(options, config.DirectoryName); var publishResult = RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{buildDir.FullName}\" -r {rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}");
var publishResult = RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{buildDir.FullName}\" -r {config.Rid} --self-contained -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}");
if (publishResult != 0) if (publishResult != 0)
return publishResult; return publishResult;
// Run beauty // Run beauty
if (!options.SkipLib && !config.SkipLib) { if (!options.SkipLib) {
var excludes = $"\"{string.Join(";", options.ExcludedFiles)}\""; var excludes = $"\"{string.Join(";", options.ExcludedFiles)}\"";
var log = options.Verbose ? "Detail" : "Error"; var log = options.Verbose ? "Detail" : "Error";
var beautyResult = RunProcess(options, "dotnet", $"ncbeauty --loglevel={log} --force=True --noflag=True \"{buildDir.FullName}\" \"{options.LibFolder}\" {excludes}", AppDomain.CurrentDomain.BaseDirectory); var beautyResult = RunProcess(options, "dotnet", $"ncbeauty --loglevel={log} --force=True --noflag=True \"{buildDir.FullName}\" \"{options.LibFolder}\" {excludes}", AppDomain.CurrentDomain.BaseDirectory);
@ -89,8 +92,8 @@ namespace GameBundle {
} }
// Run any additional actions like creating the mac bundle // Run any additional actions like creating the mac bundle
if (config.AdditionalAction != null) { if (additionalAction != null) {
var result = config.AdditionalAction.Invoke(buildDir); var result = additionalAction();
if (result != 0) if (result != 0)
return result; return result;
} }
@ -132,7 +135,7 @@ namespace GameBundle {
return null; return null;
} }
private static int CreateMacBundle(Options options, DirectoryInfo buildDir) { private static int CreateMacBundle(Options options, DirectoryInfo buildDir, FileInfo proj) {
var buildName = GetBuildName(options, buildDir); var buildName = GetBuildName(options, buildDir);
var app = buildDir.CreateSubdirectory($"{buildName}.app"); var app = buildDir.CreateSubdirectory($"{buildName}.app");
var contents = app.CreateSubdirectory("Contents"); var contents = app.CreateSubdirectory("Contents");
@ -193,25 +196,5 @@ namespace GameBundle {
return null; return null;
} }
private readonly struct BuildConfig {
public readonly string DisplayName;
public readonly string DirectoryName;
public readonly string Rid;
public readonly bool ShouldBuild;
public readonly bool SkipLib;
public readonly Func<DirectoryInfo, int> AdditionalAction;
public BuildConfig(string displayName, string directoryName, string rid, bool shouldBuild, bool skipLib = false, Func<DirectoryInfo, int> additionalAction = null) {
this.DisplayName = displayName;
this.DirectoryName = directoryName;
this.Rid = rid;
this.ShouldBuild = shouldBuild;
this.SkipLib = skipLib;
this.AdditionalAction = additionalAction;
}
}
} }
} }

View file

@ -1 +1 @@
"../GameBundle/bin/Debug/net6.0/GameBundle.exe" -wlmWL -bzn -s Test.csproj -o bin/Bundled -v --mac-bundle-ignore macmain.txt "../GameBundle/bin/Debug/net5.0/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v --mac-bundle-ignore macmain.txt

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<PublishReadyToRun>false</PublishReadyToRun> <PublishReadyToRun>false</PublishReadyToRun>
<TieredCompilation>false</TieredCompilation> <TieredCompilation>false</TieredCompilation>
<AssemblyName>Test Project</AssemblyName> <AssemblyName>Test Project</AssemblyName>