Skip to content

Commit fe2543a

Browse files
committed
[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.
1 parent f72c91f commit fe2543a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ public override bool Execute ()
5252
return retval;
5353
}
5454

55+
protected virtual void WriteOptionsToResponseFile (StreamWriter sw)
56+
{
57+
}
58+
5559
private void GenerateResponseFile ()
5660
{
5761
TemporarySourceListFile = Path.GetTempFileName ();
5862

5963
using (var sw = new StreamWriter (path:TemporarySourceListFile, append:false,
6064
encoding:new UTF8Encoding (encoderShouldEmitUTF8Identifier:false))) {
65+
66+
WriteOptionsToResponseFile (sw);
6167
// Include any user .java files
6268
if (JavaSourceFiles != null)
6369
foreach (var file in JavaSourceFiles.Where (p => Path.GetExtension (p.ItemSpec) == ".java"))

src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text;
99
using System.Collections.Generic;
1010
using Xamarin.Tools.Zip;
11+
using Xamarin.Android.Tools;
1112

1213
namespace Xamarin.Android.Tasks
1314
{
@@ -57,16 +58,19 @@ protected override string GenerateCommandLineCommands ()
5758

5859
cmd.AppendSwitchIfNotNull ("-J-Dfile.encoding=", "UTF8");
5960

60-
cmd.AppendSwitchIfNotNull ("-d ", ClassesOutputDirectory);
61-
62-
cmd.AppendSwitchIfNotNull ("-classpath ", Jars == null || !Jars.Any () ? null : string.Join (Path.PathSeparator.ToString (), Jars.Select (i => i.ItemSpec)));
63-
cmd.AppendSwitchIfNotNull ("-bootclasspath ", JavaPlatformJarPath);
64-
cmd.AppendSwitchIfNotNull ("-encoding ", "UTF-8");
6561
cmd.AppendFileNameIfNotNull (string.Format ("@{0}", TemporarySourceListFile));
6662
cmd.AppendSwitchIfNotNull ("-target ", JavacTargetVersion);
6763
cmd.AppendSwitchIfNotNull ("-source ", JavacSourceVersion);
6864

6965
return cmd.ToString ();
7066
}
67+
68+
protected override void WriteOptionsToResponseFile (StreamWriter sw)
69+
{
70+
sw.WriteLine ($"-d \"{ClassesOutputDirectory.Replace (@"\", @"\\")}");
71+
sw.WriteLine ("-classpath \"{0}\"", Jars == null || !Jars.Any () ? null : string.Join (Path.PathSeparator.ToString (), Jars.Select (i => i.ItemSpec.Replace (@"\", @"\\"))));
72+
sw.WriteLine ("-bootclasspath \"{0}\"", JavaPlatformJarPath.Replace (@"\", @"\\"));
73+
sw.WriteLine ($"-encoding UTF8");
74+
}
7175
}
7276
}

0 commit comments

Comments
 (0)