Skip to content

Commit

Permalink
Use file:/// style uris when passing platform to the compiler. (#116553)
Browse files Browse the repository at this point in the history
* Use file:/// style uris when passing platform to the compiler.

* License header.

* Use BufferLogger.

* Don't unadvertently convert strings to regexes for matching purposes.

* Fix formatting.

* More formatting.
  • Loading branch information
eyebrowsoffire authored Dec 6, 2022
1 parent 174d3be commit 5201856
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/test/web_test_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class WebTestCompiler {
initializeFromDill: cachedKernelPath,
targetModel: TargetModel.dartdevc,
extraFrontEndOptions: extraFrontEndOptions,
platformDill: platformDillPath,
platformDill: _fileSystem.file(platformDillPath).absolute.uri.toString(),
dartDefines: buildInfo.dartDefines,
librariesSpec: _artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson).uri.toString(),
packagesPath: buildInfo.packagesPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/test/web_test_compiler.dart';
import 'package:test/expect.dart';

import '../../src/context.dart';

void main() {
testUsingContext('web test compiler issues valid compile command', () async {
final BufferLogger logger = BufferLogger.test();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
fileSystem.file('project/test/fake_test.dart').createSync(recursive: true);
fileSystem.file('build/out').createSync(recursive: true);
fileSystem.file('build/build/out.sources').createSync(recursive: true);
fileSystem.file('build/build/out.json')
..createSync()
..writeAsStringSync('{}');
fileSystem.file('build/build/out.map').createSync();
fileSystem.file('build/build/out.metadata').createSync();
final FakePlatform platform = FakePlatform(
environment: <String, String>{},
);
final Config config = Config(
Config.kFlutterSettings,
fileSystem: fileSystem,
logger: logger,
platform: platform,
);
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: <Pattern>[
'Artifact.engineDartBinary.TargetPlatform.web_javascript',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk.TargetPlatform.web_javascript',
'--sdk-root',
'HostArtifact.flutterWebSdk/',
'--incremental',
'--target=dartdevc',
'--experimental-emit-debug-metadata',
'--output-dill',
'build/out',
'--packages',
'.dart_tool/package_config.json',
'-Ddart.vm.profile=false',
'-Ddart.vm.product=false',
'--enable-asserts',
'--filesystem-root',
'project/test',
'--filesystem-root',
'build',
'--filesystem-scheme',
'org-dartlang-app',
'--initialize-from-dill',
RegExp(r'^build\/(?:[a-z0-9]{32})\.cache\.dill$'),
'--platform',
'file:///HostArtifact.webPlatformKernelFolder/ddc_outline_sound.dill',
'--verbosity=error',
'--sound-null-safety'
], stdout: 'result abc\nline0\nline1\nabc\nabc build/out 0')
]);
final WebTestCompiler compiler = WebTestCompiler(
logger: logger,
fileSystem: fileSystem,
platform: FakePlatform(
environment: <String, String>{},
),
artifacts: Artifacts.test(),
processManager: processManager,
config: config,
);

const BuildInfo buildInfo = BuildInfo(
BuildMode.debug,
'',
treeShakeIcons: false,
);

await compiler.initialize(
projectDirectory: fileSystem.directory('project'),
testOutputDir: 'build',
testFiles: <String>['project/test/fake_test.dart'],
buildInfo: buildInfo,
);

expect(processManager.hasRemainingExpectations, isFalse);
});
}
12 changes: 10 additions & 2 deletions packages/flutter_tools/test/src/fake_process_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FakeCommand {

/// The exact commands that must be matched for this [FakeCommand] to be
/// considered correct.
final List<String> command;
final List<Pattern> command;

/// The exact working directory that must be matched for this [FakeCommand] to
/// be considered correct.
Expand Down Expand Up @@ -110,7 +110,15 @@ class FakeCommand {
Map<String, String>? environment,
Encoding? encoding,
) {
expect(command, equals(this.command));
expect(command.length, this.command.length);
for(int i = 0; i < command.length; i++) {
final Pattern expected = this.command[i];
if (expected is String) {
expect(command[i], expected);
} else {
expect(command[i], matches(this.command[i]));
}
}
if (this.workingDirectory != null) {
expect(this.workingDirectory, workingDirectory);
}
Expand Down

0 comments on commit 5201856

Please sign in to comment.