// returns the path to the output XML file public static string PathToXmlFromModules(string executablePath, List <string> searchDirectories, List <string> modules, string outfilePath) { var args = BuildArgs(searchDirectories, modules, outfilePath); ExecAndCollect.Run(executablePath, args); return(outfilePath); }
string GetSDKPath() { if (sdkPath == null) { sdkPath = ExecAndCollect.Run("/usr/bin/xcrun", "--show-sdk-path --sdk " + CompilerInfo.SDKPath, workingDirectory: string.Empty).Trim(); } return(sdkPath); }
void Lipo(List <string> sourcePaths, string outputPath, string libraryName) { var sb = new StringBuilder(); foreach (string s in sourcePaths) { sb.Append($" {Path.Combine (s, libraryName)}"); } ExecAndCollect.Run("/usr/bin/lipo", $"-create {sb.ToString ()} -output {Path.Combine (outputPath, libraryName)}", verbose: verbose); }
public static string CompileToCSharp(DisposableTempDirectory provider, string outputDirectory = null, string moduleName = "Xython", string target = "x86_64-apple-macosx10.9", IEnumerable <string> additionalTypeDatabases = null, bool separateProcess = false, UnicodeMapper unicodeMapper = null, int expectedErrorCount = -1) { NewClassCompiler ncc = DefaultCSharpCompiler(unicodeMapper); List <string> typeDatabases = Compiler.kTypeDatabases; if (additionalTypeDatabases != null) { typeDatabases.AddRange(additionalTypeDatabases); } ClassCompilerLocations classCompilerLocations = new ClassCompilerLocations(new List <string> { provider.DirectoryPath, Compiler.kSwiftRuntimeGlueDirectory }, new List <string> { provider.DirectoryPath, Compiler.kSwiftRuntimeGlueDirectory }, typeDatabases); ClassCompilerNames compilerNames = new ClassCompilerNames(moduleName, null); if (separateProcess) { var args = new StringBuilder(); args.Append($"--debug "); args.Append($"{Path.Combine (Path.GetDirectoryName (ncc.GetType ().Assembly.Location), "tom-swifty.exe")} "); args.Append($"--swift-bin-path={StringUtils.Quote (Compiler.CompilerLocation.SwiftCompilerBin)} "); args.Append($"--swift-lib-path={StringUtils.Quote (Path.GetDirectoryName (Compiler.CompilerLocation.SwiftCompilerLib))} "); args.Append($"--retain-xml-reflection "); foreach (var db in typeDatabases) { args.Append($"--type-database-path={StringUtils.Quote (db)} "); } args.Append($"--retain-swift-wrappers "); args.Append($"--wrapping-module-name={StringUtils.Quote (moduleName)}Wrapping "); foreach (var l in classCompilerLocations.LibraryDirectories) { args.Append($"-L {StringUtils.Quote (l)} "); } foreach (var m in classCompilerLocations.ModuleDirectories) { args.Append($"-M {StringUtils.Quote (m)} "); } args.Append($"-o {StringUtils.Quote (outputDirectory ?? provider.DirectoryPath)} "); args.Append($"--module-name={StringUtils.Quote (moduleName)} "); return(ExecAndCollect.Run("mono", args.ToString())); } else { ErrorHandling errors = ncc.CompileToCSharp(classCompilerLocations, compilerNames, new List <string> { target }, outputDirectory ?? provider.DirectoryPath); CheckErrors(errors, expectedErrorCount); return(null); } }
void YouCantBtouchThis(string csOutputFileName, bool needsSwiftRuntimeLibrary) { var btoucher = BtouchPath(); if (!File.Exists(btoucher)) { errors.Add(new FileNotFoundException($"Unable to find bgen at {kBgenPath}")); return; } var args = new StringBuilder(); BuildBtouchArgs(csOutputFileName, args, needsSwiftRuntimeLibrary); try { ExecAndCollect.Run(btoucher, args.ToString(), workingDirectory: outputDirectory, verbose: false); } catch (Exception e) { errors.Add(e); } }
string Launch(string executable, string args) { return(ExecAndCollect.Run(executable, args, workingDirectory: DirectoryPath, verbose: Verbose)); }
public static string Execute(string workingDirectory, string executable, PlatformName platform) { switch (platform) { case PlatformName.macOS: { // for macOS we create an app bundle with mmp var name = Path.GetFileNameWithoutExtension(executable); var mmp = new StringBuilder(); mmp.AppendLine($"/cache:{StringUtils.Quote (Path.Combine (workingDirectory, "mmp-cache"))}"); mmp.AppendLine($"/root-assembly:{StringUtils.Quote (Path.Combine (workingDirectory, executable))}"); mmp.AppendLine($"/sdkroot:/Applications/Xcode.app"); mmp.AppendLine($"/profile:Xamarin.Mac,v2.0,Profile=Mobile"); mmp.AppendLine($"/arch:x86_64"); mmp.AppendLine($"/assembly:{StringUtils.Quote (Path.Combine (ConstructorTests.kXamarinMacDir, "Xamarin.Mac.dll"))}"); mmp.AppendLine($"/output:{StringUtils.Quote (Path.Combine (workingDirectory, name))}"); mmp.AppendLine($"/assembly:{StringUtils.Quote (Path.Combine (ConstructorTests.kSwiftRuntimeMacOutputDirectory, ConstructorTests.kSwiftRuntimeLibraryMac))}.dll"); mmp.AppendLine($"/debug"); mmp.AppendLine($"/linksdkonly"); // FIXME: link all doesn't work for all tests, this needs looking into. mmp.AppendLine($"/native-reference:{StringUtils.Quote (Compiler.kSwiftRuntimeGlueDirectory)}"); // link with XamGlue.framework foreach (var dylib in Directory.GetFiles(workingDirectory, "*.dylib")) // Link with any dylibs produced by the test { mmp.AppendLine($"/native-reference:{StringUtils.Quote (dylib)}"); } mmp.AppendLine($"/v /v /v /v"); var output = new StringBuilder(); var responseFile = Path.Combine(workingDirectory, name + ".rsp"); File.WriteAllText(responseFile, mmp.ToString()); var rv = ExecAndCollect.RunCommand("/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp", "--link_flags=-headerpad_max_install_names " + StringUtils.Quote($"@{responseFile}"), output: output, verbose: true); if (rv != 0) { Console.WriteLine(output); throw new Exception($"Failed to run mmp, exit code: {rv}"); } // This should probably go into mmp/mtouch // run swift-stdlib-tool to get swift libraries into the app. var appPath = Path.Combine(workingDirectory, name, name + ".app"); var appExecutable = Path.Combine(appPath, "Contents", "MacOS", name); var swift_stdlib_tool = new StringBuilder(); swift_stdlib_tool.Append($"swift-stdlib-tool "); swift_stdlib_tool.Append($"--copy "); swift_stdlib_tool.Append($"--verbose "); swift_stdlib_tool.Append($"--scan-executable {StringUtils.Quote (appExecutable)} "); swift_stdlib_tool.Append($"--platform macosx "); swift_stdlib_tool.Append($"--destination {StringUtils.Quote (Path.Combine (appPath, "Contents", "Frameworks"))} "); swift_stdlib_tool.Append($"--strip-bitcode "); swift_stdlib_tool.Append($"--scan-folder {StringUtils.Quote (Path.Combine (appPath, "Contents", "MonoBundle"))} "); swift_stdlib_tool.Append($"--scan-folder {StringUtils.Quote (Path.Combine (appPath, "Contents", "Frameworks"))} "); swift_stdlib_tool.Append($"--platform macosx "); swift_stdlib_tool.Append($"--source-libraries {StringUtils.Quote (Compiler.CompilerLocation.SwiftCompilerLib)} "); output.Clear(); rv = ExecAndCollect.RunCommand("xcrun", swift_stdlib_tool.ToString(), output: output, verbose: true); if (rv != 0) { Console.WriteLine(output); throw new Exception($"Failed to run swift-stdlib-tool, exit code: {rv}\n{output}\n"); } // This should probably go into mmp/mtouch // make sure the executable has the Frameworks and MonoBundle directories as rpaths. var install_name_tool = new StringBuilder(); install_name_tool.Append($"install_name_tool "); install_name_tool.Append($"-add_rpath @executable_path/../Frameworks "); install_name_tool.Append($"-add_rpath @executable_path/../MonoBundle "); install_name_tool.Append($"{StringUtils.Quote (Path.Combine (appPath, "Contents", "MacOS", name))} "); output.Clear(); rv = ExecAndCollect.RunCommand("xcrun", install_name_tool.ToString(), output: output, verbose: true); if (rv != 0) { Console.WriteLine(output); throw new Exception($"Failed to run install_name_tool, exit code: {rv}\n{output}\n"); } var exec_output = new StringBuilder(); var exec_env = new Dictionary <string, string> (); //exec_env.Add ("MONO_LOG_LEVEL", "debug"); //exec_env.Add ("MONO_LOG_MASK", "dll"); var exec_rv = Compiler.RunCommandWithLeaks(appExecutable, new StringBuilder(), exec_env, exec_output); if (exec_rv != 0) { Console.WriteLine(exec_output); throw new Exception($"Execution failed with exit code {exec_rv}\n{output}\n{exec_output}"); } return(exec_output.ToString()); } case PlatformName.iOS: Assert.Ignore($"Execution does not apply during a test run for {platform}, tests will be executed as part of the device tests."); return(string.Empty); case PlatformName.None: { return(Compiler.RunWithMono(executable, workingDirectory, platform: platform)); } default: throw new NotImplementedException(platform.ToString()); } }