[tests] Set the correct environment variables when executing msbuild from the mtouch tests. (#5534)

This is usually not a problem, because these variables are already set when
running from the command-line or xharness. However, it shows up when running
tests directly from VSfM.
This commit is contained in:
Rolf Bjarne Kvinge 2019-02-04 07:59:29 +01:00 коммит произвёл GitHub
Родитель cf86b3e1ef
Коммит db01babe71
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 62 добавлений и 8 удалений

Просмотреть файл

@ -9,6 +9,7 @@ using System.Threading;
using System.Diagnostics;
using NUnit.Framework;
using Xamarin.Utils;
namespace Xamarin.Tests
{
@ -379,9 +380,41 @@ namespace Xamarin.Tests
}
}
public static void Build (string project, string configuration = "Debug", string platform = "iPhoneSimulator", string verbosity = null, TimeSpan? timeout = null)
public static void BuildXM (string project, string configuration = "Debug", string platform = "iPhoneSimulator", string verbosity = null, TimeSpan? timeout = null, string [] arguments = null)
{
ExecutionHelper.Execute (ToolPath, string.Format ("-- /p:Configuration={0} /p:Platform={1} {2} \"{3}\"", configuration, platform, verbosity == null ? string.Empty : "/verbosity:" + verbosity, project), timeout: timeout);
Build (project,
new Dictionary<string, string> {
{ "MD_APPLE_SDK_ROOT", Path.GetDirectoryName (Path.GetDirectoryName (Configuration.xcode_root)) },
{ "TargetFrameworkFallbackSearchPaths", Path.Combine (Configuration.TargetDirectoryXM, "Library", "Frameworks", "Mono.framework", "External", "xbuild-frameworks") },
{ "MSBuildExtensionsPathFallbackPathsOverride", Path.Combine (Configuration.TargetDirectoryXM, "Library", "Frameworks", "Mono.framework", "External", "xbuild") },
{ "XamarinMacFrameworkRoot", Path.Combine (Configuration.TargetDirectoryXM, "Library", "Frameworks", "Xamarin.Mac.framework", "Versions", "Current") },
{ "XAMMAC_FRAMEWORK_PATH", Path.Combine (Configuration.TargetDirectoryXM, "Library", "Frameworks", "Xamarin.Mac.framework", "Versions", "Current") },
}, configuration, platform, verbosity, timeout, arguments);
}
public static void BuildXI (string project, string configuration = "Debug", string platform = "iPhoneSimulator", string verbosity = null, TimeSpan? timeout = null, string [] arguments = null)
{
Build (project,
new Dictionary<string, string> {
{ "MD_APPLE_SDK_ROOT", Path.GetDirectoryName (Path.GetDirectoryName (Configuration.xcode_root)) },
{ "TargetFrameworkFallbackSearchPaths", Path.Combine (Configuration.TargetDirectoryXI, "Library", "Frameworks", "Mono.framework", "External", "xbuild-frameworks") },
{ "MSBuildExtensionsPathFallbackPathsOverride", Path.Combine (Configuration.TargetDirectoryXI, "Library", "Frameworks", "Mono.framework", "External", "xbuild") },
{ "MD_MTOUCH_SDK_ROOT", Path.Combine (Configuration.TargetDirectoryXI, "Library", "Frameworks", "Xamarin.iOS.framework", "Versions", "Current") },
}, configuration, platform, verbosity, timeout, arguments);
}
static void Build (string project, Dictionary<string, string> environmentVariables, string configuration = "Debug", string platform = "iPhoneSimulator", string verbosity = null, TimeSpan? timeout = null, string [] arguments = null)
{
ExecutionHelper.Execute (ToolPath,
new string [] {
"--",
$"/p:Configuration={configuration}",
$"/p:Platform={platform}",
$"/verbosity:{(string.IsNullOrEmpty (verbosity) ? "normal" : verbosity)}",
project
}.Union (arguments ?? new string [] { }).ToArray (),
environmentVariables: environmentVariables,
timeout: timeout);
}
}
@ -465,6 +498,12 @@ namespace Xamarin.Tests
return rv;
}
// The arguments are automatically quoted.
public static int Execute (string fileName, string[] arguments, Dictionary<string, string> environmentVariables, StringBuilder stdout, StringBuilder stderr, TimeSpan? timeout = null, string workingDirectory = null)
{
return Execute (fileName, string.Join (" ", Xamarin.Utils.StringUtils.Quote (arguments)), environmentVariables, stdout, stderr, timeout, workingDirectory);
}
public static int Execute (string fileName, string arguments, Dictionary<string, string> environmentVariables, StringBuilder stdout, StringBuilder stderr, TimeSpan? timeout = null, string workingDirectory = null)
{
if (stdout == null)
@ -489,6 +528,10 @@ namespace Xamarin.Tests
[DllImport ("libc")]
private static extern void kill (int pid, int sig);
public static string Execute (string fileName, string[] arguments, bool throwOnError = true, Dictionary<string, string> environmentVariables = null, bool hide_output = false, TimeSpan? timeout = null)
{
return Execute (fileName, string.Join (" ", StringUtils.Quote (arguments)), throwOnError, environmentVariables, hide_output, timeout);
}
public static string Execute (string fileName, string arguments, bool throwOnError = true, Dictionary<string,string> environmentVariables = null,
bool hide_output = false, TimeSpan? timeout = null

Просмотреть файл

@ -1937,7 +1937,7 @@ public class B
if (!File.Exists (fn)) {
var csproj = Path.Combine (Configuration.SourceRoot, "tests", "bindings-test", "bindings-test" + GetProjectSuffix (profile) + ".csproj");
XBuild.Build (csproj, platform: "AnyCPU");
XBuild.BuildXI (csproj, platform: "AnyCPU");
}
return fn;
@ -1950,7 +1950,7 @@ public class B
if (!File.Exists (fn)) {
var csproj = Path.Combine (Configuration.SourceRoot, "tests", "bindings-framework-test", "bindings-framework-test" + GetProjectSuffix (profile) + ".csproj");
XBuild.Build (csproj, platform: "AnyCPU");
XBuild.BuildXI (csproj, platform: "AnyCPU");
}
return fn;
@ -2529,7 +2529,7 @@ public class B
}
var platform = target == Target.Dev ? "iPhone" : "iPhoneSimulator";
var csproj = Path.Combine (Configuration.SourceRoot, "tests" + subdir, testname, testname + GetProjectSuffix (profile) + ".csproj");
XBuild.Build (csproj, configuration, platform, timeout: TimeSpan.FromMinutes (15));
XBuild.BuildXI (csproj, configuration, platform, timeout: TimeSpan.FromMinutes (15));
}
[Test]
@ -3080,7 +3080,7 @@ class Test {
var projectDir = Path.Combine (Configuration.SourceRoot, "tests", "link all");
var project = Path.Combine (projectDir, "link all.csproj");
XBuild.Build (project, platform: "iPhone");
XBuild.BuildXI (project, platform: "iPhone");
var appPath = Path.Combine (projectDir, "bin", "iPhone", "Debug", "link all.app");
foreach (var device in devices) {
if (mtouch.InstallOnDevice (device, appPath) != 0) {
@ -3115,7 +3115,7 @@ class Test {
var containerPath = Path.Combine (projectDir, "bin", "iPhone", "Debug", "MyWatch2Container.app");
var appPath = Path.Combine (containerPath, "Watch", "MyWatchApp2.app");
XBuild.Build (project, platform: "iPhone");
XBuild.BuildXI (project, platform: "iPhone");
if (!Directory.Exists (appPath))
Assert.Fail ("Failed to build the watchOS app.");
@ -4147,7 +4147,7 @@ public class Dummy {
File.WriteAllText (csprojpath, csproj);
File.WriteAllText (testfilepath, testfile);
File.WriteAllText (infoplistpath, MTouchTool.CreatePlist (profile, "testapp"));
XBuild.Build (csprojpath, configuration, platform);
XBuild.BuildXI (csprojpath, configuration, platform);
var environment_variables = new Dictionary<string, string> ();
if (!clean_simulator)
environment_variables ["SKIP_SIMULATOR_SETUP"] = "1";

Просмотреть файл

@ -15,6 +15,17 @@ namespace Xamarin.Utils {
static char shellQuoteChar;
static char[] mustQuoteCharacters = new char [] { ' ', '\'', ',', '$', '\\' };
public static string[] Quote (params string[] array)
{
if (array == null || array.Length == 0)
return array;
var rv = new string [array.Length];
for (var i = 0; i < array.Length; i++)
rv [i] = Quote (array [i]);
return rv;
}
public static string Quote (string f)
{
if (String.IsNullOrEmpty (f))