working on build scripts
This commit is contained in:
parent
f273ea4f7d
commit
d524732bbb
111 changed files with 3052 additions and 1989 deletions
47
scripts/dotnet-cli-build/Utils/BuildVersion.cs
Normal file
47
scripts/dotnet-cli-build/Utils/BuildVersion.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class BuildVersion
|
||||
{
|
||||
public int Major { get; set; }
|
||||
public int Minor { get; set; }
|
||||
public int Patch { get; set; }
|
||||
public int CommitCount { get; set; }
|
||||
public string CommitCountString => CommitCount.ToString("000000");
|
||||
public string ReleaseSuffix { get; set; }
|
||||
|
||||
public string SimpleVersion => $"{Major}.{Minor}.{Patch}.{CommitCount}";
|
||||
public string VersionSuffix => $"{ReleaseSuffix}-{CommitCount}";
|
||||
public string NuGetVersion => $"{Major}.{Minor}.{Patch}-{VersionSuffix}";
|
||||
|
||||
public string GenerateMsiVersion()
|
||||
{
|
||||
// MSI versioning
|
||||
// Encode the CLI version to fit into the MSI versioning scheme - https://msdn.microsoft.com/en-us/library/windows/desktop/aa370859(v=vs.85).aspx
|
||||
// MSI versions are 3 part
|
||||
// major.minor.build
|
||||
// Size(bits) of each part 8 8 16
|
||||
// So we have 32 bits to encode the CLI version
|
||||
// Starting with most significant bit this how the CLI version is going to be encoded as MSI Version
|
||||
// CLI major -> 6 bits
|
||||
// CLI minor -> 6 bits
|
||||
// CLI patch -> 6 bits
|
||||
// CLI commitcount -> 14 bits
|
||||
|
||||
var major = Major << 26;
|
||||
var minor = Minor << 20;
|
||||
var patch = Patch << 14;
|
||||
var msiVersionNumber = major | minor | patch | CommitCount;
|
||||
|
||||
var msiMajor = (msiVersionNumber >> 24) & 0xFF;
|
||||
var msiMinor = (msiVersionNumber >> 16) & 0xFF;
|
||||
var msiBuild = msiVersionNumber & 0xFFFF;
|
||||
|
||||
return $"{msiMajor}.{msiMinor}.{msiBuild}";
|
||||
}
|
||||
}
|
||||
}
|
38
scripts/dotnet-cli-build/Utils/Dirs.cs
Normal file
38
scripts/dotnet-cli-build/Utils/Dirs.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public static class Dirs
|
||||
{
|
||||
public static readonly string Output = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
"artifacts",
|
||||
PlatformServices.Default.Runtime.GetRuntimeIdentifier());
|
||||
public static readonly string Packages = Path.Combine(Output, "packages");
|
||||
public static readonly string Stage1 = Path.Combine(Output, "stage1");
|
||||
public static readonly string Stage1Compilation = Path.Combine(Output, "stage1compilation");
|
||||
public static readonly string Stage2 = Path.Combine(Output, "stage2");
|
||||
public static readonly string Stage2Compilation = Path.Combine(Output, "stage2compilation");
|
||||
public static readonly string Corehost = Path.Combine(Output, "corehost");
|
||||
public static readonly string TestOutput = Path.Combine(Output, "tests");
|
||||
public static readonly string TestPackages = Path.Combine(TestOutput, "packages");
|
||||
|
||||
public static readonly string OSXReferenceAssembliesPath = "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks";
|
||||
public static readonly string UsrLocalReferenceAssembliesPath = "/usr/local/lib/mono/xbuild-frameworks";
|
||||
public static readonly string UsrReferenceAssembliesPath = "/usr/lib/mono/xbuild-frameworks";
|
||||
|
||||
public static string NuGetPackages = Environment.GetEnvironmentVariable("NUGET_PACKAGES") ?? GetNuGetPackagesDir();
|
||||
|
||||
private static string GetNuGetPackagesDir()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".nuget", "packages");
|
||||
}
|
||||
return Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".nuget", "packages");
|
||||
}
|
||||
}
|
||||
}
|
51
scripts/dotnet-cli-build/Utils/DotNetCli.cs
Normal file
51
scripts/dotnet-cli-build/Utils/DotNetCli.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
internal class DotNetCli
|
||||
{
|
||||
public static readonly DotNetCli Stage0 = new DotNetCli(GetStage0Path());
|
||||
public static readonly DotNetCli Stage1 = new DotNetCli(Path.Combine(Dirs.Stage1, "bin"));
|
||||
public static readonly DotNetCli Stage2 = new DotNetCli(Path.Combine(Dirs.Stage2, "bin"));
|
||||
|
||||
public string BinPath { get; }
|
||||
|
||||
public DotNetCli(string binPath)
|
||||
{
|
||||
BinPath = binPath;
|
||||
}
|
||||
|
||||
public void SetDotNetHome()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOTNET_HOME", Path.GetDirectoryName(BinPath));
|
||||
}
|
||||
|
||||
public Command Exec(string command, params string[] args)
|
||||
{
|
||||
return Command.Create(Path.Combine(BinPath, $"dotnet{Constants.ExeSuffix}"), Enumerable.Concat(new[] { command }, args));
|
||||
}
|
||||
|
||||
public Command Restore(params string[] args) => Exec("restore", args);
|
||||
public Command Build(params string[] args) => Exec("build", args);
|
||||
public Command Pack(params string[] args) => Exec("pack", args);
|
||||
public Command Test(params string[] args) => Exec("test", args);
|
||||
public Command Publish(params string[] args) => Exec("publish", args);
|
||||
|
||||
private static string GetStage0Path()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", PlatformServices.Default.Runtime.OperatingSystemPlatform.ToString(), "cli", "bin");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", PlatformServices.Default.Runtime.OperatingSystemPlatform.ToString(), "share", "dotnet", "cli", "bin");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
114
scripts/dotnet-cli-build/Utils/FS.cs
Normal file
114
scripts/dotnet-cli-build/Utils/FS.cs
Normal file
|
@ -0,0 +1,114 @@
|
|||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public static class FS
|
||||
{
|
||||
public static void Mkdirp(string dir)
|
||||
{
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Rm(string file)
|
||||
{
|
||||
if(File.Exists(file))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Rmdir(string dir)
|
||||
{
|
||||
if(Directory.Exists(dir))
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Chmod(string file, string mode, bool recursive = false)
|
||||
{
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
if (recursive)
|
||||
{
|
||||
Command.Create("chmod", "-R", mode, file).Execute().EnsureSuccessful();
|
||||
}
|
||||
else
|
||||
{
|
||||
Command.Create("chmod", mode, file).Execute().EnsureSuccessful();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ChmodAll(string searchDir, string pattern, string mode)
|
||||
{
|
||||
Exec("find", searchDir, "-type", "f", "-name", pattern, "-exec", "chmod", mode, "{}", ";");
|
||||
}
|
||||
|
||||
public static void FixModeFlags(string dir)
|
||||
{
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
// Managed code doesn't need 'x'
|
||||
ChmodAll(dir, "*.dll", "644");
|
||||
ChmodAll(dir, "*.exe", "644");
|
||||
|
||||
// Generally, dylibs and sos have 'x' (no idea if it's required ;))
|
||||
// (No need to condition this on OS since there shouldn't be any dylibs on Linux,
|
||||
// but even if they are we may as well set their mode flags :))
|
||||
ChmodAll(dir, "*.dylib", "755");
|
||||
ChmodAll(dir, "*.so", "755");
|
||||
|
||||
// Executables (those without dots) are executable :)
|
||||
Exec("find", dir, "-type", "f", "!", "-name", "*.*", "-exec", "chmod", "755", "{}", ";");
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyRecursive(string sourceDirectory, string destinationDirectory, bool overwrite = false)
|
||||
{
|
||||
Mkdirp(destinationDirectory);
|
||||
|
||||
foreach(var dir in Directory.EnumerateDirectories(sourceDirectory))
|
||||
{
|
||||
CopyRecursive(dir, Path.Combine(destinationDirectory, Path.GetFileName(dir)), overwrite);
|
||||
}
|
||||
|
||||
foreach(var file in Directory.EnumerateFiles(sourceDirectory))
|
||||
{
|
||||
var dest = Path.Combine(destinationDirectory, Path.GetFileName(file));
|
||||
if (!File.Exists(dest) || overwrite)
|
||||
{
|
||||
// We say overwrite true, because we only get here if the file didn't exist (thus it doesn't matter) or we
|
||||
// wanted to overwrite :)
|
||||
File.Copy(file, dest, overwrite: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CleanBinObj(BuildTargetContext c, string dir)
|
||||
{
|
||||
dir = dir ?? c.BuildContext.BuildDirectory;
|
||||
foreach(var candidate in Directory.EnumerateDirectories(dir))
|
||||
{
|
||||
if (string.Equals(Path.GetFileName(candidate), "bin") ||
|
||||
string.Equals(Path.GetFileName(candidate), "obj"))
|
||||
{
|
||||
Directory.Delete(candidate, recursive: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CleanBinObj(c, candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
38
scripts/dotnet-cli-build/Utils/Utils.cs
Normal file
38
scripts/dotnet-cli-build/Utils/Utils.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
public static void CleanNuGetTempCache()
|
||||
{
|
||||
// Clean NuGet Temp Cache on Linux (seeing some issues on Linux)
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Directory.Exists("/tmp/NuGet"))
|
||||
{
|
||||
Directory.Delete("/tmp/NuGet", recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetOSName()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return "win";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
return "osx";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue