-
-
Save spouliot/d50fb9ca251ffcb90f645c39d699126e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Text; | |
using System.Threading.Tasks; | |
class Program { | |
static int verbose; | |
public static int RunCommand (string path, string args, string[] env = null, StringBuilder output = null, bool suppressPrintOnErrors = false) | |
{ | |
Exception stdin_exc = null; | |
var info = new ProcessStartInfo (path, args); | |
info.UseShellExecute = false; | |
info.RedirectStandardInput = false; | |
info.RedirectStandardOutput = true; | |
info.RedirectStandardError = true; | |
System.Threading.ManualResetEvent stdout_completed = new System.Threading.ManualResetEvent (false); | |
System.Threading.ManualResetEvent stderr_completed = new System.Threading.ManualResetEvent (false); | |
if (output == null) | |
output = new StringBuilder (); | |
if (env != null){ | |
if (env.Length % 2 != 0) | |
throw new Exception ("You passed an environment key without a value"); | |
for (int i = 0; i < env.Length; i+= 2) | |
info.EnvironmentVariables [env[i]] = env[i+1]; | |
} | |
if (verbose > 0) | |
Console.WriteLine ("{0} {1}", path, args); | |
using (var p = Process.Start (info)) { | |
p.OutputDataReceived += (s, e) => { | |
if (e.Data != null) { | |
lock (output) | |
output.AppendLine (e.Data); | |
} else { | |
stdout_completed.Set (); | |
} | |
}; | |
p.ErrorDataReceived += (s, e) => { | |
if (e.Data != null) { | |
lock (output) | |
output.AppendLine (e.Data); | |
} else { | |
stderr_completed.Set (); | |
} | |
}; | |
p.BeginOutputReadLine (); | |
p.BeginErrorReadLine (); | |
p.WaitForExit (); | |
stderr_completed.WaitOne (TimeSpan.FromSeconds (1)); | |
stdout_completed.WaitOne (TimeSpan.FromSeconds (1)); | |
GC.Collect (); // Workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=43462#c14 | |
if (p.ExitCode != 0) { | |
// note: this repeat the failing command line. However we can't avoid this since we're often | |
// running commands in parallel (so the last one printed might not be the one failing) | |
if (!suppressPrintOnErrors) | |
Console.Error.WriteLine ("Process exited with code {0}, command:\n{1} {2}{3}", p.ExitCode, path, args, output.Length > 0 ? "\n" + output.ToString () : string.Empty); | |
return p.ExitCode; | |
} else if (verbose > 0 && output.Length > 0 && !suppressPrintOnErrors) { | |
Console.WriteLine (output.ToString ()); | |
} | |
if (stdin_exc != null) | |
throw stdin_exc; | |
} | |
return 0; | |
} | |
static string[] env = { | |
"CODESIGN_ALLOCATE", "/Applications/Xcode82.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate" | |
}; | |
static void Execute (string name) | |
{ | |
RunCommand ("/usr/bin/codesign", "-v --force --sign 34C20A3725B070F5B529F6C5EA01324C873285CE " + name, env); | |
} | |
static List<string> list = new List<string> () { | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libEmbeddedResources.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libFSharp.Core.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libMono.Dynamic.Interpreter.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libMonoTouch.Dialog-1.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libMonoTouch.NUnitLite.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libSystem.Core.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libSystem.Json.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libSystem.Net.Http.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libSystem.Xml.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libSystem.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libXamarin.iOS.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libbindings-test.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libfsharplibrary.dll.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libmonotouchtest.exe.dylib", | |
"/Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app/libmscorlib.dll.dylib", | |
"--entitlements /Users/poupou/git/master/xamarin-macios/tests/monotouch-test/obj/iPhone/Debug-unified/Entitlements.xcent /Users/poupou/git/master/xamarin-macios/tests/monotouch-test/bin/iPhone/Debug-unified/monotouchtest.app", | |
}; | |
static void Main (string [] args) | |
{ | |
Parallel.ForEach (list, new ParallelOptions () { MaxDegreeOfParallelism = Int32.Parse (args [0]) }, (v) => { | |
Execute (v); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment