string GenerateCommandLineArguments(string dylib) { var args = new CommandLineArgumentBuilder(); args.Add("-v"); args.Add("--force"); args.Add("--sign"); args.AddQuoted(SigningKey); if (!string.IsNullOrEmpty(Keychain)) { args.Add("--keychain"); args.AddQuoted(Path.GetFullPath(Keychain)); } if (DisableTimestamp) { args.Add("--timestamp=none"); } if (!string.IsNullOrEmpty(ExtraArgs)) { args.Add(ExtraArgs); } args.AddQuoted(dylib); return(args.ToString()); }
int CopySceneKitAssets(string scnassets, string output, string intermediate) { var environment = new Dictionary <string, string> (); var args = new CommandLineArgumentBuilder(); environment.Add("PATH", DeveloperRootBinDir); environment.Add("DEVELOPER_DIR", SdkDevPath); environment.Add("XCODE_DEVELOPER_USR_PATH", DeveloperRootBinDir); args.AddQuoted(Path.GetFullPath(scnassets)); args.Add("-o"); args.AddQuoted(Path.GetFullPath(output)); args.AddQuotedFormat("--sdk-root={0}", SdkRoot); if (AppleSdkSettings.XcodeVersion.Major >= 10) { var platform = PlatformUtils.GetTargetPlatform(SdkPlatform, IsWatchApp); if (platform != null) { args.AddQuotedFormat("--target-platform={0}", platform); } args.AddQuotedFormat("--target-version={0}", SdkVersion); } else { args.AddQuotedFormat("--target-version-{0}={1}", OperatingSystem, SdkVersion); } args.AddQuotedFormat("--target-build-dir={0}", Path.GetFullPath(intermediate)); args.AddQuotedFormat("--resources-folder-path={0}", AppBundleName); var startInfo = GetProcessStartInfo(environment, GetFullPathToTool(), args.ToString()); try { using (var process = new Process()) { Log.LogMessage(MessageImportance.Normal, "Tool {0} execution started with arguments: {1}", startInfo.FileName, startInfo.Arguments); process.StartInfo = startInfo; process.OutputDataReceived += (sender, e) => { if (e.Data == null) { return; } Log.LogMessage(MessageImportance.Low, "{0}", e.Data); }; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); Log.LogMessage(MessageImportance.Low, "Tool {0} execution finished.", startInfo.FileName); return(process.ExitCode); } } catch (Exception ex) { Log.LogError("Error executing tool '{0}': {1}", startInfo.FileName, ex.Message); return(-1); } }
protected override string GenerateCommandLineCommands() { var prefixes = BundleResource.SplitResourcePrefixes(ResourcePrefix); var intermediate = Path.Combine(IntermediateOutputPath, ToolName); var logicalName = BundleResource.GetLogicalName(ProjectDir, prefixes, SourceFile, !string.IsNullOrEmpty(SessionId)); var path = Path.Combine(intermediate, logicalName); var args = new CommandLineArgumentBuilder(); var dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } OutputFile = new TaskItem(Path.ChangeExtension(path, ".air")); OutputFile.SetMetadata("LogicalName", Path.ChangeExtension(logicalName, ".air")); args.Add("-arch", "air64"); args.Add("-emit-llvm"); args.Add("-c"); args.Add("-gline-tables-only"); args.Add("-ffast-math"); args.Add(string.Format("-std={0}-metal1.0", OperatingSystem)); args.Add("-serialize-diagnostics"); args.AddQuoted(Path.ChangeExtension(path, ".dia")); args.Add("-o"); args.AddQuoted(Path.ChangeExtension(path, ".air")); args.AddQuoted(SourceFile.ItemSpec); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("--verify"); args.Add("-vvvv"); switch (Platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: case ApplePlatform.WatchOS: case ApplePlatform.MacCatalyst: args.AddQuoted("-R=anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.1] exists and (certificate leaf[field.1.2.840.113635.100.6.1.2] exists or certificate leaf[field.1.2.840.113635.100.6.1.4] exists)"); break; case ApplePlatform.MacOSX: args.Add("--deep"); break; default: throw new InvalidOperationException(string.Format(MSBStrings.InvalidPlatform, Platform)); } args.AddQuoted(Resource); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); if (Recursive) { args.Add("-r"); } if (Symlinks) { args.Add("-y"); } args.AddQuoted(OutputFile.GetMetadata("FullPath")); var root = WorkingDirectory.GetMetadata("FullPath"); for (int i = 0; i < Sources.Length; i++) { var relative = PathUtils.AbsoluteToRelative(root, Sources[i].GetMetadata("FullPath")); args.AddQuoted(relative); } return(args.ToString()); }
int Compile(ITaskItem item, string outputDir, string log, string partialPlist) { var environment = new Dictionary <string, string> (); var args = new CommandLineArgumentBuilder(); args.Add("compile"); args.AddQuoted(item.ItemSpec); args.AddQuoted(Path.GetFullPath(outputDir)); args.Add("--output-partial-info-plist"); args.AddQuoted(partialPlist); var startInfo = GetProcessStartInfo(environment, GetFullPathToTool(), args.ToString()); var errors = new StringBuilder(); int exitCode; try { Log.LogMessage(MessageImportance.Normal, MSBStrings.M0001, startInfo.FileName, startInfo.Arguments); using (var stdout = File.CreateText(log)) { using (var stderr = new StringWriter(errors)) { using (var process = ProcessUtils.StartProcess(startInfo, stdout, stderr)) { process.Wait(); exitCode = process.Result; } } Log.LogMessage(MessageImportance.Low, MSBStrings.M0002, startInfo.FileName, exitCode); } } catch (Exception ex) { Log.LogError("Error executing tool '{0}': {1}", startInfo.FileName, ex.Message); File.Delete(log); return(-1); } if (exitCode != 0) { // Note: coremlc exited with an error. Dump everything we can to help the user // diagnose the issue and then delete the log file so that rebuilding tries // again. if (errors.Length > 0) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "{0}", errors); } Log.LogError(MSBStrings.E0117, ToolName, exitCode); // Note: If the log file exists, log those warnings/errors as well... if (File.Exists(log)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "{0}", File.ReadAllText(log)); File.Delete(log); } } return(exitCode); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.AddQuoted(Source.ItemSpec); args.AddQuoted(Destination.ItemSpec); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var prefixes = BundleResource.SplitResourcePrefixes(ResourcePrefix); var intermediate = Path.Combine(IntermediateOutputPath, ToolName); var logicalName = BundleResource.GetLogicalName(ProjectDir, prefixes, SourceFile, !string.IsNullOrEmpty(SessionId)); var path = Path.Combine(intermediate, logicalName); var args = new CommandLineArgumentBuilder(); var dir = Path.GetDirectoryName(path); string minimumDeploymentTarget; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (AppManifest != null) { var plist = PDictionary.FromFile(AppManifest.ItemSpec); PString value; if (!plist.TryGetValue(MinimumDeploymentTargetKey, out value) || string.IsNullOrEmpty(value.Value)) { minimumDeploymentTarget = SdkVersion; } else { minimumDeploymentTarget = value.Value; } } else { minimumDeploymentTarget = SdkVersion; } OutputFile = new TaskItem(Path.ChangeExtension(path, ".air")); OutputFile.SetMetadata("LogicalName", Path.ChangeExtension(logicalName, ".air")); args.Add("-arch", "air64"); args.Add("-emit-llvm"); args.Add("-c"); args.Add("-gline-tables-only"); args.Add("-ffast-math"); args.Add("-serialize-diagnostics"); args.AddQuoted(Path.ChangeExtension(path, ".dia")); args.Add("-o"); args.AddQuoted(Path.ChangeExtension(path, ".air")); args.Add(string.Format("-m{0}-version-min={1}", OperatingSystem, minimumDeploymentTarget)); args.AddQuoted(SourceFile.ItemSpec); return(args.ToString()); }
// Note: Xamarin.Mac and Xamarin.iOS should both override this method to do pass platform-specific verify rules protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("--verify"); args.Add("-vvvv"); args.AddQuoted(Resource); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("--verify"); args.Add("-vvvv"); args.Add("-R='anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.1] exists and (certificate leaf[field.1.2.840.113635.100.6.1.2] exists or certificate leaf[field.1.2.840.113635.100.6.1.4] exists)'"); args.AddQuoted(Resource); return(args.ToString()); }
string GenerateCommandLineArguments(ITaskItem item) { var args = new CommandLineArgumentBuilder(); args.Add("-v"); args.Add("--force"); if (IsAppExtension) { args.Add("--deep"); } if (UseHardenedRuntime) { args.Add("-o runtime"); } args.Add("--sign"); args.AddQuoted(SigningKey); if (!string.IsNullOrEmpty(Keychain)) { args.Add("--keychain"); args.AddQuoted(Path.GetFullPath(Keychain)); } if (!string.IsNullOrEmpty(ResourceRules)) { args.Add("--resource-rules"); args.AddQuoted(Path.GetFullPath(ResourceRules)); } if (!string.IsNullOrEmpty(Entitlements)) { args.Add("--entitlements"); args.AddQuoted(Path.GetFullPath(Entitlements)); } if (DisableTimestamp) { args.Add("--timestamp=none"); } if (!string.IsNullOrEmpty(ExtraArgs)) { args.Add(ExtraArgs); } args.AddQuoted(Path.GetFullPath(item.ItemSpec)); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.AddQuoted(Source !.ItemSpec); args.AddQuoted(Destination !.ItemSpec); if (!string.IsNullOrEmpty(AdditionalArguments)) { args.Add(AdditionalArguments); } return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("--compress"); args.AddQuoted(InputScene); args.Add("-o"); args.AddQuoted(OutputScene); args.AddQuotedFormat("--sdk-root={0}", SdkRoot); args.AddQuotedFormat("--target-version-{0}={1}", OperatingSystem, SdkVersion); args.AddQuotedFormat("--target-build-dir={0}", IntermediateOutputPath); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("-r"); args.AddQuoted(Archive.ItemSpec); foreach (var item in Items) { args.AddQuoted(item.ItemSpec); } return(args.ToString()); }
static bool IsCodesigned(string path) { var psi = new ProcessStartInfo("/usr/bin/codesign"); var args = new CommandLineArgumentBuilder(); args.Add("--verify"); args.AddQuoted(path); psi.Arguments = args.ToString(); var process = Process.Start(psi); process.WaitForExit(); return(process.ExitCode == 0); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("--file"); args.AddQuoted(FilePath); args.Add("--type"); args.AddQuoted(GetFileTypeValue()); args.Add("--username"); args.AddQuoted(Username); args.Add("--password"); args.AddQuoted(Password); args.Add("--output-format"); args.Add("xml"); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { Log.LogMessage("Creating installer package"); var args = new CommandLineArgumentBuilder(); if (!string.IsNullOrEmpty(ProductDefinition)) { args.Add("--product"); args.AddQuoted(Path.GetFullPath(ProductDefinition)); } args.Add("--component"); args.AddQuoted(Path.Combine(OutputDirectory, Path.GetFileName(AppBundleDir))); args.Add("/Applications"); if (EnablePackageSigning) { args.Add("--sign"); args.AddQuoted(GetPackageSigningCertificateCommonName()); } if (!string.IsNullOrEmpty(PackagingExtraArgs)) { try { AppendExtraArgs(args, PackagingExtraArgs); } catch (FormatException) { Log.LogError(MSBStrings.E0123); return(string.Empty); } } if (string.IsNullOrEmpty(PkgPackagePath)) { string projectVersion = GetProjectVersion(); string target = string.Format("{0}{1}.pkg", Name, String.IsNullOrEmpty(projectVersion) ? "" : "-" + projectVersion); PkgPackagePath = Path.Combine(OutputDirectory, target); } args.AddQuoted(PkgPackagePath); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var prefixes = BundleResource.SplitResourcePrefixes(ResourcePrefix); var intermediate = Path.Combine(IntermediateOutputPath, ToolName); var logicalName = BundleResource.GetLogicalName(ProjectDir, prefixes, SourceFile, !string.IsNullOrEmpty(SessionId)); var path = Path.Combine(intermediate, logicalName); var args = new CommandLineArgumentBuilder(); var dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } OutputFile = new TaskItem(Path.ChangeExtension(path, ".air")); OutputFile.SetMetadata("LogicalName", Path.ChangeExtension(logicalName, ".air")); args.Add("-arch", "air64"); args.Add("-emit-llvm"); args.Add("-c"); args.Add("-gline-tables-only"); args.Add("-ffast-math"); args.Add("-serialize-diagnostics"); args.AddQuoted(Path.ChangeExtension(path, ".dia")); args.Add("-o"); args.AddQuoted(Path.ChangeExtension(path, ".air")); if (Platform == ApplePlatform.MacCatalyst) { args.Add($"-target"); args.Add($"air64-apple-ios{MinimumOSVersion}-macabi"); } else { args.Add(PlatformFrameworkHelper.GetMinimumVersionArgument(TargetFrameworkMoniker, SdkIsSimulator, MinimumOSVersion)); } args.AddQuoted(SourceFile.ItemSpec); return(args.ToString()); }
protected static int Ditto(string source, string destination) { var args = new CommandLineArgumentBuilder(); args.AddQuoted(source); args.AddQuoted(destination); var psi = new ProcessStartInfo("/usr/bin/ditto", args.ToString()) { RedirectStandardOutput = false, RedirectStandardError = false, UseShellExecute = false, CreateNoWindow = true, }; using (var process = Process.Start(psi)) { process.WaitForExit(); return(process.ExitCode); } }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("-r", "-y"); args.AddQuoted(OutputFile.GetMetadata("FullPath")); args.AddQuoted("META-INF"); long size = 0; int count = 0; foreach (var path in Directory.EnumerateFileSystemEntries(Source.ItemSpec)) { if (Directory.Exists(path)) { foreach (var item in Directory.EnumerateFiles(path)) { var info = new FileInfo(item); size += info.Length; count++; } } else { var info = new FileInfo(path); size += info.Length; } args.AddQuoted(Path.GetFileName(path)); count++; } SaveMetaFile(count, size); return(args.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); args.Add("--compress"); args.AddQuoted(InputScene); args.Add("-o"); args.AddQuoted(OutputScene); args.AddQuotedFormat("--sdk-root={0}", SdkRoot); args.AddQuotedFormat("--target-build-dir={0}", IntermediateOutputPath); if (AppleSdkSettings.XcodeVersion.Major >= 13) { // I'm not sure which Xcode version these options are available in, but it's at least Xcode 13+ args.AddQuotedFormat("--target-version={0}", SdkVersion); args.AddQuotedFormat("--target-platform={0}", PlatformUtils.GetTargetPlatform(SdkPlatform, IsWatchApp)); } else { args.AddQuotedFormat("--target-version-{0}={1}", OperatingSystem, SdkVersion); } return(args.ToString()); }
// Creates a response file for the given arguments, and returns the command line // with the response file and any arguments that can't go into the response file. protected string CreateResponseFile(CommandLineArgumentBuilder arguments, IList <string> nonResponseArguments) { // Generate a response file var responseFile = Path.GetFullPath(ResponseFilePath); if (File.Exists(responseFile)) { File.Delete(responseFile); } try { using (var fs = File.Create(responseFile)) { using (var writer = new StreamWriter(fs)) writer.Write(arguments); } } catch (Exception ex) { Log.LogWarning("Failed to create response file '{0}': {1}", responseFile, ex); } // Some arguments can not safely go in the response file and are // added separately. They must go _after_ the response file // as they may override options passed in the response file var actualArgs = new CommandLineArgumentBuilder(); actualArgs.AddQuoted($"@{responseFile}"); if (nonResponseArguments != null) { foreach (var arg in nonResponseArguments) { actualArgs.AddQuoted(arg); } } // Generate the command line return(actualArgs.ToString()); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); bool msym; args.AddLine("/verbose"); if (Debug) { args.AddLine("/debug"); } if (!string.IsNullOrEmpty(OutputPath)) { args.AddQuotedLine("/output:" + Path.GetFullPath(OutputPath)); } if (!string.IsNullOrEmpty(ApplicationName)) { args.AddQuotedLine("/name:" + ApplicationName); } if (TargetFrameworkIdentifier == "Xamarin.Mac") { args.AddLine("/profile:Xamarin.Mac,Version=v2.0,Profile=Mobile"); } else if (UseXamMacFullFramework) { args.AddLine($"/profile:Xamarin.Mac,Version={TargetFrameworkVersion},Profile=Full"); } else { args.AddLine($"/profile:Xamarin.Mac,Version={TargetFrameworkVersion},Profile=System"); } XamMacArch arch; if (!Enum.TryParse(Architecture, true, out arch)) { arch = XamMacArch.Default; } if (arch == XamMacArch.Default) { arch = XamMacArch.x86_64; } if (arch.HasFlag(XamMacArch.i386)) { args.AddLine("/arch:i386"); } if (arch.HasFlag(XamMacArch.x86_64)) { args.AddLine("/arch:x86_64"); } if (!string.IsNullOrEmpty(ArchiveSymbols) && bool.TryParse(ArchiveSymbols.Trim(), out msym)) { args.AddLine("--msym:" + (msym ? "yes" : "no")); } args.AddLine(string.Format("--http-message-handler={0}", HttpClientHandler)); if (AppManifest != null) { try { var plist = PDictionary.FromFile(AppManifest.ItemSpec); PString v; string minimumDeploymentTarget; if (!plist.TryGetValue(ManifestKeys.LSMinimumSystemVersion, out v) || string.IsNullOrEmpty(v.Value)) { minimumDeploymentTarget = SdkVersion; } else { minimumDeploymentTarget = v.Value; } args.AddLine(string.Format("/minos={0}", minimumDeploymentTarget)); } catch (Exception ex) { Log.LogWarning(null, null, null, AppManifest.ItemSpec, 0, 0, 0, 0, "Error loading '{0}': {1}", AppManifest.ItemSpec, ex.Message); } } if (Profiling) { args.AddLine("/profiling"); } if (EnableSGenConc) { args.AddLine("/sgen-conc"); } switch ((LinkMode ?? string.Empty).ToLower()) { case "full": break; case "sdkonly": args.AddLine("/linksdkonly"); break; case "platform": args.AddLine("/linkplatform"); break; default: args.AddLine("/nolink"); break; } if (!string.IsNullOrEmpty(AotMode) && AotMode != "None") { var aot = $"--aot:{AotMode.ToLower ()}"; if (HybridAOT) { aot += "|hybrid"; } if (!string.IsNullOrEmpty(ExplicitAotAssemblies)) { aot += $",{ExplicitAotAssemblies}"; } args.AddLine(aot); } if (!string.IsNullOrEmpty(I18n)) { args.AddQuotedLine("/i18n:" + I18n); } if (ExplicitReferences != null) { foreach (var asm in ExplicitReferences) { args.AddQuotedLine("/assembly:" + Path.GetFullPath(asm.ItemSpec)); } } if (!string.IsNullOrEmpty(ApplicationAssembly.ItemSpec)) { args.AddQuotedLine("/root-assembly:" + Path.GetFullPath(ApplicationAssembly.ItemSpec)); } if (NativeReferences != null) { foreach (var nr in NativeReferences) { args.AddQuotedLine("/native-reference:" + Path.GetFullPath(nr.ItemSpec)); } } if (IsAppExtension) { args.AddQuotedLine("/extension"); } if (IsXPCService) { args.AddQuotedLine("/xpc"); } args.AddQuotedLine("/sdkroot:" + SdkRoot); if (!string.IsNullOrEmpty(IntermediateOutputPath)) { Directory.CreateDirectory(IntermediateOutputPath); args.AddQuotedLine("--cache:" + Path.GetFullPath(IntermediateOutputPath)); } // Generate a response file var responseFile = Path.GetFullPath(ResponseFilePath); if (File.Exists(responseFile)) { File.Delete(responseFile); } try { using (var fs = File.Create(responseFile)) { using (var writer = new StreamWriter(fs)) writer.Write(args); } } catch (Exception ex) { Log.LogWarning("Failed to create response file '{0}': {1}", responseFile, ex); } // Some arguments can not safely go in the response file and are // added separately. They must go _after_ the response file // as they may override options passed in the response file var actualArgs = new CommandLineArgumentBuilder(); actualArgs.AddQuoted($"@{responseFile}"); if (!string.IsNullOrWhiteSpace(ExtraArguments)) { actualArgs.Add(ExtraArguments); } return(actualArgs.ToString()); }
protected string GenerateCommandLineCommands() { var sb = new CommandLineArgumentBuilder(); if (!string.IsNullOrEmpty(LaunchApp)) { sb.Add(SdkIsSimulator ? "--launchsim" : "--launchdev"); sb.AddQuoted(LaunchApp); } if (!string.IsNullOrEmpty(InstallApp)) { sb.Add(SdkIsSimulator ? "--installsim" : "--installdev"); sb.AddQuoted(InstallApp); } if (SdkIsSimulator && string.IsNullOrEmpty(DeviceName)) { var simruntime = $"com.apple.CoreSimulator.SimRuntime.{PlatformName}-{SdkVersion.Replace ('.', '-')}"; var simdevicetypes = GetDeviceTypes(); string simdevicetype; if (simdevicetypes?.Count > 0) { // Use the latest device type we can find. This seems to be what Xcode does by default. simdevicetype = simdevicetypes.Last(); } else { // We couldn't find any device types, so pick one. switch (Platform) { case ApplePlatform.iOS: // Don't try to launch an iPad-only app on an iPhone if (DeviceType == IPhoneDeviceType.IPad) { simdevicetype = "com.apple.CoreSimulator.SimDeviceType.iPad--7th-generation-"; } else { simdevicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-11"; } break; case ApplePlatform.TVOS: simdevicetype = "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-1080p"; break; case ApplePlatform.WatchOS: simdevicetype = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-40mm"; break; default: throw new InvalidOperationException($"Invalid platform: {Platform}"); } } DeviceName = $":v2:runtime={simruntime},devicetype={simdevicetype}"; } if (!string.IsNullOrEmpty(DeviceName)) { if (SdkIsSimulator) { sb.Add("--device"); } else { sb.Add("--devname"); } sb.AddQuoted(DeviceName); } if (CaptureOutput && string.IsNullOrEmpty(StandardOutputPath)) { StandardOutputPath = GetTerminalName(1); } if (CaptureOutput && string.IsNullOrEmpty(StandardErrorPath)) { StandardErrorPath = GetTerminalName(2); } if (!string.IsNullOrEmpty(StandardOutputPath)) { sb.Add("--stdout"); sb.AddQuoted(StandardOutputPath); } if (!string.IsNullOrEmpty(StandardErrorPath)) { sb.Add("--stderr"); sb.AddQuoted(StandardErrorPath); } if (WaitForExit) { sb.Add("--wait-for-exit"); } return(sb.ToString()); }
protected int Compile(ITaskItem[] items, string output, ITaskItem manifest) { var environment = new Dictionary <string, string> (); var args = new CommandLineArgumentBuilder(); if (!string.IsNullOrEmpty(SdkBinPath)) { environment.Add("PATH", SdkBinPath); } if (!string.IsNullOrEmpty(SdkUsrPath)) { environment.Add("XCODE_DEVELOPER_USR_PATH", SdkUsrPath); } args.Add("--errors", "--warnings", "--notices"); args.Add("--output-format", "xml1"); AppendCommandLineArguments(environment, args, items); if (Link) { args.Add("--link"); } else if (UseCompilationDirectory) { args.Add("--compilation-directory"); } else { args.Add("--compile"); } args.AddQuoted(Path.GetFullPath(output)); foreach (var item in items) { args.AddQuoted(item.GetMetadata("FullPath")); } var startInfo = GetProcessStartInfo(environment, GetFullPathToTool(), args.ToString()); var errors = new StringBuilder(); int exitCode; try { Log.LogMessage(MessageImportance.Normal, "Tool {0} execution started with arguments: {1}", startInfo.FileName, startInfo.Arguments); using (var stdout = File.CreateText(manifest.ItemSpec)) { using (var stderr = new StringWriter(errors)) { using (var process = ProcessUtils.StartProcess(startInfo, stdout, stderr)) { process.Wait(); exitCode = process.Result; } } Log.LogMessage(MessageImportance.Low, "Tool {0} execution finished (exit code = {1}).", startInfo.FileName, exitCode); } } catch (Exception ex) { Log.LogError("Error executing tool '{0}': {1}", startInfo.FileName, ex.Message); File.Delete(manifest.ItemSpec); return(-1); } if (exitCode != 0) { // Note: ibtool or actool exited with an error. Dump everything we can to help the user // diagnose the issue and then delete the manifest log file so that rebuilding tries // again (in case of ibtool's infamous spurious errors). if (errors.Length > 0) { Log.LogError(null, null, null, items[0].ItemSpec, 0, 0, 0, 0, "{0}", errors); } Log.LogError("{0} exited with code {1}", ToolName, exitCode); // Note: If the log file exists and is parseable, log those warnings/errors as well... if (File.Exists(manifest.ItemSpec)) { try { var plist = PDictionary.FromFile(manifest.ItemSpec); LogWarningsAndErrors(plist, items[0]); } catch (Exception ex) { Log.LogError("Failed to load {0} log file `{1}`: {2}", ToolName, manifest.ItemSpec, ex.Message); } File.Delete(manifest.ItemSpec); } } return(exitCode); }
protected override string GenerateCommandLineCommands() { var args = new CommandLineArgumentBuilder(); List <string> unescapedArgs = new List <string> (); TargetArchitecture architectures; bool msym; if (string.IsNullOrEmpty(Architectures) || !Enum.TryParse(Architectures, out architectures)) { architectures = TargetArchitecture.Default; } if (architectures == TargetArchitecture.ARMv6) { Log.LogError("Target architecture ARMv6 is no longer supported in Xamarin.iOS. Please select a supported architecture."); return(null); } if (!string.IsNullOrEmpty(IntermediateOutputPath)) { Directory.CreateDirectory(IntermediateOutputPath); args.AddQuotedLine($"--cache={Path.GetFullPath (IntermediateOutputPath)}"); } args.AddQuotedLine((SdkIsSimulator ? "--sim=" : "--dev=") + Path.GetFullPath(AppBundleDir)); if (AppleSdkSettings.XcodeVersion.Major >= 5 && IPhoneSdks.MonoTouch.Version.CompareTo(new IPhoneSdkVersion(6, 3, 7)) < 0) { args.AddLine("--compiler=clang"); } args.AddQuotedLine($"--executable={ExecutableName}"); if (IsAppExtension) { args.AddLine("--extension"); } if (Debug) { if (FastDev && !SdkIsSimulator) { args.AddLine("--fastdev"); } args.AddLine("--debug"); } if (Profiling) { args.AddLine("--profiling"); } if (LinkerDumpDependencies) { args.AddLine("--linkerdumpdependencies"); } if (EnableSGenConc) { args.AddLine("--sgen-conc"); } if (!string.IsNullOrEmpty(Interpreter)) { args.Add($"--interpreter={Interpreter}"); } switch (LinkMode.ToLowerInvariant()) { case "sdkonly": args.AddLine("--linksdkonly"); break; case "none": args.AddLine("--nolink"); break; } if (!string.IsNullOrEmpty(I18n)) { args.AddQuotedLine($"--i18n={I18n}"); } args.AddQuotedLine($"--sdkroot={SdkRoot}"); args.AddQuotedLine($"--sdk={SdkVersion}"); if (!minimumOSVersion.IsUseDefault) { args.AddQuotedLine($"--targetver={minimumOSVersion.ToString ()}"); } if (UseFloat32 /* We want to compile 32-bit floating point code to use 32-bit floating point operations */) { args.AddLine("--aot-options=-O=float32"); } else { args.AddLine("--aot-options=-O=-float32"); } if (!EnableGenericValueTypeSharing) { args.AddLine("--gsharedvt=false"); } if (LinkDescriptions != null) { foreach (var desc in LinkDescriptions) { args.AddQuotedLine($"--xml={desc.ItemSpec}"); } } if (EnableBitcode) { switch (Framework) { case PlatformFramework.WatchOS: args.AddLine("--bitcode=full"); break; case PlatformFramework.TVOS: args.AddLine("--bitcode=asmonly"); break; default: throw new InvalidOperationException(string.Format("Bitcode is currently not supported on {0}.", Framework)); } } if (!string.IsNullOrEmpty(HttpClientHandler)) { args.AddLine($"--http-message-handler={HttpClientHandler}"); } string thumb = UseThumb && UseLlvm ? "+thumb2" : ""; string llvm = UseLlvm ? "+llvm" : ""; string abi = ""; if (SdkIsSimulator) { if (architectures.HasFlag(TargetArchitecture.i386)) { abi += (abi.Length > 0 ? "," : "") + "i386"; } if (architectures.HasFlag(TargetArchitecture.x86_64)) { abi += (abi.Length > 0 ? "," : "") + "x86_64"; } if (string.IsNullOrEmpty(abi)) { architectures = TargetArchitecture.i386; abi = "i386"; } } else { if (architectures == TargetArchitecture.Default) { architectures = TargetArchitecture.ARMv7; } if (architectures.HasFlag(TargetArchitecture.ARMv7)) { abi += (abi.Length > 0 ? "," : "") + "armv7" + llvm + thumb; } if (architectures.HasFlag(TargetArchitecture.ARMv7s)) { abi += (abi.Length > 0 ? "," : "") + "armv7s" + llvm + thumb; } if (architectures.HasFlag(TargetArchitecture.ARM64)) { // Note: ARM64 does not have thumb. abi += (abi.Length > 0 ? "," : "") + "arm64" + llvm; } if (architectures.HasFlag(TargetArchitecture.ARMv7k)) { abi += (abi.Length > 0 ? "," : "") + "armv7k" + llvm; } if (string.IsNullOrEmpty(abi)) { abi = "armv7" + llvm + thumb; } } // Output the CompiledArchitectures CompiledArchitectures = architectures.ToString(); args.AddLine($"--abi={abi}"); // output symbols to preserve when stripping args.AddQuotedLine($"--symbollist={Path.GetFullPath (SymbolsList)}"); // don't have mtouch generate the dsyms... args.AddLine("--dsym=no"); if (!string.IsNullOrEmpty(ArchiveSymbols) && bool.TryParse(ArchiveSymbols.Trim(), out msym)) { args.AddLine($"--msym={(msym ? "yes" : "no")}"); } var gcc = new GccOptions(); if (!string.IsNullOrEmpty(ExtraArgs)) { var extraArgs = CommandLineArgumentBuilder.Parse(ExtraArgs); var target = MainAssembly.ItemSpec; string projectDir; if (ProjectDir.StartsWith("~/", StringComparison.Ordinal)) { // Note: Since the Visual Studio plugin doesn't know the user's home directory on the Mac build host, // it simply uses paths relative to "~/". Expand these paths to their full path equivalents. var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); projectDir = Path.Combine(home, ProjectDir.Substring(2)); } else { projectDir = ProjectDir; } var customTags = new Dictionary <string, string> (StringComparer.OrdinalIgnoreCase) { { "projectdir", projectDir }, // Apparently msbuild doesn't propagate the solution path, so we can't get it. // { "solutiondir", proj.ParentSolution != null ? proj.ParentSolution.BaseDirectory : proj.BaseDirectory }, { "appbundledir", AppBundleDir }, { "targetpath", Path.Combine(Path.GetDirectoryName(target), Path.GetFileName(target)) }, { "targetdir", Path.GetDirectoryName(target) }, { "targetname", Path.GetFileName(target) }, { "targetext", Path.GetExtension(target) }, }; for (int i = 0; i < extraArgs.Length; i++) { var argument = extraArgs[i]; int startIndex = 0; while (argument.Length > startIndex && argument[startIndex] == '-') { startIndex++; } int endIndex = startIndex; while (endIndex < argument.Length && argument[endIndex] != '=') { endIndex++; } int length = endIndex - startIndex; if (length == 9 && string.CompareOrdinal(argument, startIndex, "gcc_flags", 0, 9) == 0) { // user-defined -gcc_flags argument string flags = null; if (endIndex < extraArgs[i].Length) { flags = Unquote(argument, endIndex + 1); } else if (i + 1 < extraArgs.Length) { flags = extraArgs[++i]; } if (!string.IsNullOrEmpty(flags)) { var gccArgs = CommandLineArgumentBuilder.Parse(flags); for (int j = 0; j < gccArgs.Length; j++) { gcc.Arguments.Add(StringParserService.Parse(gccArgs[j], customTags)); } } } else { // other user-defined mtouch arguments unescapedArgs.Add(StringParserService.Parse(argument, customTags)); } } } BuildNativeReferenceFlags(gcc); BuildEntitlementFlags(gcc); foreach (var framework in gcc.Frameworks) { args.AddQuotedLine($"--framework={framework}"); } foreach (var framework in gcc.WeakFrameworks) { args.AddQuotedLine($"--weak-framework={framework}"); } if (gcc.Cxx) { args.AddLine("--cxx"); } if (gcc.Arguments.Length > 0) { unescapedArgs.Add($"--gcc_flags={gcc.Arguments.ToString ()}"); } foreach (var asm in References) { if (IsFrameworkItem(asm)) { args.AddQuotedLine($"-r={ResolveFrameworkFile (asm.ItemSpec)}"); } else { args.AddQuotedLine($"-r={Path.GetFullPath (asm.ItemSpec)}"); } } foreach (var ext in AppExtensionReferences) { args.AddQuotedLine($"--app-extension={Path.GetFullPath (ext.ItemSpec)}"); } args.AddLine($"--target-framework={TargetFrameworkIdentifier},{TargetFrameworkVersion}"); args.AddQuotedLine($"--root-assembly={Path.GetFullPath (MainAssembly.ItemSpec)}"); // We give the priority to the ExtraArgs to set the mtouch verbosity. if (string.IsNullOrEmpty(ExtraArgs) || (!string.IsNullOrEmpty(ExtraArgs) && !ExtraArgs.Contains("-q") && !ExtraArgs.Contains("-v"))) { args.AddLine(GetVerbosityLevel(Verbosity)); } if (!string.IsNullOrWhiteSpace(License)) { args.AddLine($"--license={License}"); } // Generate a response file var responseFile = Path.GetFullPath(ResponseFilePath); if (File.Exists(responseFile)) { File.Delete(responseFile); } try { using (var fs = File.Create(responseFile)) { using (var writer = new StreamWriter(fs)) writer.Write(args); } } catch (Exception ex) { Log.LogWarning("Failed to create response file '{0}': {1}", responseFile, ex); } // Some arguments can not safely go in the response file and are // added separately. They must go _after_ the response file // as they may override options passed in the response file var actualArgs = new CommandLineArgumentBuilder(); actualArgs.AddQuoted($"@{responseFile}"); foreach (var arg in unescapedArgs) { actualArgs.AddQuoted(arg); } return(actualArgs.ToString()); }