2014-12-07 19:09:38 -05:00
|
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AutomationTool
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public partial class CommandUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Runs msbuild.exe with the specified arguments. Automatically creates a logfile. When
|
|
|
|
|
|
/// no LogName is specified, the executable name is used as logfile base name.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Env">BuildEnvironment to use.</param>
|
|
|
|
|
|
/// <param name="Project">Path to the project to build.</param>
|
|
|
|
|
|
/// <param name="Arguments">Arguments to pass to msbuild.exe.</param>
|
|
|
|
|
|
/// <param name="LogName">Optional logfile name.</param>
|
|
|
|
|
|
public static void MsBuild(CommandEnvironment Env, string Project, string Arguments, string LogName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (String.IsNullOrEmpty(Env.MsBuildExe))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new AutomationException("Unable to find msbuild.exe at: \"{0}\"", Env.MsBuildExe);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!FileExists(Project))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new AutomationException("Project {0} does not exist!", Project);
|
|
|
|
|
|
}
|
|
|
|
|
|
var RunArguments = MakePathSafeToUseWithCommandLine(Project);
|
|
|
|
|
|
if (!String.IsNullOrEmpty(Arguments))
|
|
|
|
|
|
{
|
|
|
|
|
|
RunArguments += " " + Arguments;
|
|
|
|
|
|
}
|
|
|
|
|
|
RunAndLog(Env, Env.MsBuildExe, RunArguments, LogName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Builds a Visual Studio solution with MsDevEnv. Automatically creates a logfile. When
|
|
|
|
|
|
/// no LogName is specified, the executable name is used as logfile base name.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Env">BuildEnvironment to use.</param>
|
|
|
|
|
|
/// <param name="SolutionFile">Path to the solution file</param>
|
|
|
|
|
|
/// <param name="BuildConfig">Configuration to build.</param>
|
|
|
|
|
|
/// <param name="LogName">Optional logfile name.</param>
|
|
|
|
|
|
public static void BuildSolution(CommandEnvironment Env, string SolutionFile, string BuildConfig = "Development", string LogName = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!FileExists(SolutionFile))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new AutomationException(String.Format("Unabled to build Solution {0}. Solution file not found.", SolutionFile));
|
|
|
|
|
|
}
|
2014-04-02 18:09:23 -04:00
|
|
|
|
if (String.IsNullOrEmpty(Env.MsDevExe))
|
2014-03-14 14:13:41 -04:00
|
|
|
|
{
|
|
|
|
|
|
throw new AutomationException(String.Format("Unabled to build Solution {0}. devenv.com not found.", SolutionFile));
|
|
|
|
|
|
}
|
|
|
|
|
|
string CmdLine = String.Format("\"{0}\" /build \"{1}\"", SolutionFile, BuildConfig);
|
|
|
|
|
|
RunAndLog(Env, Env.MsDevExe, CmdLine, LogName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Builds a CSharp project with msbuild.exe. Automatically creates a logfile. When
|
|
|
|
|
|
/// no LogName is specified, the executable name is used as logfile base name.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Env">BuildEnvironment to use.</param>
|
|
|
|
|
|
/// <param name="ProjectFile">Path to the project file. Must be a .csproj file.</param>
|
|
|
|
|
|
/// <param name="BuildConfig">Configuration to build.</param>
|
|
|
|
|
|
/// <param name="LogName">Optional logfile name.</param>
|
|
|
|
|
|
public static void BuildCSharpProject(CommandEnvironment Env, string ProjectFile, string BuildConfig = "Development", string LogName = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ProjectFile.EndsWith(".csproj"))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new AutomationException(String.Format("Unabled to build Project {0}. Not a valid .csproj file.", ProjectFile));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!FileExists(ProjectFile))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new AutomationException(String.Format("Unabled to build Project {0}. Project file not found.", ProjectFile));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string CmdLine = String.Format(@"/verbosity:normal /target:Rebuild /property:Configuration={0} /property:Platform=AnyCPU", BuildConfig);
|
|
|
|
|
|
MsBuild(Env, ProjectFile, CmdLine, LogName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// returns true if this is a mac executable using some awful conventions
|
|
|
|
|
|
/// <param name="Filename">Filename</param>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static bool IsProbablyAMacOrIOSExe(string Filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
return
|
2014-04-23 16:36:11 -04:00
|
|
|
|
Path.GetExtension(Filename) == ".sh" ||
|
|
|
|
|
|
Path.GetExtension(Filename) == ".command" ||
|
|
|
|
|
|
((
|
2014-03-14 14:13:41 -04:00
|
|
|
|
CommandUtils.CombinePaths(Filename).ToLower().Contains(CommandUtils.CombinePaths("Binaries", "Mac").ToLower()) ||
|
2014-07-02 14:19:20 -04:00
|
|
|
|
CommandUtils.CombinePaths(Filename).ToLower().Contains(CommandUtils.CombinePaths("Binaries", "IOS").ToLower()) ||
|
2014-11-26 11:01:02 -05:00
|
|
|
|
CommandUtils.CombinePaths(Filename).ToLower().Contains(CommandUtils.CombinePaths("Binaries", "ThirdParty").ToLower()) ||
|
|
|
|
|
|
CommandUtils.CombinePaths(Filename).ToLower().Contains(".app/Contents/MacOS".ToLower())
|
2014-04-23 16:36:11 -04:00
|
|
|
|
) && (Path.GetExtension(Filename) == "" || Path.GetExtension(Filename) == "."));
|
2014-03-14 14:13:41 -04:00
|
|
|
|
}
|
2014-06-10 16:45:40 -04:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets an executable bit for Unix executables and adds read permission for all users plus write permission for owner.
|
|
|
|
|
|
/// <param name="Filename">Filename</param>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void FixUnixFilePermissions(string Filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
string Permissions = IsProbablyAMacOrIOSExe(Filename) ? "0755" : "0644";
|
2014-06-21 08:07:26 -04:00
|
|
|
|
var Result = CommandUtils.Run("sh", string.Format("-c 'chmod {0} \"{1}\"'", Permissions, Filename.Replace("'", "'\"'\"'")));
|
2014-06-10 16:45:40 -04:00
|
|
|
|
if (Result.ExitCode != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new AutomationException(String.Format("Failed to chmod \"{0}\"", Filename));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|