Skip to content

Commit 5816da8

Browse files
authored
[tool] consistently use environment (not globals) in targets/web.dart (#125937)
Also update the order of args to commands so that testing has less repeated "stuff"
1 parent 8449623 commit 5816da8

File tree

2 files changed

+95
-159
lines changed
  • packages/flutter_tools

2 files changed

+95
-159
lines changed

packages/flutter_tools/lib/src/build_system/targets/web.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ class Dart2JSTarget extends Dart2WebTarget {
163163
}
164164
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
165165
final JsCompilerConfig compilerConfig = JsCompilerConfig.fromBuildSystemEnvironment(environment.defines);
166-
final Artifacts artifacts = globals.artifacts!;
166+
final Artifacts artifacts = environment.artifacts;
167167
final String platformBinariesPath = getWebPlatformBinariesDirectory(artifacts, webRenderer).path;
168168
final List<String> sharedCommandOptions = <String>[
169169
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
170170
'--disable-dart-dev',
171171
artifacts.getArtifactPath(Artifact.dart2jsSnapshot, platform: TargetPlatform.web_javascript),
172172
'--platform-binaries=$platformBinariesPath',
173-
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
174173
'--invoker=flutter_tool',
174+
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
175175
if (buildMode == BuildMode.profile)
176176
'-Ddart.vm.profile=true'
177177
else
@@ -214,7 +214,7 @@ class Dart2JSTarget extends Dart2WebTarget {
214214
final File dart2jsDeps = environment.buildDir
215215
.childFile('app.dill.deps');
216216
if (!dart2jsDeps.existsSync()) {
217-
globals.printWarning('Warning: dart2js did not produced expected deps list at '
217+
environment.logger.printWarning('Warning: dart2js did not produced expected deps list at '
218218
'${dart2jsDeps.path}');
219219
return;
220220
}
@@ -241,7 +241,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
241241
}
242242
final WasmCompilerConfig compilerConfig = WasmCompilerConfig.fromBuildSystemEnvironment(environment.defines);
243243
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
244-
final Artifacts artifacts = globals.artifacts!;
244+
final Artifacts artifacts = environment.artifacts;
245245
final File outputWasmFile = environment.buildDir.childFile(
246246
compilerConfig.runWasmOpt ? 'main.dart.unopt.wasm' : 'main.dart.wasm'
247247
);
@@ -253,14 +253,6 @@ class Dart2WasmTarget extends Dart2WebTarget {
253253
artifacts.getArtifactPath(Artifact.engineDartAotRuntime, platform: TargetPlatform.web_javascript),
254254
'--disable-dart-dev',
255255
artifacts.getArtifactPath(Artifact.dart2wasmSnapshot, platform: TargetPlatform.web_javascript),
256-
if (buildMode == BuildMode.profile)
257-
'-Ddart.vm.profile=true'
258-
else
259-
'-Ddart.vm.product=true',
260-
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
261-
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
262-
'-D$dartDefine',
263-
...compilerConfig.toCommandOptions(),
264256
'--packages=.dart_tool/package_config.json',
265257
'--dart-sdk=$dartSdkPath',
266258
'--multi-root-scheme',
@@ -271,6 +263,14 @@ class Dart2WasmTarget extends Dart2WebTarget {
271263
dartSdkRoot,
272264
'--libraries-spec',
273265
artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson).path,
266+
if (buildMode == BuildMode.profile)
267+
'-Ddart.vm.profile=true'
268+
else
269+
'-Ddart.vm.product=true',
270+
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
271+
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
272+
'-D$dartDefine',
273+
...compilerConfig.toCommandOptions(),
274274
if (webRenderer == WebRendererMode.skwasm)
275275
...<String>[
276276
'--import-shared-memory',
@@ -383,10 +383,10 @@ class WebReleaseBundle extends Target {
383383
@override
384384
Future<void> build(Environment environment) async {
385385
for (final File outputFile in environment.buildDir.listSync(recursive: true).whereType<File>()) {
386-
final String basename = globals.fs.path.basename(outputFile.path);
386+
final String basename = environment.fileSystem.path.basename(outputFile.path);
387387
if (shouldCopy(basename)) {
388388
outputFile.copySync(
389-
environment.outputDir.childFile(globals.fs.path.basename(outputFile.path)).path
389+
environment.outputDir.childFile(environment.fileSystem.path.basename(outputFile.path)).path
390390
);
391391
}
392392
}
@@ -422,9 +422,9 @@ class WebReleaseBundle extends Target {
422422
// Copy other resource files out of web/ directory.
423423
final List<File> outputResourcesFiles = <File>[];
424424
for (final File inputFile in inputResourceFiles) {
425-
final File outputFile = globals.fs.file(globals.fs.path.join(
425+
final File outputFile = environment.fileSystem.file(environment.fileSystem.path.join(
426426
environment.outputDir.path,
427-
globals.fs.path.relative(inputFile.path, from: webResources.path)));
427+
environment.fileSystem.path.relative(inputFile.path, from: webResources.path)));
428428
if (!outputFile.parent.existsSync()) {
429429
outputFile.parent.createSync(recursive: true);
430430
}
@@ -535,7 +535,7 @@ class WebBuiltInAssets extends Target {
535535
// Write the flutter.js file
536536
final File flutterJsFile = environment.outputDir.childFile('flutter.js');
537537
final String fileGeneratorsPath =
538-
globals.artifacts!.getArtifactPath(Artifact.flutterToolsFileGenerators);
538+
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
539539
flutterJsFile.writeAsStringSync(
540540
flutter_js.generateFlutterJsFile(fileGeneratorsPath));
541541
}
@@ -576,7 +576,7 @@ class WebServiceWorker extends Target {
576576
.listSync(recursive: true)
577577
.whereType<File>()
578578
.where((File file) => !file.path.endsWith('flutter_service_worker.js')
579-
&& !globals.fs.path.basename(file.path).startsWith('.'))
579+
&& !environment.fileSystem.path.basename(file.path).startsWith('.'))
580580
.toList();
581581

582582
final Map<String, String> urlToHash = <String, String>{};
@@ -586,15 +586,15 @@ class WebServiceWorker extends Target {
586586
file.path.endsWith('.part.js.map')) {
587587
continue;
588588
}
589-
final String url = globals.fs.path.toUri(
590-
globals.fs.path.relative(
589+
final String url = environment.fileSystem.path.toUri(
590+
environment.fileSystem.path.relative(
591591
file.path,
592592
from: environment.outputDir.path),
593593
).toString();
594594
final String hash = md5.convert(await file.readAsBytes()).toString();
595595
urlToHash[url] = hash;
596596
// Add an additional entry for the base URL.
597-
if (globals.fs.path.basename(url) == 'index.html') {
597+
if (environment.fileSystem.path.basename(url) == 'index.html') {
598598
urlToHash['/'] = hash;
599599
}
600600
}
@@ -605,7 +605,7 @@ class WebServiceWorker extends Target {
605605
final ServiceWorkerStrategy serviceWorkerStrategy =
606606
ServiceWorkerStrategy.fromCliName(environment.defines[kServiceWorkerStrategy]);
607607
final String fileGeneratorsPath =
608-
globals.artifacts!.getArtifactPath(Artifact.flutterToolsFileGenerators);
608+
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
609609
final String serviceWorker = generateServiceWorker(
610610
fileGeneratorsPath,
611611
urlToHash,

0 commit comments

Comments
 (0)