Skip to content

Commit

Permalink
Build: Create 'PublishMonoBuilds' target
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinCampbell committed Aug 2, 2017
1 parent fde0984 commit b1e533c
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 28 deletions.
90 changes: 66 additions & 24 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -254,36 +254,17 @@ Task("InstallMonoAssets")
DownloadFileAndUnzip($"{buildPlan.DownloadURL}/{buildPlan.MonoMSBuildRuntime}", env.Folders.MonoMSBuildRuntime);
DownloadFileAndUnzip($"{buildPlan.DownloadURL}/{buildPlan.MonoMSBuildLib}", env.Folders.MonoMSBuildLib);
string runtimeFolder;
string runtimeFile;
if (Platform.Current.IsMacOS)
{
runtimeFolder = env.Folders.MonoRuntimeMacOS;
runtimeFile = "mono.osx";
}
else if (Platform.Current.IsLinux && Platform.Current.Is32Bit)
{
runtimeFolder = env.Folders.MonoRuntimeLinux32;
runtimeFile = "mono.linux-x86";
}
else if (Platform.Current.IsLinux && Platform.Current.Is64Bit)
{
runtimeFolder = env.Folders.MonoRuntimeLinux64;
runtimeFile = "mono.linux-x86_64";
}
else
{
throw new Exception($"Unsupported platform: {Platform.Current}");
}
var monoInstallFolder = env.CurrentMonoRuntime.InstallFolder;
var monoRuntimeFile = env.CurrentMonoRuntime.RuntimeFile;
DirectoryHelper.ForceCreate(env.Folders.Mono);
DirectoryHelper.Copy(runtimeFolder, env.Folders.Mono);
DirectoryHelper.Copy(monoInstallFolder, env.Folders.Mono);
var frameworkFolder = CombinePaths(env.Folders.Mono, "framework");
DirectoryHelper.ForceCreate(frameworkFolder);
DirectoryHelper.Copy(env.Folders.MonoFramework, frameworkFolder);
Run("chmod", $"+x '{CombinePaths(env.Folders.Mono, runtimeFile)}'");
Run("chmod", $"+x '{CombinePaths(env.Folders.Mono, monoRuntimeFile)}'");
Run("chmod", $"+x '{CombinePaths(env.Folders.Mono, "run")}'");
});

Expand Down Expand Up @@ -489,6 +470,67 @@ string GetPublishArguments(string projectFileName, string rid, string framework,
return string.Join(" ", argList);
}

void PublishMonoBuild(BuildEnvironment env, BuildPlan plan, string configuration)
{
Information("Publishing Mono build...");

var project = plan.MainProject;
var outputFolder = CombinePaths(env.Folders.ArtifactsPublish, project, "mono");

var buildFolder = CombinePaths(env.Folders.Source, project, "bin", configuration, "net46");
DirectoryHelper.Copy(buildFolder, outputFolder, copySubDirectories: false);

// Copy MSBuild runtime and libraries
DirectoryHelper.Copy($"{env.Folders.MSBuildBase}-net46", CombinePaths(outputFolder, "msbuild"));
DirectoryHelper.Copy($"{env.Folders.MonoMSBuildLib}", outputFolder);

// Included in Mono
FileHelper.Delete(CombinePaths(outputFolder, "System.AppContext.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.Numerics.Vectors.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.Runtime.InteropServices.RuntimeInformation.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.ComponentModel.Primitives.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.ComponentModel.TypeConverter.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.Console.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.IO.FileSystem.Primitives.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.IO.FileSystem.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.Security.Cryptography.Encoding.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.Security.Cryptography.Primitives.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.Security.Cryptography.X509Certificates.dll"));
FileHelper.Delete(CombinePaths(outputFolder, "System.Threading.Thread.dll"));
}

void PublishMonoBuildForPlatform(MonoRuntime monoRuntime, BuildEnvironment env, BuildPlan plan)
{
Information("Publishing platform-specific Mono build: {0}", monoRuntime.PlatformName);

var project = plan.MainProject;
var outputFolder = CombinePaths(env.Folders.ArtifactsPublish, project, monoRuntime.PlatformName);

DirectoryHelper.Copy(monoRuntime.InstallFolder, outputFolder);

Run("chmod", $"+x '{CombinePaths(outputFolder, monoRuntime.RuntimeFile)}'");
Run("chmod", $"+x '{CombinePaths(outputFolder, "run")}'");

DirectoryHelper.Copy(env.Folders.MonoFramework, CombinePaths(outputFolder, "framework"));

var sourceFolder = CombinePaths(env.Folders.ArtifactsPublish, project, "mono");
var omnisharpFolder = CombinePaths(outputFolder, "omnisharp");
DirectoryHelper.Copy(sourceFolder, omnisharpFolder);
}

Task("PublishMonoBuilds")
.IsDependentOn("Setup")
.WithCriteria(() => !Platform.Current.IsWindows)
.Does(() =>
{
PublishMonoBuild(env, buildPlan, configuration);
foreach (var monoRuntime in env.MonoRuntimes)
{
PublishMonoBuildForPlatform(monoRuntime, env, buildPlan);
}
});

/// <summary>
/// Build, publish and package artifacts.
/// Targets all RIDs specified in build.json unless restricted by RestrictToLocalRuntime.
Expand Down Expand Up @@ -552,7 +594,7 @@ Task("OnlyPublish")
// For OSX/Linux net46 builds, copy the MSBuild libraries built for Mono.
// In addition, delete System.Runtime.InteropServices.RuntimeInformation, which is Windows-specific.
if (!Platform.Current.IsWindows && framework == "net46")
if (!Platform.Current.IsWindows)
{
DirectoryHelper.Copy($"{env.Folders.MonoMSBuildLib}", outputFolder);
Expand Down
48 changes: 44 additions & 4 deletions scripts/common.cake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static class FileHelper

public static class DirectoryHelper
{
public static void Copy(string source, string destination)
public static void Copy(string source, string destination, bool copySubDirectories = true)
{
var files = System.IO.Directory.GetFiles(source);
var subDirectories = System.IO.Directory.GetDirectories(source);
Expand All @@ -56,10 +56,13 @@ public static class DirectoryHelper
FileHelper.Copy(file, newFile, overwrite: true);
}

foreach (var subDirectory in subDirectories)
if (copySubDirectories)
{
var newSubDirectory = PathHelper.Combine(destination, PathHelper.GetFileName(subDirectory));
Copy(subDirectory, newSubDirectory);
foreach (var subDirectory in subDirectories)
{
var newSubDirectory = PathHelper.Combine(destination, PathHelper.GetFileName(subDirectory));
Copy(subDirectory, newSubDirectory);
}
}
}

Expand Down Expand Up @@ -177,6 +180,20 @@ public class Folders
}
}

public class MonoRuntime
{
public string PlatformName { get; }
public string InstallFolder { get; }
public string RuntimeFile { get; }

public MonoRuntime(string platformName, string installFolder, string runtimeFile)
{
this.PlatformName = platformName;
this.InstallFolder = installFolder;
this.RuntimeFile = runtimeFile;
}
}

public class BuildEnvironment
{
public string WorkingDirectory { get; }
Expand All @@ -189,6 +206,9 @@ public class BuildEnvironment
public string ShellArgument { get; }
public string ShellScriptFileExtension { get; }

public MonoRuntime[] MonoRuntimes { get; }
public MonoRuntime CurrentMonoRuntime { get; }

public BuildEnvironment(bool useGlobalDotNetSdk)
{
this.WorkingDirectory = PathHelper.GetFullPath(
Expand All @@ -204,6 +224,26 @@ public class BuildEnvironment
this.ShellCommand = Platform.Current.IsWindows ? "powershell" : "bash";
this.ShellArgument = Platform.Current.IsWindows ? "-NoProfile /Command" : "-C";
this.ShellScriptFileExtension = Platform.Current.IsWindows ? "ps1" : "sh";

this.MonoRuntimes = new []
{
new MonoRuntime("osx", this.Folders.MonoRuntimeMacOS, "mono.osx"),
new MonoRuntime("linux-x86", this.Folders.MonoRuntimeLinux32, "mono.linux-x86"),
new MonoRuntime("linux-x64", this.Folders.MonoRuntimeLinux64, "mono.linux-x86_64")
};

if (Platform.Current.IsMacOS)
{
this.CurrentMonoRuntime = this.MonoRuntimes[0];
}
else if (Platform.Current.IsLinux && Platform.Current.Is32Bit)
{
this.CurrentMonoRuntime = this.MonoRuntimes[1];
}
else if (Platform.Current.IsLinux && Platform.Current.Is64Bit)
{
this.CurrentMonoRuntime = this.MonoRuntimes[2];
}
}
}

Expand Down

0 comments on commit b1e533c

Please sign in to comment.