From 09fc472af7696f57cb8ea35e4242a7d21bc20ff3 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 22 May 2018 14:05:24 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Use a Response file for javac Context https://devdiv.visualstudio.com/DevDiv/_workitems/edit/599161 We currently only use a response file for .java files. Looking at the docs there is no reason why we can't use them for all of the arguments. This should help with problems where windows has a max command line length. --- .../Tasks/JavaCompileToolTask.cs | 6 ++++++ src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs index f7d51de8523..d405039832e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs @@ -52,12 +52,18 @@ public override bool Execute () return retval; } + protected virtual void WriteOptionsToResponseFile (StreamWriter sw) + { + } + private void GenerateResponseFile () { TemporarySourceListFile = Path.GetTempFileName (); using (var sw = new StreamWriter (path:TemporarySourceListFile, append:false, encoding:new UTF8Encoding (encoderShouldEmitUTF8Identifier:false))) { + + WriteOptionsToResponseFile (sw); // Include any user .java files if (JavaSourceFiles != null) foreach (var file in JavaSourceFiles.Where (p => Path.GetExtension (p.ItemSpec) == ".java")) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs index ae626b863bf..c14a9589978 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs @@ -8,6 +8,7 @@ using System.Text; using System.Collections.Generic; using Xamarin.Tools.Zip; +using Xamarin.Android.Tools; namespace Xamarin.Android.Tasks { @@ -57,16 +58,19 @@ protected override string GenerateCommandLineCommands () cmd.AppendSwitchIfNotNull ("-J-Dfile.encoding=", "UTF8"); - cmd.AppendSwitchIfNotNull ("-d ", ClassesOutputDirectory); - - cmd.AppendSwitchIfNotNull ("-classpath ", Jars == null || !Jars.Any () ? null : string.Join (Path.PathSeparator.ToString (), Jars.Select (i => i.ItemSpec))); - cmd.AppendSwitchIfNotNull ("-bootclasspath ", JavaPlatformJarPath); - cmd.AppendSwitchIfNotNull ("-encoding ", "UTF-8"); cmd.AppendFileNameIfNotNull (string.Format ("@{0}", TemporarySourceListFile)); cmd.AppendSwitchIfNotNull ("-target ", JavacTargetVersion); cmd.AppendSwitchIfNotNull ("-source ", JavacSourceVersion); return cmd.ToString (); } + + protected override void WriteOptionsToResponseFile (StreamWriter sw) + { + sw.WriteLine ($"-d \"{ClassesOutputDirectory.Replace (@"\", @"\\")}\""); + sw.WriteLine ("-classpath \"{0}\"", Jars == null || !Jars.Any () ? null : string.Join (Path.PathSeparator.ToString (), Jars.Select (i => i.ItemSpec.Replace (@"\", @"\\")))); + sw.WriteLine ("-bootclasspath \"{0}\"", JavaPlatformJarPath.Replace (@"\", @"\\")); + sw.WriteLine ($"-encoding UTF8"); + } } }