Skip to content

Commit 36ea114

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 resposen 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 37c5577 commit 36ea114

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

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

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,6 @@ static string GetNdkToolchainLibraryDir(string binDir)
148148
return libPath;
149149
}
150150

151-
static string GetShortPath (string path)
152-
{
153-
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
154-
return QuoteFileName (path);
155-
var shortPath = KernelEx.GetShortPathName (Path.GetDirectoryName (path));
156-
return Path.Combine (shortPath, Path.GetFileName (path));
157-
}
158-
159-
static string QuoteFileName(string fileName)
160-
{
161-
var builder = new CommandLineBuilder();
162-
builder.AppendFileNameIfNotNull(fileName);
163-
return builder.ToString();
164-
}
165-
166151
static bool ValidateAotConfiguration (TaskLoggingHelper log, AndroidTargetArch arch, bool enableLLVM)
167152
{
168153
return true;
@@ -381,9 +366,9 @@ IEnumerable<Config> GetAotConfigs ()
381366
Diagnostic.Error (5101, ex.Message);
382367
}
383368
var libs = new List<string>() {
384-
GetShortPath (Path.Combine(GetNdkToolchainLibraryDir(toolchainPath), "libgcc.a")),
385-
GetShortPath (Path.Combine(androidLibPath, "libc.so")),
386-
GetShortPath (Path.Combine(androidLibPath, "libm.so"))
369+
Files.GetShortPath (Path.Combine(GetNdkToolchainLibraryDir(toolchainPath), "libgcc.a")),
370+
Files.GetShortPath (Path.Combine(androidLibPath, "libc.so")),
371+
Files.GetShortPath (Path.Combine(androidLibPath, "libm.so"))
387372
};
388373
ldFlags = string.Join(";", libs);
389374
}
@@ -404,17 +389,17 @@ IEnumerable<Config> GetAotConfigs ()
404389
if (!string.IsNullOrEmpty (AotAdditionalArguments))
405390
aotOptions.Add (AotAdditionalArguments);
406391
if (sequencePointsMode == SequencePointsMode.Offline)
407-
aotOptions.Add ("msym-dir=" + GetShortPath (outdir));
392+
aotOptions.Add ("msym-dir=" + Files.GetShortPath (outdir));
408393
if (AotMode != AotMode.Normal)
409394
aotOptions.Add (AotMode.ToString ().ToLowerInvariant ());
410395

411-
aotOptions.Add ("outfile=" + GetShortPath (outputFile));
396+
aotOptions.Add ("outfile=" + Files.GetShortPath (outputFile));
412397
aotOptions.Add ("asmwriter");
413398
aotOptions.Add ("mtriple=" + mtriple);
414-
aotOptions.Add ("tool-prefix=" + GetShortPath (toolPrefix));
399+
aotOptions.Add ("tool-prefix=" + Files.GetShortPath (toolPrefix));
415400
aotOptions.Add ("ld-flags=" + ldFlags);
416-
aotOptions.Add ("llvm-path=" + GetShortPath (sdkBinDirectory));
417-
aotOptions.Add ("temp-path=" + GetShortPath (tempDir));
401+
aotOptions.Add ("llvm-path=" + Files.GetShortPath (sdkBinDirectory));
402+
aotOptions.Add ("temp-path=" + Files.GetShortPath (tempDir));
418403

419404
string aotOptionsStr = (EnableLLVM ? "--llvm " : "") + "--aot=" + string.Join (",", aotOptions);
420405

@@ -436,9 +421,9 @@ IEnumerable<Config> GetAotConfigs ()
436421
}
437422

438423
var assembliesPath = Path.GetFullPath (Path.GetDirectoryName (resolvedPath));
439-
var assemblyPath = QuoteFileName (Path.GetFullPath (resolvedPath));
424+
var assemblyPath = Files.QuoteFileName (Path.GetFullPath (resolvedPath));
440425

441-
yield return new Config (assembliesPath, QuoteFileName (aotCompiler), aotOptionsStr, assemblyPath, outputFile);
426+
yield return new Config (assembliesPath, Files.QuoteFileName (aotCompiler), aotOptionsStr, assemblyPath, outputFile);
442427
}
443428
}
444429
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,18 @@ public override bool Execute ()
6363
return retval;
6464
}
6565

66+
protected virtual void WriteOptionsToResponseFile (StreamWriter sw)
67+
{
68+
}
69+
6670
private void GenerateResponseFile ()
6771
{
6872
TemporarySourceListFile = Path.GetTempFileName ();
6973

7074
using (var sw = new StreamWriter (path:TemporarySourceListFile, append:false,
7175
encoding:new UTF8Encoding (encoderShouldEmitUTF8Identifier:false))) {
76+
77+
WriteOptionsToResponseFile (sw);
7278
// Include any user .java files
7379
if (JavaSourceFiles != null)
7480
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 {Files.GetShortPath (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}", Files.GetShortPath (JavaPlatformJarPath).Replace (@"\", "\\"));
73+
sw.WriteLine ($"-encoding UTF8");
74+
}
7175
}
7276
}

src/Xamarin.Android.Build.Tasks/Utilities/Files.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@ public static bool IsPortablePdb (string filename)
329329
return false;
330330
}
331331
}
332+
333+
internal static string QuoteFileName (string fileName)
334+
{
335+
var builder = new CommandLineBuilder ();
336+
builder.AppendFileNameIfNotNull (fileName);
337+
return builder.ToString ();
338+
}
339+
340+
internal static string GetShortPath (string path)
341+
{
342+
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
343+
return QuoteFileName (path);
344+
var shortPath = KernelEx.GetShortPathName (Path.GetDirectoryName (path));
345+
return Path.Combine (shortPath, Path.GetFileName (path));
346+
}
332347
}
333348
}
334349

0 commit comments

Comments
 (0)