Skip to content

Commit 6b95dfb

Browse files
committed
Move 7zip download & extraction into build process
Use local 7z when not running on yamato
1 parent f7ece74 commit 6b95dfb

12 files changed

+76
-50
lines changed

.yamato/build_linux_x64_debug.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-linux-x64.7z
1212

1313
commands:
14-
- mkdir artifacts
15-
- curl https://public-stevedore.unity3d.com/r/public/7za-linux-x64/e6c75fb7ffda_e6a295cdcae3f74d315361883cf53f75141be2e739c020035f414a449d4876af.zip --output artifacts/7za-linux-x64.zip
16-
- unzip artifacts/7za-linux-x64.zip -d artifacts/7za-linux-x64
1714
- ./.yamato/scripts/build_yamato.sh Debug
1815

1916
artifacts:

.yamato/build_linux_x64_release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-linux-x64.7z
1212

1313
commands:
14-
- mkdir artifacts
15-
- curl https://public-stevedore.unity3d.com/r/public/7za-linux-x64/e6c75fb7ffda_e6a295cdcae3f74d315361883cf53f75141be2e739c020035f414a449d4876af.zip --output artifacts/7za-linux-x64.zip
16-
- unzip artifacts/7za-linux-x64.zip -d artifacts/7za-linux-x64
1714
- ./.yamato/scripts/build_yamato.sh Release
1815

1916
artifacts:

.yamato/build_osx_arm64_debug.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-osx-arm64.7z
1212

1313
commands:
14-
- mkdir -p artifacts
15-
- curl https://public-stevedore.unity3d.com/r/public/7za-mac-x64/e6c75fb7ffda_5bd76652986a0e3756d1cfd7e84ce056a9e1dbfc5f70f0514a001f724c0fbad2.zip --output artifacts/7za-mac-x64.zip
16-
- unzip -o artifacts/7za-mac-x64.zip -d artifacts/7za-mac-x64
1714
- ./.yamato/scripts/build_yamato.sh arm64 Debug
1815

1916
artifacts:

.yamato/build_osx_arm64_release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-osx-arm64.7z
1212

1313
commands:
14-
- mkdir -p artifacts
15-
- curl https://public-stevedore.unity3d.com/r/public/7za-mac-x64/e6c75fb7ffda_5bd76652986a0e3756d1cfd7e84ce056a9e1dbfc5f70f0514a001f724c0fbad2.zip --output artifacts/7za-mac-x64.zip
16-
- unzip -o artifacts/7za-mac-x64.zip -d artifacts/7za-mac-x64
1714
- ./.yamato/scripts/build_yamato.sh arm64 Release
1815

1916
artifacts:

.yamato/build_osx_x64_debug.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-osx-x64.7z
1212

1313
commands:
14-
- mkdir -p artifacts
15-
- curl https://public-stevedore.unity3d.com/r/public/7za-mac-x64/e6c75fb7ffda_5bd76652986a0e3756d1cfd7e84ce056a9e1dbfc5f70f0514a001f724c0fbad2.zip --output artifacts/7za-mac-x64.zip
16-
- unzip -o artifacts/7za-mac-x64.zip -d artifacts/7za-mac-x64
1714
- ./.yamato/scripts/build_yamato.sh x64 Debug
1815

1916
artifacts:

.yamato/build_osx_x64_release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-osx-x64.7z
1212

1313
commands:
14-
- mkdir -p artifacts
15-
- curl https://public-stevedore.unity3d.com/r/public/7za-mac-x64/e6c75fb7ffda_5bd76652986a0e3756d1cfd7e84ce056a9e1dbfc5f70f0514a001f724c0fbad2.zip --output artifacts/7za-mac-x64.zip
16-
- unzip -o artifacts/7za-mac-x64.zip -d artifacts/7za-mac-x64
1714
- ./.yamato/scripts/build_yamato.sh x64 Release
1815

1916
artifacts:

.yamato/build_windows_x64_debug.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-win-x64.7z
1212

1313
commands:
14-
- powershell .yamato\scripts\download_7z.ps1
1514
- .yamato/scripts/build_yamato.cmd x64 Debug
1615

1716
artifacts:

.yamato/build_windows_x64_release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-win-x64.7z
1212

1313
commands:
14-
- powershell .yamato\scripts\download_7z.ps1
1514
- .yamato/scripts/build_yamato.cmd x64 Release
1615

1716
artifacts:

.yamato/build_windows_x86_debug.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-win-x86.7z
1212

1313
commands:
14-
- powershell .yamato\scripts\download_7z.ps1
1514
- .yamato/scripts/build_yamato.cmd x86 Debug
1615

1716
artifacts:

.yamato/build_windows_x86_release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ variables:
1111
ARTIFACT_FILENAME: {{globals.artifact_base_name}}-win-x86.7z
1212

1313
commands:
14-
- powershell .yamato\scripts\download_7z.ps1
1514
- .yamato/scripts/build_yamato.cmd x86 Release
1615

1716
artifacts:

unity/CITools/BuildDriver/Program.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ namespace BuildDriver;
55

66
public class Program
77
{
8-
public static int Main(string[] args)
8+
public static bool RunningOnYamato() => Environment.GetEnvironmentVariable("YAMATO_PROJECT_ID") != null;
9+
public static async Task<int> Main(string[] args)
910
{
1011
string architecture = GetArchitectures()[0]; // Get default arch for current system
1112
string configuration = "Release";
1213
bool silent = false;
14+
bool zip = RunningOnYamato();
15+
bool skipBuild = false;
16+
Task<NPath>? zipTask = null;
1317
foreach (string arg in args)
1418
{
1519
if ((arg.StartsWith("--arch") || arg.StartsWith("--architecture="))
@@ -18,8 +22,17 @@ public static int Main(string[] args)
1822
if ((arg.StartsWith("--config=") || arg.StartsWith("--configuration="))
1923
&& !TryParseArgument(new[] {"Release", "Debug"}, arg, out configuration))
2024
return 1;
21-
if (arg.Equals("--silent"))
25+
if (arg.Equals("--silent") || arg.Equals("--s"))
2226
silent = true;
27+
if (arg.Equals("--zip") || arg.Equals("--z"))
28+
zip = true;
29+
if (arg.Equals("--skip-build"))
30+
skipBuild = true;
31+
}
32+
33+
if (RunningOnYamato())
34+
{
35+
zipTask = SevenZip.DownloadAndUnzip7Zip();
2336
}
2437

2538
Console.WriteLine("*****************************");
@@ -30,13 +43,25 @@ public static int Main(string[] args)
3043
Console.WriteLine("*****************************");
3144

3245
GlobalConfig gConfig = new (){ Architecture = architecture, Configuration = configuration, Silent = silent};
33-
BuildEmbeddingHost.Run(gConfig);
34-
BuildNullGC.Run(gConfig);
35-
BuildCoreCLR.Run(gConfig);
46+
if (!skipBuild)
47+
{
48+
BuildEmbeddingHost.Run(gConfig);
49+
BuildNullGC.Run(gConfig);
50+
BuildCoreCLR.Run(gConfig);
51+
}
52+
3653
NPath artifacts = ConsolidateArtifacts(gConfig);
37-
NPath zipArtifact = new (Environment.GetEnvironmentVariable("ARTIFACT_FILENAME") ??
38-
$"dotnet-unity-{architecture}.7z");
39-
SevenZip.Create7z(artifacts, Paths.Artifacts.Combine(zipArtifact));
54+
55+
NPath zipExe = new("7z");
56+
if (zipTask != null)
57+
{
58+
zipExe = await zipTask;
59+
if (zipTask.Exception != null)
60+
throw zipTask.Exception;
61+
}
62+
63+
if (zip)
64+
SevenZip.Zip(zipExe, artifacts, gConfig);
4065

4166
return 0;
4267
}

unity/CITools/BuildDriver/SevenZip.cs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
using System.Diagnostics;
2+
using System.IO.Compression;
3+
using System.Net;
24
using System.Runtime.InteropServices;
35
using NiceIO;
46

57
namespace BuildDriver;
68

79
public class SevenZip
810
{
9-
public static NPath Create7z(NPath directory, NPath outputFile, string additional7zArguments = "")
10-
=> Create7z(Get7zPath(), directory, outputFile, additional7zArguments);
11-
12-
static NPath Create7z(NPath sevenZipPath, NPath directory, string outputFile, string additional7zArguments)
11+
public static NPath Create7z(NPath sevenZipPath, NPath directory, string outputFile, string additional7zArguments = "")
1312
{
1413
Console.WriteLine($"Creating .7z {outputFile}");
1514
var args = $"a {outputFile} *";
@@ -28,28 +27,52 @@ static NPath Create7z(NPath sevenZipPath, NPath directory, string outputFile, st
2827
return new NPath(outputFile);
2928
}
3029

31-
public static NPath Get7zPath()
30+
public static void Zip(NPath zipExe, NPath artifacts, GlobalConfig gConfig)
31+
{
32+
NPath zipArtifact = new (Environment.GetEnvironmentVariable("ARTIFACT_FILENAME") ??
33+
$"dotnet-unity-{gConfig.Architecture}.7z");
34+
SevenZip.Create7z(zipExe, artifacts, Paths.Artifacts.Combine(zipArtifact));
35+
}
36+
37+
public static void Get7ZipUrl(out string url, out string filename)
3238
{
33-
var artifacts = Paths.Artifacts;
34-
NPath GetArtifactsPath()
39+
string baseUrl = "https://public-stevedore.unity3d.com/r/public";
40+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
41+
{
42+
url = $"{baseUrl}/7za-linux-x64/e6c75fb7ffda_e6a295cdcae3f74d315361883cf53f75141be2e739c020035f414a449d4876af.zip";
43+
}
44+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
3545
{
36-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
37-
return artifacts.Combine("7za-win-x64/7za.exe");
46+
url = RuntimeInformation.OSArchitecture == Architecture.Arm64
47+
? $"{baseUrl}/7za-mac-arm64/e6c75fb7ffda_891473e6242d16ca181cee7c728b73f80c931f58de45ab79f376acd63d524151.zip"
48+
: $"{baseUrl}/7za-mac-x64/e6c75fb7ffda_5bd76652986a0e3756d1cfd7e84ce056a9e1dbfc5f70f0514a001f724c0fbad2.zip";
49+
}
50+
else
51+
url = $"{baseUrl}/7za-win-x64/38c5b39be2e8_a333cfccb708c88459b3812eb2597ca486ec9b416172543ca3ef8e5cd5f80984.zip";
3852

39-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
40-
{
41-
if (RuntimeInformation.OSArchitecture == Architecture.Arm64)
42-
return artifacts.Combine("7za-mac-arm64/7za");
43-
return artifacts.Combine("7za-mac-x64/7za");
44-
}
53+
filename = $"{url.Split('/').Single(s => s.StartsWith("7za"))}.zip";
54+
}
4555

46-
return artifacts.Combine("7za-linux-x64/7za");
56+
public static async Task<NPath> DownloadAndUnzip7Zip()
57+
{
58+
WebClient wc = new();
59+
string url, filename;
60+
Get7ZipUrl(out url, out filename);
61+
NPath zipDest = Paths.Artifacts.Combine(filename);
62+
zipDest.Parent.EnsureDirectoryExists();
63+
if (!zipDest.FileExists())
64+
{
65+
Console.WriteLine($"Starting download of 7zip: {filename}");
66+
wc.DownloadFile(url, zipDest);
4767
}
4868

49-
var path = GetArtifactsPath();
50-
if (path.FileExists())
51-
return path;
69+
NPath destDir = zipDest.Parent.Combine(zipDest.FileNameWithoutExtension);
70+
if (!destDir.DirectoryExists())
71+
{
72+
Console.WriteLine($"Extracting 7zip to: {destDir}");
73+
ZipFile.ExtractToDirectory(zipDest, destDir);
74+
}
5275

53-
return new NPath("7z");
76+
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? destDir.Combine("7za.exe") : destDir.Combine("7za");
5477
}
5578
}

0 commit comments

Comments
 (0)