Improvements for dependencies building utilities

This commit is contained in:
Wojtek Figat
2022-03-22 19:04:10 +01:00
parent 532203040f
commit b2e91b8a07
2 changed files with 74 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2020 Flax Engine. All rights reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Flax.Build;
@@ -219,7 +220,8 @@ namespace Flax.Deploy
/// <param name="solutionFile">Path to the solution file</param>
/// <param name="buildConfig">Configuration to build.</param>
/// <param name="buildPlatform">Platform to build.</param>
public static void BuildSolution(string solutionFile, string buildConfig, string buildPlatform)
/// <param name="props">Custom build properties mapping (property=value).</param>
public static void BuildSolution(string solutionFile, string buildConfig, string buildPlatform, Dictionary<string, string> props = null)
{
var msBuild = MSBuildPath;
if (string.IsNullOrEmpty(msBuild))
@@ -233,6 +235,11 @@ namespace Flax.Deploy
}
string cmdLine = string.Format("\"{0}\" /m /t:Build /p:Configuration=\"{1}\" /p:Platform=\"{2}\" {3} /nologo", solutionFile, buildConfig, buildPlatform, Verbosity);
if (props != null)
{
foreach (var e in props)
cmdLine += string.Format(" /p:{0}={1}", e.Key, e.Value);
}
int result = Utilities.Run(msBuild, cmdLine);
if (result != 0)
{

View File

@@ -99,6 +99,18 @@ namespace Flax.Deps
}
}
/// <summary>
/// Clones the directory.
/// </summary>
/// <param name="src">The source folder path.</param>
/// <param name="dst">The destination folder path.</param>
public static void CloneDirectory(string src, string dst)
{
if (Directory.Exists(dst))
Utilities.DirectoryDelete(dst);
Utilities.DirectoryCopy(src, dst);
}
/// <summary>
/// Clones the git repository from the remote url (full repository).
/// </summary>
@@ -275,30 +287,76 @@ namespace Flax.Deps
/// </summary>
/// <param name="path">The path.</param>
/// <param name="workspace">The workspace folder.</param>
/// <param name="envVars">Custom environment variables to pass to the child process.</param>
public static void RunCygwin(string path, string workspace = null, Dictionary<string, string> envVars = null)
public static void RunCygwin(string path, string workspace = null)
{
RunBash(path, string.Empty, workspace);
}
/// <summary>
/// Runs the bash script (executes natively on Unix platforms, uses Cygwin on Windows).
/// </summary>
/// <param name="path">The script or command path.</param>
/// <param name="args">The arguments.</param>
/// <param name="workspace">The workspace folder.</param>
/// <param name="envVars">Custom environment variables to pass to the child process.</param>
public static void RunBash(string path, string args = null, string workspace = null, Dictionary<string, string> envVars = null)
{
string app;
switch (BuildPlatform)
{
case TargetPlatform.Windows:
{
// Find Cygwin
var cygwinFolder = Environment.GetEnvironmentVariable("CYGWIN");
if (string.IsNullOrEmpty(cygwinFolder) || !Directory.Exists(cygwinFolder))
{
cygwinFolder = "C:\\cygwin";
if (!Directory.Exists(cygwinFolder))
throw new Exception("Missing Cygwin. Install Cygwin64 to C:\\cygwin or set CYGWIN env variable to install location folder.");
{
cygwinFolder = "C:\\cygwin64";
if (!Directory.Exists(cygwinFolder))
throw new Exception("Missing Cygwin. Install Cygwin64 to C:\\cygwin or set CYGWIN env variable to install location folder.");
}
}
var cygwinBinFolder = Path.Combine(cygwinFolder, "bin");
// Ensure that Cygwin binaries folder is in a PATH
string envPath = null;
envVars?.TryGetValue("PATH", out envPath);
if (envPath == null || envPath.IndexOf(cygwinBinFolder, StringComparison.OrdinalIgnoreCase) == -1)
{
if (envVars == null)
envVars = new Dictionary<string, string>();
envVars["PATH"] = cygwinBinFolder;
if (envPath != null)
envVars["PATH"] += ";" + envPath;
}
// Get the executable file path
if (path.EndsWith(".sh", StringComparison.OrdinalIgnoreCase))
{
// Bash script
if (args == null)
args = path.Replace('\\', '/');
else
args = path.Replace('\\', '/') + " " + args;
path = Path.Combine(cygwinBinFolder, "bash.exe");
}
else if (File.Exists(Path.Combine(cygwinBinFolder, path + ".exe")))
{
// Tool (eg. make)
path = Path.Combine(cygwinBinFolder, path + ".exe");
}
else
{
throw new Exception("Cannot execute command " + path + " with args " + args);
}
app = Path.Combine(cygwinFolder, "bin\\bash.exe");
break;
}
case TargetPlatform.Linux:
app = "bash";
break;
case TargetPlatform.Mac: break;
default: throw new InvalidPlatformException(BuildPlatform);
}
Utilities.Run(app, path, null, workspace, Utilities.RunOptions.None, envVars);
Utilities.Run(path, args, null, workspace, Utilities.RunOptions.ThrowExceptionOnError, envVars);
}
}
}