Skip to content

Commit

Permalink
[tool] consistently use environment (not globals) in targets/web.dart (
Browse files Browse the repository at this point in the history
…#125937)

Also update the order of args to commands so that testing has less repeated "stuff"
  • Loading branch information
kevmoo committed May 4, 2023
1 parent 8449623 commit 5816da8
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 159 deletions.
44 changes: 22 additions & 22 deletions packages/flutter_tools/lib/src/build_system/targets/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ class Dart2JSTarget extends Dart2WebTarget {
}
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
final JsCompilerConfig compilerConfig = JsCompilerConfig.fromBuildSystemEnvironment(environment.defines);
final Artifacts artifacts = globals.artifacts!;
final Artifacts artifacts = environment.artifacts;
final String platformBinariesPath = getWebPlatformBinariesDirectory(artifacts, webRenderer).path;
final List<String> sharedCommandOptions = <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.dart2jsSnapshot, platform: TargetPlatform.web_javascript),
'--platform-binaries=$platformBinariesPath',
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
'--invoker=flutter_tool',
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
if (buildMode == BuildMode.profile)
'-Ddart.vm.profile=true'
else
Expand Down Expand Up @@ -214,7 +214,7 @@ class Dart2JSTarget extends Dart2WebTarget {
final File dart2jsDeps = environment.buildDir
.childFile('app.dill.deps');
if (!dart2jsDeps.existsSync()) {
globals.printWarning('Warning: dart2js did not produced expected deps list at '
environment.logger.printWarning('Warning: dart2js did not produced expected deps list at '
'${dart2jsDeps.path}');
return;
}
Expand All @@ -241,7 +241,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
}
final WasmCompilerConfig compilerConfig = WasmCompilerConfig.fromBuildSystemEnvironment(environment.defines);
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
final Artifacts artifacts = globals.artifacts!;
final Artifacts artifacts = environment.artifacts;
final File outputWasmFile = environment.buildDir.childFile(
compilerConfig.runWasmOpt ? 'main.dart.unopt.wasm' : 'main.dart.wasm'
);
Expand All @@ -253,14 +253,6 @@ class Dart2WasmTarget extends Dart2WebTarget {
artifacts.getArtifactPath(Artifact.engineDartAotRuntime, platform: TargetPlatform.web_javascript),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.dart2wasmSnapshot, platform: TargetPlatform.web_javascript),
if (buildMode == BuildMode.profile)
'-Ddart.vm.profile=true'
else
'-Ddart.vm.product=true',
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
'-D$dartDefine',
...compilerConfig.toCommandOptions(),
'--packages=.dart_tool/package_config.json',
'--dart-sdk=$dartSdkPath',
'--multi-root-scheme',
Expand All @@ -271,6 +263,14 @@ class Dart2WasmTarget extends Dart2WebTarget {
dartSdkRoot,
'--libraries-spec',
artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson).path,
if (buildMode == BuildMode.profile)
'-Ddart.vm.profile=true'
else
'-Ddart.vm.product=true',
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
'-D$dartDefine',
...compilerConfig.toCommandOptions(),
if (webRenderer == WebRendererMode.skwasm)
...<String>[
'--import-shared-memory',
Expand Down Expand Up @@ -383,10 +383,10 @@ class WebReleaseBundle extends Target {
@override
Future<void> build(Environment environment) async {
for (final File outputFile in environment.buildDir.listSync(recursive: true).whereType<File>()) {
final String basename = globals.fs.path.basename(outputFile.path);
final String basename = environment.fileSystem.path.basename(outputFile.path);
if (shouldCopy(basename)) {
outputFile.copySync(
environment.outputDir.childFile(globals.fs.path.basename(outputFile.path)).path
environment.outputDir.childFile(environment.fileSystem.path.basename(outputFile.path)).path
);
}
}
Expand Down Expand Up @@ -422,9 +422,9 @@ class WebReleaseBundle extends Target {
// Copy other resource files out of web/ directory.
final List<File> outputResourcesFiles = <File>[];
for (final File inputFile in inputResourceFiles) {
final File outputFile = globals.fs.file(globals.fs.path.join(
final File outputFile = environment.fileSystem.file(environment.fileSystem.path.join(
environment.outputDir.path,
globals.fs.path.relative(inputFile.path, from: webResources.path)));
environment.fileSystem.path.relative(inputFile.path, from: webResources.path)));
if (!outputFile.parent.existsSync()) {
outputFile.parent.createSync(recursive: true);
}
Expand Down Expand Up @@ -535,7 +535,7 @@ class WebBuiltInAssets extends Target {
// Write the flutter.js file
final File flutterJsFile = environment.outputDir.childFile('flutter.js');
final String fileGeneratorsPath =
globals.artifacts!.getArtifactPath(Artifact.flutterToolsFileGenerators);
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
flutterJsFile.writeAsStringSync(
flutter_js.generateFlutterJsFile(fileGeneratorsPath));
}
Expand Down Expand Up @@ -576,7 +576,7 @@ class WebServiceWorker extends Target {
.listSync(recursive: true)
.whereType<File>()
.where((File file) => !file.path.endsWith('flutter_service_worker.js')
&& !globals.fs.path.basename(file.path).startsWith('.'))
&& !environment.fileSystem.path.basename(file.path).startsWith('.'))
.toList();

final Map<String, String> urlToHash = <String, String>{};
Expand All @@ -586,15 +586,15 @@ class WebServiceWorker extends Target {
file.path.endsWith('.part.js.map')) {
continue;
}
final String url = globals.fs.path.toUri(
globals.fs.path.relative(
final String url = environment.fileSystem.path.toUri(
environment.fileSystem.path.relative(
file.path,
from: environment.outputDir.path),
).toString();
final String hash = md5.convert(await file.readAsBytes()).toString();
urlToHash[url] = hash;
// Add an additional entry for the base URL.
if (globals.fs.path.basename(url) == 'index.html') {
if (environment.fileSystem.path.basename(url) == 'index.html') {
urlToHash['/'] = hash;
}
}
Expand All @@ -605,7 +605,7 @@ class WebServiceWorker extends Target {
final ServiceWorkerStrategy serviceWorkerStrategy =
ServiceWorkerStrategy.fromCliName(environment.defines[kServiceWorkerStrategy]);
final String fileGeneratorsPath =
globals.artifacts!.getArtifactPath(Artifact.flutterToolsFileGenerators);
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
final String serviceWorker = generateServiceWorker(
fileGeneratorsPath,
urlToHash,
Expand Down

0 comments on commit 5816da8

Please sign in to comment.