16 public const string LatestVersion =
"3.0.7";
17 internal static string GetBundleAppName(
string version = LatestVersion)
18 => (plat: EnvironmentInfo.Platform, arch: RuntimeInformation.OSArchitecture)
switch
20 (PlatformFamily.Windows, Architecture.X64) => $
"xmake-bundle-v{version}.win64.exe",
21 (PlatformFamily.Windows, Architecture.X86) => $
"xmake-bundle-v{version}.win32.exe",
22 (PlatformFamily.Windows, Architecture.Arm64) => $
"xmake-bundle-v{version}.arm64.exe",
23 (PlatformFamily.Linux, Architecture.X64) => $
"xmake-bundle-v{version}.linux.x86_64",
24 (PlatformFamily.OSX, Architecture.Arm64) => $
"xmake-bundle-v{version}.macos.arm64",
25 (PlatformFamily.OSX, Architecture.X64) => $
"xmake-bundle-v{version}.macos.x86_64",
26 var other =>
throw new Exception($
"Trying to use XMake on an unsupported platform: {other.plat} {other.arch}")
31 not found main script\:\s(?<PATH>.*)\/core.*\.lua
33 RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture
35 private static partial Regex ProblematicMainXMakeFolder();
37 internal static AbsolutePath? GetProblematicMainXMakeFolder(
this Output line)
39 var text = line.Text.Replace(
'\\',
'/').Replace(
"//",
"/");
40 var result = text.Parse(ProblematicMainXMakeFolder(), forceNullOnWhitespce:
true)(
"PATH");
41 return result.TryAsPath();
49 var bundleAppName = GetBundleAppName(version);
50 var xmakePath = NukeBuild.TemporaryDirectory / bundleAppName;
51 if (!xmakePath.FileExists())
53 Log.Information(
"Downloading XMake {0}", bundleAppName);
54 HttpTasks.HttpDownloadFile(
55 $
"https://github.com/xmake-io/xmake/releases/download/v{LatestVersion}/{bundleAppName}",
61 retry: (tool, process, attempt) =>
63 if (process.ExitCode == 0 || attempt >= 2)
return null;
64 foreach (var line
in process.Output)
66 var mainXMakeFolder = line.GetProblematicMainXMakeFolder();
67 if (mainXMakeFolder !=
null)
69 Log.Information(
"A known issue has occured with XMake where it cannot use {0}", mainXMakeFolder);
70 Log.Information(
"Remove it and have another attempt {0}", attempt + 1);
71 mainXMakeFolder.Parent.DeleteDirectory();
80 public static ValueOrError<ToolEx> EnsureXMake =>
TryGetXMake();