From 0db1fe1ff20d55ccc626f7113de11667dcdb67c6 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 22 Sep 2016 15:21:20 +0200 Subject: [PATCH] [mtouch] Add support for -j X to specify concurrency. (#876) --- tools/mtouch/Application.cs | 4 ++-- tools/mtouch/Target.cs | 2 +- tools/mtouch/mtouch.cs | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/mtouch/Application.cs b/tools/mtouch/Application.cs index df5042d79f..a5f98e5dd9 100644 --- a/tools/mtouch/Application.cs +++ b/tools/mtouch/Application.cs @@ -1698,7 +1698,7 @@ namespace Xamarin.Bundler { { var next = v.Execute (); if (next != null) - Parallel.ForEach (next, new ParallelOptions () { MaxDegreeOfParallelism = Environment.ProcessorCount }, Execute); + Parallel.ForEach (next, new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, Execute); } public void ExecuteInParallel () @@ -1706,7 +1706,7 @@ namespace Xamarin.Bundler { if (Count == 0) return; - Parallel.ForEach (this, new ParallelOptions () { MaxDegreeOfParallelism = Environment.ProcessorCount }, Execute); + Parallel.ForEach (this, new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, Execute); Clear (); } diff --git a/tools/mtouch/Target.cs b/tools/mtouch/Target.cs index 6fa9f3873e..ff7f64c6a4 100644 --- a/tools/mtouch/Target.cs +++ b/tools/mtouch/Target.cs @@ -1009,7 +1009,7 @@ namespace Xamarin.Bundler if (strip) { // note: this is much slower when Parallel.ForEach is used - Parallel.ForEach (Assemblies, new ParallelOptions () { MaxDegreeOfParallelism = Environment.ProcessorCount }, (assembly) => + Parallel.ForEach (Assemblies, new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, (assembly) => { var file = assembly.FullPath; var output = Path.Combine (AppTargetDirectory, Path.GetFileName (assembly.FullPath)); diff --git a/tools/mtouch/mtouch.cs b/tools/mtouch/mtouch.cs index 325bfe7dbe..e0200c2ca6 100644 --- a/tools/mtouch/mtouch.cs +++ b/tools/mtouch/mtouch.cs @@ -150,6 +150,13 @@ namespace Xamarin.Bundler public static List classic_only_arguments = new List (); // list of deprecated arguments, which (if used) will cause errors in Unified profile) + static int Jobs; + public static int Concurrency { + get { + return Jobs == 0 ? Environment.ProcessorCount : Jobs; + } + } + // // We need to put a hard dep on Mono.Cecil.Mdb.dll so that it get's mkbundled // @@ -1075,6 +1082,7 @@ namespace Xamarin.Bundler var os = new OptionSet () { { "h|?|help", "Displays the help", v => SetAction (Action.Help) }, { "version", "Output version information and exit.", v => SetAction (Action.Version) }, + { "j|jobs=", "The level of concurrency. Default is the number of processors.", v => Jobs = int.Parse (v) }, { "d|dir=", "Output directory for the results (Used for partial builds) [Deprecated]", v => { output_dir = v; classic_only_arguments.Add ("--dir"); }, true }, { "cp=|crossprefix=", "Specifies the Mono cross compiler prefix [Deprecated]", v => { cross_prefix = v; classic_only_arguments.Add ("--crossprefix"); }, true }, { "f|force", "Forces the recompilation of code, regardless of timestamps", v=>force = true },