Example #1
0
        void Codesign(ITaskItem item)
        {
            var startInfo = GetProcessStartInfo(GetFullPathToTool(), GenerateCommandLineArguments(item));
            var messages  = new StringBuilder();
            var errors    = new StringBuilder();
            int exitCode;

            try {
                Log.LogMessage(MessageImportance.Normal, MSBStrings.M0001, startInfo.FileName, startInfo.Arguments);

                using (var stdout = new StringWriter(messages)) {
                    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(MSBStrings.E0003, startInfo.FileName, ex.Message);
                return;
            }

            if (messages.Length > 0)
            {
                Log.LogMessage(MessageImportance.Normal, "{0}", messages.ToString());
            }

            if (exitCode != 0)
            {
                if (errors.Length > 0)
                {
                    Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "{0}", errors);
                }
                else
                {
                    Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0098, startInfo.FileName);
                }
            }
        }
Example #2
0
        void Codesign(ITaskItem item)
        {
            var startInfo = GetProcessStartInfo(GetFullPathToTool(), GenerateCommandLineArguments(item));
            var messages  = new StringBuilder();
            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 = new StringWriter(messages)) {
                    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);
                return;
            }

            if (messages.Length > 0)
            {
                Log.LogMessage(MessageImportance.Normal, "{0}", messages.ToString());
            }

            if (exitCode != 0)
            {
                if (errors.Length > 0)
                {
                    Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "{0}", errors);
                }
                else
                {
                    Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "{0} failed.", startInfo.FileName);
                }
            }
        }
Example #3
0
        protected int Compile(ITaskItem[] items, ITaskItem output, ITaskItem manifest)
        {
            var environment = new Dictionary <string, string> ();
            var args        = new ProcessArgumentBuilder();

            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(output.GetMetadata("FullPath"));

            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)) {
                        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)
            {
                if (errors.Length > 0)
                {
                    Log.LogError(null, null, null, items[0].ItemSpec, 0, 0, 0, 0, "{0}", errors);
                }

                if (File.Exists(manifest.ItemSpec))
                {
                    try {
                        var plist = PDictionary.FromFile(manifest.ItemSpec);

                        LogWarningsAndErrors(plist, items[0]);
                    } catch (FormatException) {
                        Log.LogError("{0} exited with code {1}", ToolName, exitCode);
                    }

                    File.Delete(manifest.ItemSpec);
                }
            }

            return(exitCode);
        }
Example #4
0
        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);
        }