Improvements for dependencies building utilities
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2012-2020 Flax Engine. All rights reserved.
|
// Copyright (c) 2012-2020 Flax Engine. All rights reserved.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Flax.Build;
|
using Flax.Build;
|
||||||
@@ -219,7 +220,8 @@ namespace Flax.Deploy
|
|||||||
/// <param name="solutionFile">Path to the solution file</param>
|
/// <param name="solutionFile">Path to the solution file</param>
|
||||||
/// <param name="buildConfig">Configuration to build.</param>
|
/// <param name="buildConfig">Configuration to build.</param>
|
||||||
/// <param name="buildPlatform">Platform 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;
|
var msBuild = MSBuildPath;
|
||||||
if (string.IsNullOrEmpty(msBuild))
|
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);
|
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);
|
int result = Utilities.Run(msBuild, cmdLine);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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>
|
/// <summary>
|
||||||
/// Clones the git repository from the remote url (full repository).
|
/// Clones the git repository from the remote url (full repository).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -275,30 +287,76 @@ namespace Flax.Deps
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path.</param>
|
/// <param name="path">The path.</param>
|
||||||
/// <param name="workspace">The workspace folder.</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)
|
||||||
public static void RunCygwin(string path, string workspace = null, Dictionary<string, string> envVars = 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)
|
switch (BuildPlatform)
|
||||||
{
|
{
|
||||||
case TargetPlatform.Windows:
|
case TargetPlatform.Windows:
|
||||||
{
|
{
|
||||||
|
// Find Cygwin
|
||||||
var cygwinFolder = Environment.GetEnvironmentVariable("CYGWIN");
|
var cygwinFolder = Environment.GetEnvironmentVariable("CYGWIN");
|
||||||
if (string.IsNullOrEmpty(cygwinFolder) || !Directory.Exists(cygwinFolder))
|
if (string.IsNullOrEmpty(cygwinFolder) || !Directory.Exists(cygwinFolder))
|
||||||
{
|
{
|
||||||
cygwinFolder = "C:\\cygwin";
|
cygwinFolder = "C:\\cygwin";
|
||||||
|
if (!Directory.Exists(cygwinFolder))
|
||||||
|
{
|
||||||
|
cygwinFolder = "C:\\cygwin64";
|
||||||
if (!Directory.Exists(cygwinFolder))
|
if (!Directory.Exists(cygwinFolder))
|
||||||
throw new Exception("Missing Cygwin. Install Cygwin64 to C:\\cygwin or set CYGWIN env variable to install location folder.");
|
throw new Exception("Missing Cygwin. Install Cygwin64 to C:\\cygwin or set CYGWIN env variable to install location folder.");
|
||||||
}
|
}
|
||||||
app = Path.Combine(cygwinFolder, "bin\\bash.exe");
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TargetPlatform.Linux:
|
case TargetPlatform.Linux:
|
||||||
app = "bash";
|
case TargetPlatform.Mac: break;
|
||||||
break;
|
|
||||||
default: throw new InvalidPlatformException(BuildPlatform);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user