Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bee script to pull down required mono-build-deps from stevedore #1064

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ GTAGS
docs/doxygen*
docs/perlmod*

# Bee
artifacts
.vs
external/buildscripts/build.gen*

# Allow
!external/buildscripts/bee.exe

##############################################################################
# Mono-specific patterns
Expand Down
192 changes: 192 additions & 0 deletions external/buildscripts/Build.bee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using System;
using System.IO;
using Bee.Core;
using Bee.Stevedore;
using NiceIO;
using Unity.BuildTools;
using System.Collections.Generic;
using System.Text;

namespace BuildProgram
{
public class BuildProgram
{
internal static void Main()
{
if (IsRunningOnBuildMachine())
Console.WriteLine("\n>>> Running on build machine");

var monoRoot = GetMonoRootDir();
Console.WriteLine(">>> Mono root directory: " + monoRoot);

var buildScriptsRoot = monoRoot.Combine("external").Combine("buildscripts");
Console.WriteLine(">>> Build scripts directory: " + buildScriptsRoot);

var monoBuildDeps = monoRoot.Parent.Parent.Combine("mono-build-deps").Combine("build");
Console.WriteLine(">>> Mono build dependecies directory: " + monoBuildDeps);

var buildDependenciesConfigFile = buildScriptsRoot.Combine("buildDependencies.txt");
Console.WriteLine(">>> Mono build dependecies stevedore version config file: " + buildDependenciesConfigFile);

var stevedoreArtifactsDir = buildScriptsRoot.Combine("artifacts").Combine("Stevedore");
Console.WriteLine(">>> Stevedore artifacts directory: " + stevedoreArtifactsDir + "\n");

if (buildDependenciesConfigFile.Exists())
{
if (!monoBuildDeps.DirectoryExists())
{
Console.WriteLine(">>> " + monoBuildDeps + " does not exist. Creating it ...");
monoBuildDeps.CreateDirectory();
}

var artifactNameIdFilesDictionary = ParseBuildDependenciesConfigFile(buildDependenciesConfigFile.ToString());

foreach (var item in artifactNameIdFilesDictionary)
{
var artifactName = item.Key.Key;
var artifactId = item.Key.Value;
var artifactFiles = item.Value;
DownloadAndCopyArtifact(artifactId, artifactName, artifactFiles, monoBuildDeps, stevedoreArtifactsDir);
}
}
else
{
throw new Exception($"{buildDependenciesConfigFile} does not exist");
}
}

private static void DownloadAndCopyArtifact(string artifactId, string artifactName, IEnumerable<NPath> artifacts, NPath monoBuildDeps, NPath stevedoreArtifactsDir)
{
var artifact = StevedoreArtifact.Testing(artifactId);
Backend.Current.Register(artifact);

var inputs = new List<NPath>();
var targetFiles = new List<NPath>();
foreach (var item in artifacts)
{
inputs.Add(stevedoreArtifactsDir.Combine(artifactName).Combine(item));
targetFiles.Add(monoBuildDeps.Combine(artifactName).Combine(item));
}

var targetDir = monoBuildDeps;
if (HostPlatform.IsWindows)
{
targetDir = monoBuildDeps.Combine(artifactName);
}

Backend.Current.AddAction(
actionName: "CopyArtifact",
targetFiles: targetFiles.ToArray(),
inputs: inputs.ToArray(),
executableStringFor: ExecutableStringForDirectoryCopy(stevedoreArtifactsDir.Combine(artifactName), targetDir),
commandLineArguments: new string[] { },
allowUnwrittenOutputFiles: true
);
}

private static void ExecuteBuildScript(NPath[] inputFiles, NPath buildScript, NPath buildRoot)
{
Backend.Current.AddAction(
actionName: "ExecuteBuildScript",
targetFiles: new[] { buildRoot},
inputs: inputFiles,
executableStringFor: $"perl {buildScript}",
commandLineArguments: new string[] { },
allowUnwrittenOutputFiles: true
);
}
private static NPath GetMonoRootDir()
{
var exePath = new NPath(System.Reflection.Assembly.GetEntryAssembly().Location);
var monoRoot = exePath;

//Assume "external" directory exists under monoRoot.
while (monoRoot.ToString().Contains("external"))
monoRoot = monoRoot.Parent;

return monoRoot;
}

private static string ExecutableStringForDirectoryCopy(NPath from, NPath target)
{
return HostPlatform.IsWindows
? $"xcopy {from.InQuotes(SlashMode.Native)} {target.InQuotes(SlashMode.Native)} /s /e /d /Y"
: $"cp -r -v {from.InQuotes(SlashMode.Native)} {target.InQuotes(SlashMode.Native)}";
}

private static bool IsRunningOnBuildMachine()
{
var buildMachine = Environment.GetEnvironmentVariable("UNITY_THISISABUILDMACHINE");
return buildMachine != null && buildMachine == "1";
}

//Sample config file format:
/*
# Dependencoes to pull down from Stevedore. Please follow the following format:
# name : <stevedore artifact name>
# id : <stevedore artifact id>
# files : <folder and/or comma-separated list of files downloaded and unpacked>

name: 7z
id: 7z/9df1e3b3b120_12ed325f6a47f0e5cebc247dbe9282a5da280d392cce4e6c9ed227d57ff1e2ff.7z
files : 7z

name: libgdiplus
id : libgdiplus/9df1e3b3b120_4cf7c08770db93922f54f38d2461b9122cddc898db58585864446e70c5ad3057.7z
files : libgdiplus,lib2
*/
private static Dictionary<KeyValuePair<string, string>, List<NPath>> ParseBuildDependenciesConfigFile(string buildDependenciesConfigFile)
{
var artifactNameIdFilesDictionary = new Dictionary<KeyValuePair<string, string>, List<NPath>>();

var fileStream = new FileStream(buildDependenciesConfigFile, FileMode.Open, FileAccess.Read);
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
string line;
while ((line = streamReader.ReadLine()) != null)
{
//Check if line contains a comment
if (!string.IsNullOrEmpty(line) && !line.Contains("#"))
{
if (line.Contains("name :") || line.Contains("name:"))
{
var name = "";
var id = "";
var files = "";

//read name
name = line.Split(':')[1].Trim();

//read id
if ((line = streamReader.ReadLine()) != null)
id = line.Split(':')[1].Trim();
else
throw new Exception($">>> Invalid {buildDependenciesConfigFile}");

//read comma separated folder/files list
if ((line = streamReader.ReadLine()) != null)
files = line.Split(':')[1].Trim();
else
throw new Exception($">>> Invalid {buildDependenciesConfigFile}");

var filesList = new List<NPath>();
if (!string.IsNullOrEmpty(files))
{
if (files.Contains(","))
files.Split(',').ForEach(f => { filesList.Add(new NPath(f.Trim())); });
else
filesList.Add(new NPath(files.Trim()));
}
else
{
throw new Exception($">>> Invalid {buildDependenciesConfigFile}");
}
artifactNameIdFilesDictionary.Add(new KeyValuePair<string, string>(name, id), filesList);
}
}
}
}
return artifactNameIdFilesDictionary;
}
}
}
2 changes: 2 additions & 0 deletions external/buildscripts/bee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
mono bee.exe "$@"
Binary file added external/buildscripts/bee.exe
Binary file not shown.
60 changes: 60 additions & 0 deletions external/buildscripts/buildDependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Dependencoes to pull down from Stevedore. Please follow the following format:
# name : <stevedore artifact name>
# id : <stevedore artifact id>
# files : <folder and/or comma-separated list of files downloaded and unpacked>

name : 7z
id: 7z/9df1e3b3b120_12ed325f6a47f0e5cebc247dbe9282a5da280d392cce4e6c9ed227d57ff1e2ff.7z
files : 7z

name : libgdiplus
id : libgdiplus/9df1e3b3b120_4cf7c08770db93922f54f38d2461b9122cddc898db58585864446e70c5ad3057.7z
files : libgdiplus

name : MacBuildEnvironment
id : MacBuildEnvironment/9df1e3b3b120_2fc8e616a2e5dfb7907fc42d9576b427e692223c266dc3bc305de4bf03714e30.7z
files : MacBuildEnvironment

name : mono
id : mono/9df1e3b3b120_f81c172b91f45b2e045f4ba52d5f65cc54041da1527f2c854bf9db3a99495007.7z
files : MacBuildEnvironment

name : MonoBleedingEdge
id : MonoBleedingEdge/9df1e3b3b120_ab6d2f131e6bd4fe2aacafb0f683e8fa4e1ccba35552b6fe89bf359b6ee16215.7z
files : MonoBleedingEdge

name : reference-assemblies
id : reference-assemblies/9df1e3b3b120_bbb4750c6bf0a1784bec7d7c04b8ef5881f31f6212136e014694f3864a388886.7z
files : reference-assemblies

name : linux-sdk-20170609
id : linux-sdk-20170609/9df1e3b3b120_9a3a0847d5b3767579e908b5a9ce050936617b1b9275a79a8b71bb3229998957.7z
files : linux-sdk-20170609

name : libtool-2-4-6
id : libtool-2-4-6/9df1e3b3b120_50f88211570edd89e1bf344d33e416a2eb04519f54940ae72d954a5ee0b8a69c.7z
files : libtool-2-4-6

name : texinfo-4-8
id : texinfo-4-8/9df1e3b3b120_f0f8445fc0e8b8d6f52b8be4c3ff09fa59c30ff4424fe8c9bea951b9893540c9.7z
files : texinfo-4-8

name : automake-1-15
id : automake-1-15/9df1e3b3b120_815e3ebf8d8bd08aa7f6ac1bbdff50d0379febba2049a5520247f7f4a1a6b3a3.7z
files : automake-1-15

name : autoconf-2-69
id : autoconf-2-69/9df1e3b3b120_08915db7451aeafc86abedc46ef88243a1179ebaef4829ac75e5de8bfc80d0d2.7z
files : autoconf-2-69

name : android-ndk-r16b-darwin
id : android-ndk-r16b-darwin/9df1e3b3b120_c7cda5a221dd72799b7e618597b3f8766df7183d386becb2785631c2d3ac0d75.7z
files : android-ndk-r16b-darwin

name : android-ndk-r16b-linux
id : android-ndk-r16b-linux/9df1e3b3b120_fbabd18208d82cbc810266e8b566bb0ea4e1e438de38d450a92deaa3e23757b6.7z
files : android-ndk-r16b-linux

name : android-ndk-r16b-windows
id : android-ndk-r16b-windows/9df1e3b3b120_403e0d58eabae03f0d9e8d1d2cea2dbf1d14c380c3d1c7eeb6e8c60ffc15e1b8.7z
files : android-ndk-r16b-windows