@@ -100,15 +100,26 @@ CompilerOptions setupCompilerOptions(
100100 int nullSafety,
101101 List <String > experimentalFlags,
102102 bool bytecode,
103- Uri packagesUri,
103+ String packageConfig,
104+ String workingDirectory,
104105 List <String > errors) {
105106 final expFlags = < String > [];
106107 if (experimentalFlags != null ) {
107108 for (String flag in experimentalFlags) {
108109 expFlags.addAll (flag.split ("," ));
109110 }
110111 }
111-
112+ Uri packagesUri = null ;
113+ if (packageConfig != null ) {
114+ packagesUri = Uri .parse (packageConfig);
115+ if (packagesUri.scheme == '' ) {
116+ // Script does not have a scheme, assume that it is a path,
117+ // resolve it against the working directory.
118+ packagesUri = Uri .directory (workingDirectory).resolveUri (packagesUri);
119+ }
120+ } else if (Platform .packageConfig != null ) {
121+ packagesUri = Uri .parse (Platform .packageConfig);
122+ }
112123 return new CompilerOptions ()
113124 ..fileSystem = fileSystem
114125 ..target = new VmTarget (new TargetFlags (
@@ -158,7 +169,7 @@ abstract class Compiler {
158169 final List <String > experimentalFlags;
159170 final bool bytecode;
160171 final String packageConfig;
161-
172+ final String workingDirectory;
162173 // Code coverage and hot reload are only supported by incremental compiler,
163174 // which is used if vm-service is enabled.
164175 final bool supportCodeCoverage;
@@ -176,21 +187,8 @@ abstract class Compiler {
176187 this .bytecode: false ,
177188 this .supportCodeCoverage: false ,
178189 this .supportHotReload: false ,
179- this .packageConfig: null }) {
180- Uri packagesUri = null ;
181- if (packageConfig != null ) {
182- packagesUri = Uri .parse (packageConfig);
183- } else if (Platform .packageConfig != null ) {
184- packagesUri = Uri .parse (Platform .packageConfig);
185- }
186-
187- if (verbose) {
188- print ("DFE: Platform.packageConfig: ${Platform .packageConfig }" );
189- print ("DFE: packagesUri: ${packagesUri }" );
190- print ("DFE: Platform.resolvedExecutable: ${Platform .resolvedExecutable }" );
191- print ("DFE: platformKernelPath: ${platformKernelPath }" );
192- }
193-
190+ this .packageConfig: null ,
191+ this .workingDirectory: null }) {
194192 options = setupCompilerOptions (
195193 fileSystem,
196194 platformKernelPath,
@@ -199,8 +197,16 @@ abstract class Compiler {
199197 nullSafety,
200198 experimentalFlags,
201199 bytecode,
202- packagesUri,
200+ packageConfig,
201+ workingDirectory,
203202 errors);
203+
204+ if (verbose) {
205+ print ("DFE: Platform.packageConfig: ${Platform .packageConfig }" );
206+ print ("DFE: packagesUri: ${options .packagesFileUri }" );
207+ print ("DFE: Platform.resolvedExecutable: ${Platform .resolvedExecutable }" );
208+ print ("DFE: platformKernelPath: ${platformKernelPath }" );
209+ }
204210 }
205211
206212 Future <CompilerResult > compile (Uri script) {
@@ -337,7 +343,8 @@ class IncrementalCompilerWrapper extends Compiler {
337343 int nullSafety: kNullSafetyOptionUnspecified,
338344 List <String > experimentalFlags: null ,
339345 bool bytecode: false ,
340- String packageConfig: null })
346+ String packageConfig: null ,
347+ String workingDirectory: null })
341348 : super (isolateId, fileSystem, platformKernelPath,
342349 suppressWarnings: suppressWarnings,
343350 enableAsserts: enableAsserts,
@@ -346,7 +353,8 @@ class IncrementalCompilerWrapper extends Compiler {
346353 bytecode: bytecode,
347354 supportHotReload: true ,
348355 supportCodeCoverage: true ,
349- packageConfig: packageConfig);
356+ packageConfig: packageConfig,
357+ workingDirectory: workingDirectory);
350358
351359 factory IncrementalCompilerWrapper .forExpressionCompilationOnly (
352360 Component component,
@@ -357,7 +365,8 @@ class IncrementalCompilerWrapper extends Compiler {
357365 bool enableAsserts: false ,
358366 List <String > experimentalFlags: null ,
359367 bool bytecode: false ,
360- String packageConfig: null }) {
368+ String packageConfig: null ,
369+ String workingDirectory: null }) {
361370 IncrementalCompilerWrapper result = IncrementalCompilerWrapper (
362371 isolateId, fileSystem, platformKernelPath,
363372 suppressWarnings: suppressWarnings,
@@ -393,7 +402,8 @@ class IncrementalCompilerWrapper extends Compiler {
393402 nullSafety: nullSafety,
394403 experimentalFlags: experimentalFlags,
395404 bytecode: bytecode,
396- packageConfig: packageConfig);
405+ packageConfig: packageConfig,
406+ workingDirectory: workingDirectory);
397407
398408 generator.resetDeltaState ();
399409 Component fullComponent = await generator.compile ();
@@ -424,14 +434,16 @@ class SingleShotCompilerWrapper extends Compiler {
424434 int nullSafety: kNullSafetyOptionUnspecified,
425435 List <String > experimentalFlags: null ,
426436 bool bytecode: false ,
427- String packageConfig: null })
437+ String packageConfig: null ,
438+ String workingDirectory: null })
428439 : super (isolateId, fileSystem, platformKernelPath,
429440 suppressWarnings: suppressWarnings,
430441 enableAsserts: enableAsserts,
431442 nullSafety: nullSafety,
432443 experimentalFlags: experimentalFlags,
433444 bytecode: bytecode,
434- packageConfig: packageConfig);
445+ packageConfig: packageConfig,
446+ workingDirectory: workingDirectory);
435447
436448 @override
437449 Future <CompilerResult > compileInternal (Uri script) async {
@@ -467,6 +479,7 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
467479 List <String > experimentalFlags: null ,
468480 bool bytecode: false ,
469481 String packageConfig: null ,
482+ String workingDirectory: null ,
470483 String multirootFilepaths,
471484 String multirootScheme}) async {
472485 IncrementalCompilerWrapper compiler = lookupIncrementalCompiler (isolateId);
@@ -480,7 +493,8 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
480493 if (sourceFiles != null &&
481494 sourceFiles.length > 0 &&
482495 sourceFiles[1 ] == null ) {
483- // Just use first compiler that should represent main isolate as a source for cloning.
496+ // Just use first compiler that should represent main isolate as a source
497+ // for cloning.
484498 var source = isolateCompilers.entries.first;
485499 compiler = await source.value.clone (isolateId);
486500 } else {
@@ -498,7 +512,8 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
498512 nullSafety: nullSafety,
499513 experimentalFlags: experimentalFlags,
500514 bytecode: bytecode,
501- packageConfig: packageConfig);
515+ packageConfig: packageConfig,
516+ workingDirectory: workingDirectory);
502517 }
503518 isolateCompilers[isolateId] = compiler;
504519 }
@@ -822,20 +837,18 @@ Future _processLoadRequest(request) async {
822837 } else if (tag == kDetectNullabilityTag) {
823838 FileSystem fileSystem = _buildFileSystem (
824839 sourceFiles, platformKernel, multirootFilepaths, multirootScheme);
825- Uri packagesUri = null ;
826- if (packageConfig != null ) {
827- packagesUri = Uri .parse (packageConfig);
828- } else if (Platform .packageConfig != null ) {
829- packagesUri = Uri .parse (Platform .packageConfig);
830- }
831- if (packagesUri != null && packagesUri.scheme == '' ) {
832- // Script does not have a scheme, assume that it is a path,
833- // resolve it against the working directory.
834- packagesUri = Uri .directory (workingDirectory).resolveUri (packagesUri);
835- }
836840 final List <String > errors = < String > [];
837- var options = setupCompilerOptions (fileSystem, platformKernelPath, false ,
838- false , nullSafety, experimentalFlags, false , packagesUri, errors);
841+ var options = setupCompilerOptions (
842+ fileSystem,
843+ platformKernelPath,
844+ false ,
845+ false ,
846+ nullSafety,
847+ experimentalFlags,
848+ false ,
849+ packageConfig,
850+ workingDirectory,
851+ errors);
839852
840853 // script should only be null for kUpdateSourcesTag.
841854 assert (script != null );
@@ -861,6 +874,7 @@ Future _processLoadRequest(request) async {
861874 experimentalFlags: experimentalFlags,
862875 bytecode: bytecode,
863876 packageConfig: packageConfig,
877+ workingDirectory: workingDirectory,
864878 multirootFilepaths: multirootFilepaths,
865879 multirootScheme: multirootScheme);
866880 } else {
@@ -874,7 +888,8 @@ Future _processLoadRequest(request) async {
874888 nullSafety: nullSafety,
875889 experimentalFlags: experimentalFlags,
876890 bytecode: bytecode,
877- packageConfig: packageConfig);
891+ packageConfig: packageConfig,
892+ workingDirectory: workingDirectory);
878893 }
879894
880895 CompilationResult result;
0 commit comments