Skip to content

Commit c79ba2b

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 98d881b commit c79ba2b

File tree

4 files changed

+43
-34
lines changed

4 files changed

+43
-34
lines changed

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

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,6 @@ static string GetNdkToolchainLibraryDir (string binDir, AndroidTargetArch arch)
167167
return GetNdkToolchainLibraryDir (binDir, NdkUtil.GetArchDirName (arch));
168168
}
169169

170-
static string GetShortPath (string path)
171-
{
172-
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
173-
return QuoteFileName (path);
174-
var shortPath = KernelEx.GetShortPathName (Path.GetDirectoryName (path));
175-
return Path.Combine (shortPath, Path.GetFileName (path));
176-
}
177-
178-
static string QuoteFileName(string fileName)
179-
{
180-
var builder = new CommandLineBuilder();
181-
builder.AppendFileNameIfNotNull(fileName);
182-
return builder.ToString();
183-
}
184-
185170
static bool ValidateAotConfiguration (TaskLoggingHelper log, AndroidTargetArch arch, bool enableLLVM)
186171
{
187172
return true;
@@ -395,20 +380,19 @@ IEnumerable<Config> GetAotConfigs ()
395380

396381
var libs = new List<string>();
397382
if (NdkUtil.UsingClangNDK) {
398-
libs.Add ($"-L{GetShortPath (toolchainLibDir)}");
399-
libs.Add ($"-L{GetShortPath (androidLibPath)}");
383+
libs.Add ($"-L{Files.GetShortPath (toolchainLibDir)}");
384+
libs.Add ($"-L{Files.GetShortPath (androidLibPath)}");
400385

401386
if (arch == AndroidTargetArch.Arm) {
402387
// Needed for -lunwind to work
403388
string compilerLibDir = Path.Combine (toolchainPath, "..", "sysroot", "usr", "lib", NdkUtil.GetArchDirName (arch));
404-
libs.Add ($"-L{GetShortPath (compilerLibDir)}");
389+
libs.Add ($"-L{Files.GetShortPath (compilerLibDir)}");
405390
}
406391
}
407392

408-
libs.Add (GetShortPath (Path.Combine (toolchainLibDir, "libgcc.a")));
409-
libs.Add (GetShortPath (Path.Combine (androidLibPath, "libc.so")));
410-
libs.Add (GetShortPath (Path.Combine (androidLibPath, "libm.so")));
411-
393+
libs.Add (Files.GetShortPath (Path.Combine (toolchainLibDir, "libgcc.a")));
394+
libs.Add (Files.GetShortPath (Path.Combine (androidLibPath, "libc.so")));
395+
libs.Add (Files.GetShortPath (Path.Combine (androidLibPath, "libm.so")));
412396
ldFlags = string.Join(";", libs);
413397
}
414398

@@ -428,17 +412,17 @@ IEnumerable<Config> GetAotConfigs ()
428412
if (!string.IsNullOrEmpty (AotAdditionalArguments))
429413
aotOptions.Add (AotAdditionalArguments);
430414
if (sequencePointsMode == SequencePointsMode.Offline)
431-
aotOptions.Add ("msym-dir=" + GetShortPath (outdir));
415+
aotOptions.Add ("msym-dir=" + Files.GetShortPath (outdir));
432416
if (AotMode != AotMode.Normal)
433417
aotOptions.Add (AotMode.ToString ().ToLowerInvariant ());
434418

435-
aotOptions.Add ("outfile=" + GetShortPath (outputFile));
419+
aotOptions.Add ("outfile=" + Files.GetShortPath (outputFile));
436420
aotOptions.Add ("asmwriter");
437421
aotOptions.Add ("mtriple=" + mtriple);
438-
aotOptions.Add ("tool-prefix=" + GetShortPath (toolPrefix));
422+
aotOptions.Add ("tool-prefix=" + Files.GetShortPath (toolPrefix));
439423
aotOptions.Add ("ld-flags=" + ldFlags);
440-
aotOptions.Add ("llvm-path=" + GetShortPath (sdkBinDirectory));
441-
aotOptions.Add ("temp-path=" + GetShortPath (tempDir));
424+
aotOptions.Add ("llvm-path=" + Files.GetShortPath (sdkBinDirectory));
425+
aotOptions.Add ("temp-path=" + Files.GetShortPath (tempDir));
442426

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

@@ -460,9 +444,9 @@ IEnumerable<Config> GetAotConfigs ()
460444
}
461445

462446
var assembliesPath = Path.GetFullPath (Path.GetDirectoryName (resolvedPath));
463-
var assemblyPath = QuoteFileName (Path.GetFullPath (resolvedPath));
447+
var assemblyPath = Files.QuoteFileName (Path.GetFullPath (resolvedPath));
464448

465-
yield return new Config (assembliesPath, QuoteFileName (aotCompiler), aotOptionsStr, assemblyPath, outputFile);
449+
yield return new Config (assembliesPath, Files.QuoteFileName (aotCompiler), aotOptionsStr, assemblyPath, outputFile);
466450
}
467451
}
468452
}

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
@@ -394,6 +394,21 @@ public static bool IsPortablePdb (string filename)
394394
return false;
395395
}
396396
}
397+
398+
internal static string QuoteFileName (string fileName)
399+
{
400+
var builder = new CommandLineBuilder ();
401+
builder.AppendFileNameIfNotNull (fileName);
402+
return builder.ToString ();
403+
}
404+
405+
internal static string GetShortPath (string path)
406+
{
407+
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
408+
return QuoteFileName (path);
409+
var shortPath = KernelEx.GetShortPathName (Path.GetDirectoryName (path));
410+
return Path.Combine (shortPath, Path.GetFileName (path));
411+
}
397412
}
398413
}
399414

0 commit comments

Comments
 (0)