Skip to content

Commit 5201856

Browse files
Use file:/// style uris when passing platform to the compiler. (#116553)
* 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.
1 parent 174d3be commit 5201856

File tree

3 files changed

+105
-3
lines changed

3 files changed

+105
-3
lines changed

packages/flutter_tools/lib/src/test/web_test_compiler.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class WebTestCompiler {
123123
initializeFromDill: cachedKernelPath,
124124
targetModel: TargetModel.dartdevc,
125125
extraFrontEndOptions: extraFrontEndOptions,
126-
platformDill: platformDillPath,
126+
platformDill: _fileSystem.file(platformDillPath).absolute.uri.toString(),
127127
dartDefines: buildInfo.dartDefines,
128128
librariesSpec: _artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson).uri.toString(),
129129
packagesPath: buildInfo.packagesPath,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:file/memory.dart';
6+
import 'package:flutter_tools/src/artifacts.dart';
7+
import 'package:flutter_tools/src/base/config.dart';
8+
import 'package:flutter_tools/src/base/logger.dart';
9+
import 'package:flutter_tools/src/base/platform.dart';
10+
import 'package:flutter_tools/src/build_info.dart';
11+
import 'package:flutter_tools/src/test/web_test_compiler.dart';
12+
import 'package:test/expect.dart';
13+
14+
import '../../src/context.dart';
15+
16+
void main() {
17+
testUsingContext('web test compiler issues valid compile command', () async {
18+
final BufferLogger logger = BufferLogger.test();
19+
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
20+
fileSystem.file('project/test/fake_test.dart').createSync(recursive: true);
21+
fileSystem.file('build/out').createSync(recursive: true);
22+
fileSystem.file('build/build/out.sources').createSync(recursive: true);
23+
fileSystem.file('build/build/out.json')
24+
..createSync()
25+
..writeAsStringSync('{}');
26+
fileSystem.file('build/build/out.map').createSync();
27+
fileSystem.file('build/build/out.metadata').createSync();
28+
final FakePlatform platform = FakePlatform(
29+
environment: <String, String>{},
30+
);
31+
final Config config = Config(
32+
Config.kFlutterSettings,
33+
fileSystem: fileSystem,
34+
logger: logger,
35+
platform: platform,
36+
);
37+
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
38+
FakeCommand(command: <Pattern>[
39+
'Artifact.engineDartBinary.TargetPlatform.web_javascript',
40+
'--disable-dart-dev',
41+
'Artifact.frontendServerSnapshotForEngineDartSdk.TargetPlatform.web_javascript',
42+
'--sdk-root',
43+
'HostArtifact.flutterWebSdk/',
44+
'--incremental',
45+
'--target=dartdevc',
46+
'--experimental-emit-debug-metadata',
47+
'--output-dill',
48+
'build/out',
49+
'--packages',
50+
'.dart_tool/package_config.json',
51+
'-Ddart.vm.profile=false',
52+
'-Ddart.vm.product=false',
53+
'--enable-asserts',
54+
'--filesystem-root',
55+
'project/test',
56+
'--filesystem-root',
57+
'build',
58+
'--filesystem-scheme',
59+
'org-dartlang-app',
60+
'--initialize-from-dill',
61+
RegExp(r'^build\/(?:[a-z0-9]{32})\.cache\.dill$'),
62+
'--platform',
63+
'file:///HostArtifact.webPlatformKernelFolder/ddc_outline_sound.dill',
64+
'--verbosity=error',
65+
'--sound-null-safety'
66+
], stdout: 'result abc\nline0\nline1\nabc\nabc build/out 0')
67+
]);
68+
final WebTestCompiler compiler = WebTestCompiler(
69+
logger: logger,
70+
fileSystem: fileSystem,
71+
platform: FakePlatform(
72+
environment: <String, String>{},
73+
),
74+
artifacts: Artifacts.test(),
75+
processManager: processManager,
76+
config: config,
77+
);
78+
79+
const BuildInfo buildInfo = BuildInfo(
80+
BuildMode.debug,
81+
'',
82+
treeShakeIcons: false,
83+
);
84+
85+
await compiler.initialize(
86+
projectDirectory: fileSystem.directory('project'),
87+
testOutputDir: 'build',
88+
testFiles: <String>['project/test/fake_test.dart'],
89+
buildInfo: buildInfo,
90+
);
91+
92+
expect(processManager.hasRemainingExpectations, isFalse);
93+
});
94+
}

packages/flutter_tools/test/src/fake_process_manager.dart

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FakeCommand {
3939

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

4444
/// The exact working directory that must be matched for this [FakeCommand] to
4545
/// be considered correct.
@@ -110,7 +110,15 @@ class FakeCommand {
110110
Map<String, String>? environment,
111111
Encoding? encoding,
112112
) {
113-
expect(command, equals(this.command));
113+
expect(command.length, this.command.length);
114+
for(int i = 0; i < command.length; i++) {
115+
final Pattern expected = this.command[i];
116+
if (expected is String) {
117+
expect(command[i], expected);
118+
} else {
119+
expect(command[i], matches(this.command[i]));
120+
}
121+
}
114122
if (this.workingDirectory != null) {
115123
expect(this.workingDirectory, workingDirectory);
116124
}

0 commit comments

Comments
 (0)