Skip to content

Commit 4302a8a

Browse files
committed
Add bee script to pull down required mono-build-deps from stevedore
1 parent 8ac9f63 commit 4302a8a

File tree

5 files changed

+261
-0
lines changed

5 files changed

+261
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ GTAGS
117117
docs/doxygen*
118118
docs/perlmod*
119119

120+
# Bee
121+
artifacts
122+
.vs
123+
external/buildscripts/build.gen*
124+
125+
# Allow
126+
!external/buildscripts/bee.exe
120127

121128
##############################################################################
122129
# Mono-specific patterns

external/buildscripts/Build.bee.cs

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
using System;
2+
using System.IO;
3+
using Bee.Core;
4+
using Bee.Stevedore;
5+
using NiceIO;
6+
using Unity.BuildTools;
7+
using System.Collections.Generic;
8+
using System.Text;
9+
10+
namespace BuildProgram
11+
{
12+
public class BuildProgram
13+
{
14+
internal static void Main()
15+
{
16+
if (IsRunningOnBuildMachine())
17+
Console.WriteLine("\n>>> Running on build machine");
18+
19+
var monoRoot = GetMonoRootDir();
20+
Console.WriteLine(">>> Mono root directory: " + monoRoot);
21+
22+
var buildScriptsRoot = monoRoot.Combine("external").Combine("buildscripts");
23+
Console.WriteLine(">>> Build scripts directory: " + buildScriptsRoot);
24+
25+
var monoBuildDeps = monoRoot.Parent.Parent.Combine("mono-build-deps").Combine("build");
26+
Console.WriteLine(">>> Mono build dependecies directory: " + monoBuildDeps);
27+
28+
var buildDependenciesConfigFile = buildScriptsRoot.Combine("buildDependencies.txt");
29+
Console.WriteLine(">>> Mono build dependecies stevedore version config file: " + buildDependenciesConfigFile);
30+
31+
var stevedoreArtifactsDir = buildScriptsRoot.Combine("artifacts").Combine("Stevedore");
32+
Console.WriteLine(">>> Stevedore artifacts directory: " + stevedoreArtifactsDir + "\n");
33+
34+
if (buildDependenciesConfigFile.Exists())
35+
{
36+
if (!monoBuildDeps.DirectoryExists())
37+
{
38+
Console.WriteLine(">>> " + monoBuildDeps + " does not exist. Creating it ...");
39+
monoBuildDeps.CreateDirectory();
40+
}
41+
42+
var artifactNameIdFilesDictionary = ParseBuildDependenciesConfigFile(buildDependenciesConfigFile.ToString());
43+
44+
foreach (var item in artifactNameIdFilesDictionary)
45+
{
46+
var artifactName = item.Key.Key;
47+
var artifactId = item.Key.Value;
48+
var artifactFiles = item.Value;
49+
DownloadAndCopyArtifact(artifactId, artifactName, artifactFiles, monoBuildDeps, stevedoreArtifactsDir);
50+
}
51+
}
52+
else
53+
{
54+
throw new Exception($"{buildDependenciesConfigFile} does not exist");
55+
}
56+
}
57+
58+
private static void DownloadAndCopyArtifact(string artifactId, string artifactName, IEnumerable<NPath> artifacts, NPath monoBuildDeps, NPath stevedoreArtifactsDir)
59+
{
60+
var artifact = StevedoreArtifact.Testing(artifactId);
61+
Backend.Current.Register(artifact);
62+
63+
var inputs = new List<NPath>();
64+
var targetFiles = new List<NPath>();
65+
foreach (var item in artifacts)
66+
{
67+
inputs.Add(stevedoreArtifactsDir.Combine(artifactName).Combine(item));
68+
targetFiles.Add(monoBuildDeps.Combine(artifactName).Combine(item));
69+
}
70+
71+
var targetDir = monoBuildDeps;
72+
if (HostPlatform.IsWindows)
73+
{
74+
targetDir = monoBuildDeps.Combine(artifactName);
75+
}
76+
77+
Backend.Current.AddAction(
78+
actionName: "CopyArtifact",
79+
targetFiles: targetFiles.ToArray(),
80+
inputs: inputs.ToArray(),
81+
executableStringFor: ExecutableStringForDirectoryCopy(stevedoreArtifactsDir.Combine(artifactName), targetDir),
82+
commandLineArguments: new string[] { },
83+
allowUnwrittenOutputFiles: true
84+
);
85+
}
86+
87+
private static void ExecuteBuildScript(NPath[] inputFiles, NPath buildScript, NPath buildRoot)
88+
{
89+
Backend.Current.AddAction(
90+
actionName: "ExecuteBuildScript",
91+
targetFiles: new[] { buildRoot},
92+
inputs: inputFiles,
93+
executableStringFor: $"perl {buildScript}",
94+
commandLineArguments: new string[] { },
95+
allowUnwrittenOutputFiles: true
96+
);
97+
}
98+
private static NPath GetMonoRootDir()
99+
{
100+
var exePath = new NPath(System.Reflection.Assembly.GetEntryAssembly().Location);
101+
var monoRoot = exePath;
102+
103+
//Assume "external" directory exists under monoRoot.
104+
while (monoRoot.ToString().Contains("external"))
105+
monoRoot = monoRoot.Parent;
106+
107+
return monoRoot;
108+
}
109+
110+
private static string ExecutableStringForDirectoryCopy(NPath from, NPath target)
111+
{
112+
return HostPlatform.IsWindows
113+
? $"xcopy {from.InQuotes(SlashMode.Native)} {target.InQuotes(SlashMode.Native)} /s /e /d /Y"
114+
: $"cp -r -v {from.InQuotes(SlashMode.Native)} {target.InQuotes(SlashMode.Native)}";
115+
}
116+
117+
private static bool IsRunningOnBuildMachine()
118+
{
119+
var buildMachine = Environment.GetEnvironmentVariable("UNITY_THISISABUILDMACHINE");
120+
return buildMachine != null && buildMachine == "1";
121+
}
122+
123+
//Sample config file format:
124+
/*
125+
# Dependencoes to pull down from Stevedore. Please follow the following format:
126+
# name : <stevedore artifact name>
127+
# id : <stevedore artifact id>
128+
# files : <folder and/or comma-separated list of files downloaded and unpacked>
129+
130+
name: 7z
131+
id: 7z/9df1e3b3b120_12ed325f6a47f0e5cebc247dbe9282a5da280d392cce4e6c9ed227d57ff1e2ff.7z
132+
files : 7z
133+
134+
name: libgdiplus
135+
id : libgdiplus/9df1e3b3b120_4cf7c08770db93922f54f38d2461b9122cddc898db58585864446e70c5ad3057.7z
136+
files : libgdiplus,lib2
137+
*/
138+
private static Dictionary<KeyValuePair<string, string>, List<NPath>> ParseBuildDependenciesConfigFile(string buildDependenciesConfigFile)
139+
{
140+
var artifactNameIdFilesDictionary = new Dictionary<KeyValuePair<string, string>, List<NPath>>();
141+
142+
var fileStream = new FileStream(buildDependenciesConfigFile, FileMode.Open, FileAccess.Read);
143+
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
144+
{
145+
string line;
146+
while ((line = streamReader.ReadLine()) != null)
147+
{
148+
//Check if line contains a comment
149+
if (!string.IsNullOrEmpty(line) && !line.Contains("#"))
150+
{
151+
if (line.Contains("name :") || line.Contains("name:"))
152+
{
153+
var name = "";
154+
var id = "";
155+
var files = "";
156+
157+
//read name
158+
name = line.Split(':')[1].Trim();
159+
160+
//read id
161+
if ((line = streamReader.ReadLine()) != null)
162+
id = line.Split(':')[1].Trim();
163+
else
164+
throw new Exception($">>> Invalid {buildDependenciesConfigFile}");
165+
166+
//read comma separated folder/files list
167+
if ((line = streamReader.ReadLine()) != null)
168+
files = line.Split(':')[1].Trim();
169+
else
170+
throw new Exception($">>> Invalid {buildDependenciesConfigFile}");
171+
172+
var filesList = new List<NPath>();
173+
if (!string.IsNullOrEmpty(files))
174+
{
175+
if (files.Contains(","))
176+
files.Split(',').ForEach(f => { filesList.Add(new NPath(f.Trim())); });
177+
else
178+
filesList.Add(new NPath(files.Trim()));
179+
}
180+
else
181+
{
182+
throw new Exception($">>> Invalid {buildDependenciesConfigFile}");
183+
}
184+
artifactNameIdFilesDictionary.Add(new KeyValuePair<string, string>(name, id), filesList);
185+
}
186+
}
187+
}
188+
}
189+
return artifactNameIdFilesDictionary;
190+
}
191+
}
192+
}

external/buildscripts/bee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
mono bee.exe "$@"

external/buildscripts/bee.exe

2.36 MB
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Dependencoes to pull down from Stevedore. Please follow the following format:
2+
# name : <stevedore artifact name>
3+
# id : <stevedore artifact id>
4+
# files : <folder and/or comma-separated list of files downloaded and unpacked>
5+
6+
name : 7z
7+
id: 7z/9df1e3b3b120_12ed325f6a47f0e5cebc247dbe9282a5da280d392cce4e6c9ed227d57ff1e2ff.7z
8+
files : 7z
9+
10+
name : libgdiplus
11+
id : libgdiplus/9df1e3b3b120_4cf7c08770db93922f54f38d2461b9122cddc898db58585864446e70c5ad3057.7z
12+
files : libgdiplus
13+
14+
name : MacBuildEnvironment
15+
id : MacBuildEnvironment/9df1e3b3b120_2fc8e616a2e5dfb7907fc42d9576b427e692223c266dc3bc305de4bf03714e30.7z
16+
files : MacBuildEnvironment
17+
18+
name : mono
19+
id : mono/9df1e3b3b120_f81c172b91f45b2e045f4ba52d5f65cc54041da1527f2c854bf9db3a99495007.7z
20+
files : MacBuildEnvironment
21+
22+
name : MonoBleedingEdge
23+
id : MonoBleedingEdge/9df1e3b3b120_ab6d2f131e6bd4fe2aacafb0f683e8fa4e1ccba35552b6fe89bf359b6ee16215.7z
24+
files : MonoBleedingEdge
25+
26+
name : reference-assemblies
27+
id : reference-assemblies/9df1e3b3b120_bbb4750c6bf0a1784bec7d7c04b8ef5881f31f6212136e014694f3864a388886.7z
28+
files : reference-assemblies
29+
30+
name : linux-sdk-20170609
31+
id : linux-sdk-20170609/9df1e3b3b120_9a3a0847d5b3767579e908b5a9ce050936617b1b9275a79a8b71bb3229998957.7z
32+
files : linux-sdk-20170609
33+
34+
name : libtool-2-4-6
35+
id : libtool-2-4-6/9df1e3b3b120_50f88211570edd89e1bf344d33e416a2eb04519f54940ae72d954a5ee0b8a69c.7z
36+
files : libtool-2-4-6
37+
38+
name : texinfo-4-8
39+
id : texinfo-4-8/9df1e3b3b120_f0f8445fc0e8b8d6f52b8be4c3ff09fa59c30ff4424fe8c9bea951b9893540c9.7z
40+
files : texinfo-4-8
41+
42+
name : automake-1-15
43+
id : automake-1-15/9df1e3b3b120_815e3ebf8d8bd08aa7f6ac1bbdff50d0379febba2049a5520247f7f4a1a6b3a3.7z
44+
files : automake-1-15
45+
46+
name : autoconf-2-69
47+
id : autoconf-2-69/9df1e3b3b120_08915db7451aeafc86abedc46ef88243a1179ebaef4829ac75e5de8bfc80d0d2.7z
48+
files : autoconf-2-69
49+
50+
name : android-ndk-r16b-darwin
51+
id : android-ndk-r16b-darwin/9df1e3b3b120_c7cda5a221dd72799b7e618597b3f8766df7183d386becb2785631c2d3ac0d75.7z
52+
files : android-ndk-r16b-darwin
53+
54+
name : android-ndk-r16b-linux
55+
id : android-ndk-r16b-linux/9df1e3b3b120_fbabd18208d82cbc810266e8b566bb0ea4e1e438de38d450a92deaa3e23757b6.7z
56+
files : android-ndk-r16b-linux
57+
58+
name : android-ndk-r16b-windows
59+
id : android-ndk-r16b-windows/9df1e3b3b120_403e0d58eabae03f0d9e8d1d2cea2dbf1d14c380c3d1c7eeb6e8c60ffc15e1b8.7z
60+
files : android-ndk-r16b-windows

0 commit comments

Comments
 (0)