public static ExecutionResult Execute(string verb, string project, Dictionary <string, string> properties, string verbosity = "diagnostic", bool assert_success = true) { if (!File.Exists(project)) { throw new FileNotFoundException($"The project file '{project}' does not exist."); } verb = verb.ToLowerInvariant(); switch (verb) { case "clean": case "build": var args = new List <string> (); args.Add(verb); args.Add(project); if (properties != null) { foreach (var prop in properties) { args.Add($"/p:{prop.Key}={prop.Value}"); } } if (!string.IsNullOrEmpty(verbosity)) { args.Add($"/verbosity:{verbosity}"); } args.Add($"/bl:{Path.Combine (Path.GetDirectoryName (project), "log.binlog")}"); var env = new Dictionary <string, string> (); env ["MSBuildSDKsPath"] = null; env ["MSBUILD_EXE_PATH"] = null; var output = new StringBuilder(); var rv = ExecutionHelper.Execute(Executable, args, env, output, output, workingDirectory: Path.GetDirectoryName(project), timeout: TimeSpan.FromMinutes(10)); if (assert_success && rv != 0) { Console.WriteLine($"'{Executable} {StringUtils.FormatArguments (args)}' failed with exit code {rv}."); Console.WriteLine(output); Assert.AreEqual(0, rv, $"Exit code: {Executable} {StringUtils.FormatArguments (args)}"); } return(new ExecutionResult { StandardOutput = output, StandardError = output, ExitCode = rv, }); default: throw new NotImplementedException($"Unknown dotnet action: '{verb}'"); } }
public int Execute(string toolPath, string arguments, bool always_show_output, params string [] args) { output.Clear(); output_lines = null; var rv = ExecutionHelper.Execute(Configuration.XIBuildPath, $"-t -- {toolPath} " + string.Format(arguments, args), EnvironmentVariables, output, output, workingDirectory: WorkingDirectory); if ((rv != 0 || always_show_output) && output.Length > 0) { Console.WriteLine("\t" + output.ToString().Replace("\n", "\n\t")); } ParseMessages(); return(rv); }
public static string EvaluateVariable(string variable) { var output = new StringBuilder(); var rv = ExecutionHelper.Execute("/usr/bin/make", new string [] { "-C", Path.Combine(SourceRoot, "jenkins"), "print-abspath-variable", $"VARIABLE={variable}" }, environmentVariables: null, stdout: output, stderr: output, timeout: TimeSpan.FromSeconds(5)); if (rv != 0) { throw new Exception($"Failed to evaluate variable '{variable}'. Exit code: {rv}. Output:\n{output}"); } var result = output.ToString().Split(new char [] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Where(v => v.StartsWith(variable + "=", StringComparison.Ordinal)).SingleOrDefault(); if (result == null) { throw new Exception($"Could not find the variable '{variable}' to evaluate."); } return(result.Substring(variable.Length + 1)); }
public int Execute(string toolPath, string arguments, params string [] args) { output.Clear(); output_lines = null; var rv = ExecutionHelper.Execute(toolPath, string.Format(arguments, args), EnvironmentVariables, output, output); if (rv != 0) { if (output.Length > 0) { Console.WriteLine(output); } } ParseMessages(); return(rv); }
public static string [] CopyDotNetSupportingFiles(string targetDirectory) { var srcDirectory = Path.Combine(SourceRoot, "tests", "dotnet"); var files = new string [] { "global.json", "NuGet.config" }; var targets = new string [files.Length]; for (var i = 0; i < files.Length; i++) { var fn = files [i]; targets [i] = Path.Combine(targetDirectory, fn); var src = Path.Combine(srcDirectory, fn); if (!File.Exists(src)) { ExecutionHelper.Execute("make", new [] { "-C", srcDirectory, fn }); } File.Copy(src, targets [i], true); } return(targets); }
public int Execute(string toolPath, IList <string> arguments, bool always_show_output) { output.Clear(); output_lines = null; var args = new List <string> (); args.Add("-t"); args.Add("--"); args.Add(toolPath); args.AddRange(arguments); var rv = ExecutionHelper.Execute(Configuration.XIBuildPath, args, EnvironmentVariables, output, output, workingDirectory: WorkingDirectory); if ((rv != 0 || always_show_output) && output.Length > 0) { Console.WriteLine("\t" + output.ToString().Replace("\n", "\n\t")); } ParseMessages(); return(rv); }
public static string CloneTestDirectory(string directory, string mode) { // Copy the test projects to a temporary directory so that we can run the tests from there without affecting the working directory. // Some tests may modify the test code / projects, and this way the working copy doesn't end up dirty. lock (cloned_directories) { if (cloned_directories.TryGetValue(mode, out var value)) { return(value); } var testsTemporaryDirectory = Xamarin.Cache.CreateTemporaryDirectory($"{Path.GetFileName (directory)}-{mode}"); // We want to start off clean every time the tests are launched if (Directory.Exists(testsTemporaryDirectory)) { Directory.Delete(testsTemporaryDirectory, true); } // Only copy files in git, we want a clean copy var rv = ExecutionHelper.Execute("git", new string [] { "ls-files" }, out var ls_files_output, working_directory: directory, timeout: TimeSpan.FromSeconds(15)); if (rv != 0) { throw new Exception($"Failed to list test files. 'git ls-files' in {directory} failed with exit code {rv}."); } var files = ls_files_output.ToString().Split(new char [] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); foreach (var file in files) { var src = Path.Combine(directory, file); var tgt = Path.Combine(testsTemporaryDirectory, file); var tgtDir = Path.GetDirectoryName(tgt); Directory.CreateDirectory(tgtDir); File.Copy(src, tgt); } cloned_directories [mode] = testsTemporaryDirectory; return(testsTemporaryDirectory); } }
public static string CompileTestAppCode(string target, string targetDirectory, string code, string extraArg = "", Profile profile = Profile.iOS, string appName = "testApp", bool use_csc = false) { var ext = target == "exe" ? "exe" : "dll"; var cs = Path.Combine(targetDirectory, "testApp.cs"); var assembly = Path.Combine(targetDirectory, appName + "." + ext); var root_library = Configuration.GetBaseLibrary(profile); File.WriteAllText(cs, code); string output; StringBuilder args = new StringBuilder(); string fileName = Configuration.GetCompiler(profile, args, use_csc); args.AppendFormat($" /noconfig /t:{target} /nologo /out:{StringUtils.Quote (assembly)} /r:{StringUtils.Quote (root_library)} {StringUtils.Quote (cs)} {extraArg}"); if (ExecutionHelper.Execute(fileName, args.ToString(), out output) != 0) { Console.WriteLine("{0} {1}", fileName, args); Console.WriteLine(output); throw new Exception(output); } return(assembly); }
public static string [] CopyDotNetSupportingFiles(params string[] targetDirectories) { var srcDirectory = Path.Combine(SourceRoot, "tests", "dotnet"); var files = new string [] { "global.json", "NuGet.config" }; var targets = new List <string> (); for (var i = 0; i < files.Length; i++) { var fn = files [i]; var src = Path.Combine(srcDirectory, fn); if (!File.Exists(src)) { ExecutionHelper.Execute("make", new [] { "-C", srcDirectory, fn }); } foreach (var targetDirectory in targetDirectories) { var target = Path.Combine(targetDirectory, fn); File.Copy(src, target, true); targets.Add(target); } } return(targets.ToArray()); }
public static void Build(string project, string configuration = "Debug", string platform = "iPhoneSimulator", string verbosity = null) { ExecutionHelper.Execute(ToolPath, string.Format("/p:Configuration={0} /p:Platform={1} {2} \"{3}\"", configuration, platform, verbosity == null ? string.Empty : "/verbosity:" + verbosity, project)); }