55using System . IO ;
66using System . Linq ;
77using System . Reflection ;
8+ using System . Text ;
89using System . Threading ;
910using Microsoft . Build . Framework ;
1011using Microsoft . Build . Utilities ;
@@ -173,14 +174,6 @@ static string GetNdkToolchainLibraryDir (string binDir, AndroidTargetArch arch)
173174 return GetNdkToolchainLibraryDir ( binDir , NdkUtil . GetArchDirName ( arch ) ) ;
174175 }
175176
176- static string GetShortPath ( string path )
177- {
178- if ( Environment . OSVersion . Platform != PlatformID . Win32NT )
179- return QuoteFileName ( path ) ;
180- var shortPath = KernelEx . GetShortPathName ( Path . GetDirectoryName ( path ) ) ;
181- return Path . Combine ( shortPath , Path . GetFileName ( path ) ) ;
182- }
183-
184177 static string QuoteFileName ( string fileName )
185178 {
186179 var builder = new CommandLineBuilder ( ) ;
@@ -282,12 +275,15 @@ bool RunParallelAotCompiler (List<string> nativeLibs)
282275 return ;
283276 }
284277
285- if ( ! RunAotCompiler ( config . AssembliesPath , config . AotCompiler , config . AotOptions , config . AssemblyPath ) ) {
278+ if ( ! RunAotCompiler ( config . AssembliesPath , config . AotCompiler , config . AotOptions , config . AssemblyPath , config . ResponseFile ) ) {
286279 LogCodedError ( "XA3001" , "Could not AOT the assembly: {0}" , Path . GetFileName ( config . AssemblyPath ) ) ;
287280 Cancel ( ) ;
288281 return ;
289282 }
290283
284+ if ( File . Exists ( config . ResponseFile ) )
285+ File . Delete ( config . ResponseFile ) ;
286+
291287 lock ( nativeLibs )
292288 nativeLibs . Add ( config . OutputFile ) ;
293289 }
@@ -361,6 +357,11 @@ IEnumerable<Config> GetAotConfigs ()
361357 if ( ! Directory . Exists ( outdir ) )
362358 Directory . CreateDirectory ( outdir ) ;
363359
360+ // dont use a full path if the outdir is withing the WorkingDirectory.
361+ if ( outdir . StartsWith ( WorkingDirectory , StringComparison . InvariantCultureIgnoreCase ) ) {
362+ outdir = outdir . Replace ( WorkingDirectory + Path . DirectorySeparatorChar , string . Empty ) ;
363+ }
364+
364365 int level = 0 ;
365366 string toolPrefix = EnableLLVM
366367 ? NdkUtil . GetNdkToolPrefix ( AndroidNdkDirectory , arch , level = GetNdkApiLevel ( AndroidNdkDirectory , AndroidApiLevel , arch ) )
@@ -388,19 +389,19 @@ IEnumerable<Config> GetAotConfigs ()
388389
389390 var libs = new List < string > ( ) ;
390391 if ( NdkUtil . UsingClangNDK ) {
391- libs . Add ( $ "-L{ GetShortPath ( toolchainLibDir ) } ") ;
392- libs . Add ( $ "-L{ GetShortPath ( androidLibPath ) } ") ;
392+ libs . Add ( $ "-L{ toolchainLibDir } ") ;
393+ libs . Add ( $ "-L{ androidLibPath } ") ;
393394
394395 if ( arch == AndroidTargetArch . Arm ) {
395396 // Needed for -lunwind to work
396397 string compilerLibDir = Path . Combine ( toolchainPath , ".." , "sysroot" , "usr" , "lib" , NdkUtil . GetArchDirName ( arch ) ) ;
397- libs . Add ( $ "-L{ GetShortPath ( compilerLibDir ) } ") ;
398+ libs . Add ( $ "-L{ compilerLibDir } ") ;
398399 }
399400 }
400401
401- libs . Add ( GetShortPath ( Path . Combine ( toolchainLibDir , "libgcc.a" ) ) ) ;
402- libs . Add ( GetShortPath ( Path . Combine ( androidLibPath , "libc.so" ) ) ) ;
403- libs . Add ( GetShortPath ( Path . Combine ( androidLibPath , "libm.so" ) ) ) ;
402+ libs . Add ( Path . Combine ( toolchainLibDir , "libgcc.a" ) ) ;
403+ libs . Add ( Path . Combine ( androidLibPath , "libc.so" ) ) ;
404+ libs . Add ( Path . Combine ( androidLibPath , "libm.so" ) ) ;
404405
405406 ldFlags = string . Join ( ";" , libs ) ;
406407 }
@@ -422,25 +423,28 @@ IEnumerable<Config> GetAotConfigs ()
422423 aotOptions . Add ( "profile-only" ) ;
423424 foreach ( var p in Profiles ) {
424425 var fp = Path . GetFullPath ( p . ItemSpec ) ;
425- aotOptions . Add ( $ "profile={ GetShortPath ( fp ) } ") ;
426+ aotOptions . Add ( $ "profile={ fp } ") ;
426427 }
427428 }
428429 if ( ! string . IsNullOrEmpty ( AotAdditionalArguments ) )
429430 aotOptions . Add ( AotAdditionalArguments ) ;
430431 if ( sequencePointsMode == SequencePointsMode . Offline )
431- aotOptions . Add ( "msym-dir=" + GetShortPath ( outdir ) ) ;
432+ aotOptions . Add ( $ "msym-dir={ outdir } " ) ;
432433 if ( AotMode != AotMode . Normal )
433434 aotOptions . Add ( AotMode . ToString ( ) . ToLowerInvariant ( ) ) ;
434435
435- aotOptions . Add ( "outfile=" + GetShortPath ( outputFile ) ) ;
436+ aotOptions . Add ( $ "outfile={ outputFile } " ) ;
436437 aotOptions . Add ( "asmwriter" ) ;
437- aotOptions . Add ( "mtriple=" + mtriple ) ;
438- aotOptions . Add ( "tool-prefix=" + GetShortPath ( toolPrefix ) ) ;
439- aotOptions . Add ( "ld-flags=" + ldFlags ) ;
440- aotOptions . Add ( "llvm-path=" + GetShortPath ( sdkBinDirectory ) ) ;
441- aotOptions . Add ( "temp-path=" + GetShortPath ( tempDir ) ) ;
438+ aotOptions . Add ( $ "mtriple={ mtriple } " ) ;
439+ aotOptions . Add ( $ "tool-prefix={ toolPrefix } " ) ;
440+ aotOptions . Add ( $ "ld-flags={ ldFlags } " ) ;
441+ aotOptions . Add ( $ "llvm-path={ sdkBinDirectory } " ) ;
442+ aotOptions . Add ( $ "temp-path={ tempDir } " ) ;
442443
443- string aotOptionsStr = ( EnableLLVM ? "--llvm " : "" ) + "--aot=" + string . Join ( "," , aotOptions ) ;
444+ // we need to quote the entire --aot arguments here to make sure it is parsed
445+ // on windows as one argument. Otherwise it will be split up into multiple
446+ // values, which wont work.
447+ string aotOptionsStr = ( EnableLLVM ? "--llvm " : "" ) + $ "\" --aot={ string . Join ( "," , aotOptions ) } \" ";
444448
445449 if ( ! string . IsNullOrEmpty ( ExtraAotOptions ) ) {
446450 aotOptionsStr += ( aotOptions . Count > 0 ? "," : "" ) + ExtraAotOptions ;
@@ -460,23 +464,29 @@ IEnumerable<Config> GetAotConfigs ()
460464 }
461465
462466 var assembliesPath = Path . GetFullPath ( Path . GetDirectoryName ( resolvedPath ) ) ;
463- var assemblyPath = QuoteFileName ( Path . GetFullPath ( resolvedPath ) ) ;
467+ var assemblyPath = Path . GetFullPath ( resolvedPath ) ;
464468
465- yield return new Config ( assembliesPath , QuoteFileName ( aotCompiler ) , aotOptionsStr , assemblyPath , outputFile ) ;
469+ yield return new Config ( assembliesPath , aotCompiler , aotOptionsStr , assemblyPath , outputFile , Path . Combine ( tempDir , "response.txt" ) ) ;
466470 }
467471 }
468472 }
469473
470- bool RunAotCompiler ( string assembliesPath , string aotCompiler , string aotOptions , string assembly )
474+ bool RunAotCompiler ( string assembliesPath , string aotCompiler , string aotOptions , string assembly , string responseFile )
471475 {
472476 var stdout_completed = new ManualResetEvent ( false ) ;
473477 var stderr_completed = new ManualResetEvent ( false ) ;
478+
479+ using ( var sw = new StreamWriter ( responseFile , append : false , encoding : new UTF8Encoding ( encoderShouldEmitUTF8Identifier : false ) ) ) {
480+ sw . WriteLine ( aotOptions + " " + QuoteFileName ( assembly ) ) ;
481+ }
482+
474483 var psi = new ProcessStartInfo ( ) {
475- FileName = aotCompiler ,
476- Arguments = aotOptions + " " + assembly ,
484+ FileName = QuoteFileName ( aotCompiler ) ,
485+ Arguments = $ "--response= { QuoteFileName ( responseFile ) } " ,
477486 UseShellExecute = false ,
478487 RedirectStandardOutput = true ,
479488 RedirectStandardError = true ,
489+ StandardOutputEncoding = Encoding . UTF8 ,
480490 CreateNoWindow = true ,
481491 WindowStyle = ProcessWindowStyle . Hidden ,
482492 WorkingDirectory = WorkingDirectory ,
@@ -536,16 +546,18 @@ struct Config {
536546 public string AotOptions { get ; }
537547 public string AssemblyPath { get ; }
538548 public string OutputFile { get ; }
549+ public string ResponseFile { get ; }
539550
540551 public bool Valid { get ; private set ; }
541552
542- public Config ( string assembliesPath , string aotCompiler , string aotOptions , string assemblyPath , string outputFile )
553+ public Config ( string assembliesPath , string aotCompiler , string aotOptions , string assemblyPath , string outputFile , string responseFile )
543554 {
544555 AssembliesPath = assembliesPath ;
545556 AotCompiler = aotCompiler ;
546557 AotOptions = aotOptions ;
547558 AssemblyPath = assemblyPath ;
548559 OutputFile = outputFile ;
560+ ResponseFile = responseFile ;
549561 Valid = true ;
550562 }
551563
0 commit comments