string CompileLibrary(Platform platform, string code = null, string libraryName = null) { int exitCode; if (libraryName == null) { libraryName = "library"; } var tmpdir = Xamarin.Cache.CreateTemporaryDirectory(); var cs_path = Path.Combine(tmpdir, libraryName + ".cs"); var dll_path = Path.Combine(tmpdir, libraryName + ".dll"); if (code == null) { code = "public class Test { public static void X () {} }"; } File.WriteAllText(cs_path, code); if (!Embedder.RunProcess("/Library/Frameworks/Mono.framework/Versions/Current/bin/csc", $"/target:library {Embedder.Quote (cs_path)} /out:{Embedder.Quote (dll_path)}", out exitCode)) { Assert.Fail("Failed to compile test code"); } return(dll_path); }
public void ABI(Platform platform, string abi) { var dll = CompileLibrary(platform); var tmpdir = Xamarin.Cache.CreateTemporaryDirectory(); Driver.Main2("--platform", platform.ToString(), "--abi", abi, "-c", dll, "-o", tmpdir); string output; int exitCode; Assert.IsTrue(Embedder.RunProcess("xcrun", $"lipo -info {tmpdir}/libLibrary.dylib", out exitCode, out output), "lipo"); StringAssert.IsMatch($"Non-fat file: .* is architecture: {abi}", output, "architecture"); }
public static void RunProcess(string filename, string arguments, out string stdout, string message) { int exitCode; Console.WriteLine($"{filename} {arguments}"); // We capture stderr too, otherwise it won't show up in the test unit pad's output. if (Embedder.RunProcess(filename, arguments, out exitCode, out stdout, capture_stderr: true)) { return; } Console.WriteLine($"Command failed with exit code: {exitCode}"); Console.WriteLine(stdout); Console.WriteLine($"Command failed with exit code: {exitCode}"); Assert.Fail($"Executing '{filename} {arguments}' failed with exit code {exitCode}: {message}"); }
public void XcodeBuildErrorTest(string directoryTest, string csprojName, string objcmFileName, Platform platform, Configuration config, string errorToSearch) { Assert.IsTrue(Directory.Exists(XcodeFolderPath), "XcodeFolderPath"); Assert.IsTrue(File.Exists(MonoMsBuildPath), "MonoMsBuildPath"); Assert.IsTrue(File.Exists(MonoPath), "MonoPath"); var testcaseBaseDir = Path.Combine(XcodeFolderPath, directoryTest); var tempWorkingDir = Xamarin.Cache.CreateTemporaryDirectory(); var e4kOutputDir = Path.Combine(tempWorkingDir, "E4KOutput"); Asserts.RunProcess(MonoMsBuildPath, $"/p:Configuration={config} /p:IntermediateOutputPath={Path.Combine (tempWorkingDir, "obj")}/ /p:OutputPath={Path.Combine (tempWorkingDir, "DllOutput")} {Path.Combine (testcaseBaseDir, csprojName)}.csproj", "msbuildProc"); var eargs = new List <string> { "-c", $"{Path.Combine (tempWorkingDir, "DllOutput", csprojName)}.dll", $"-o={e4kOutputDir}" }; if (config == Configuration.Debug) { eargs.Add("--debug"); } Driver.Main2(eargs.ToArray()); // Sadly no C# 7 yet // (string sdk, string arch, string sdkName, string minVersion) build_info; Tuple <string, string, string, string> build_info = null; switch (platform) { case Platform.macOS: build_info = new Tuple <string, string, string, string> ("MacOSX", "x86_64", "macosx", "10.7"); break; case Platform.iOS: build_info = new Tuple <string, string, string, string> ("iPhoneSimulator", "x86_64", "ios-simulator", "8.0"); break; case Platform.tvOS: build_info = new Tuple <string, string, string, string> ("AppleTVSimulator", "x86_64", "tvos-simulator", "9.0"); break; case Platform.watchOS: build_info = new Tuple <string, string, string, string> ("WatchSimulator", "i386", "watchos-simulator", "2.0"); break; } var clangArgs = new StringBuilder("clang "); if (config == Configuration.Debug) { clangArgs.Append("-g -O0 "); } else { clangArgs.Append("-O2 "); } clangArgs.Append("-fobjc-arc "); clangArgs.Append("-ObjC "); clangArgs.Append($"-arch {build_info.Item2} "); clangArgs.Append($"-isysroot {Embedder.XcodeApp}/Contents/Developer/Platforms/{build_info.Item1}.platform/Developer/SDKs/{build_info.Item1}.sdk "); clangArgs.Append($"-m{build_info.Item3}-version-min={build_info.Item4} "); clangArgs.Append($"-I{e4kOutputDir} "); clangArgs.Append($"-c {Path.Combine (testcaseBaseDir, objcmFileName)} "); clangArgs.Append($"-o {Path.Combine (tempWorkingDir, "foo.o")} "); // Embedder.RunProcess returns false if exitcode != 0 Assert.IsFalse(Embedder.RunProcess("xcrun", clangArgs.ToString(), out int exitCode, out string output, capture_stderr: true), "clangbuild"); Assert.That(output, Does.Contain(errorToSearch), $"Not found: {errorToSearch}"); }