forked from firka/flutter
[ Tool ] Correctly select entrypoint target for web build from positional argument list (#166260)
`BuildWebCommand` was accessing the value of `target` directly from the argument parser rather than using the `targetFile` getter defined on `FlutterCommand` which handles file paths provided in the positional argument list. Fixes https://github.com/flutter/flutter/issues/136830.
This commit is contained in:
@@ -208,7 +208,6 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
];
|
||||
}
|
||||
|
||||
final String target = stringArg('target')!;
|
||||
final BuildInfo buildInfo = await getBuildInfo();
|
||||
final String? baseHref = stringArg('base-href');
|
||||
if (baseHref != null && !(baseHref.startsWith('/') && baseHref.endsWith('/'))) {
|
||||
@@ -246,7 +245,7 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
);
|
||||
await webBuilder.buildWeb(
|
||||
project,
|
||||
target,
|
||||
targetFile,
|
||||
buildInfo,
|
||||
ServiceWorkerStrategy.fromCliName(stringArg('pwa-strategy')),
|
||||
compilerConfigs: compilerConfigs,
|
||||
|
||||
@@ -43,6 +43,7 @@ void main() {
|
||||
writePackageConfigFile(mainLibName: 'foo', directory: fileSystem.currentDirectory);
|
||||
fileSystem.file(fileSystem.path.join('web', 'index.html')).createSync(recursive: true);
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
fileSystem.file(fileSystem.path.join('lib', 'a.dart')).createSync(recursive: true);
|
||||
logger = BufferLogger.test();
|
||||
processManager = FakeProcessManager.any();
|
||||
});
|
||||
@@ -155,6 +156,110 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'Infers target entrypoint correctly from --target',
|
||||
() async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/136830.
|
||||
final BuildCommand buildCommand = BuildCommand(
|
||||
androidSdk: FakeAndroidSdk(),
|
||||
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
osUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
|
||||
setupFileSystemForEndToEndTest(fileSystem);
|
||||
await runner.run(<String>[
|
||||
'build',
|
||||
'web',
|
||||
'--no-pub',
|
||||
'--no-web-resources-cdn',
|
||||
'--target=lib/a.dart',
|
||||
]);
|
||||
|
||||
final Directory buildDir = fileSystem.directory(fileSystem.path.join('build', 'web'));
|
||||
expect(buildDir.existsSync(), true);
|
||||
expect(testLogger.statusText, contains('Compiling lib/a.dart for the Web...'));
|
||||
expect(testLogger.statusText, contains('✓ Built ${buildDir.path}'));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Platform: () => fakePlatform,
|
||||
FileSystem: () => fileSystem,
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
|
||||
ProcessManager: () => processManager,
|
||||
BuildSystem:
|
||||
() => TestBuildSystem.all(BuildResult(success: true), (
|
||||
Target target,
|
||||
Environment environment,
|
||||
) {
|
||||
expect(environment.defines, <String, String>{
|
||||
'TargetFile': 'lib/a.dart',
|
||||
'HasWebPlugins': 'true',
|
||||
'ServiceWorkerStrategy': 'offline-first',
|
||||
'BuildMode': 'release',
|
||||
'DartDefines':
|
||||
'RkxVVFRFUl9WRVJTSU9OPTAuMC4w,RkxVVFRFUl9DSEFOTkVMPW1hc3Rlcg==,RkxVVFRFUl9HSVRfVVJMPWh0dHBzOi8vZ2l0aHViLmNvbS9mbHV0dGVyL2ZsdXR0ZXIuZ2l0,RkxVVFRFUl9GUkFNRVdPUktfUkVWSVNJT049MTExMTE=,RkxVVFRFUl9FTkdJTkVfUkVWSVNJT049YWJjZGU=,RkxVVFRFUl9EQVJUX1ZFUlNJT049MTI=',
|
||||
'DartObfuscation': 'false',
|
||||
'TrackWidgetCreation': 'false',
|
||||
'TreeShakeIcons': 'true',
|
||||
'UseLocalCanvasKit': 'true',
|
||||
});
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'Infers target entrypoint correctly from positional argument list',
|
||||
() async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/136830.
|
||||
final BuildCommand buildCommand = BuildCommand(
|
||||
androidSdk: FakeAndroidSdk(),
|
||||
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
osUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
|
||||
setupFileSystemForEndToEndTest(fileSystem);
|
||||
await runner.run(<String>[
|
||||
'build',
|
||||
'web',
|
||||
'--no-pub',
|
||||
'--no-web-resources-cdn',
|
||||
'lib/a.dart',
|
||||
]);
|
||||
|
||||
final Directory buildDir = fileSystem.directory(fileSystem.path.join('build', 'web'));
|
||||
expect(buildDir.existsSync(), true);
|
||||
expect(testLogger.statusText, contains('Compiling lib/a.dart for the Web...'));
|
||||
expect(testLogger.statusText, contains('✓ Built ${buildDir.path}'));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Platform: () => fakePlatform,
|
||||
FileSystem: () => fileSystem,
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
|
||||
ProcessManager: () => processManager,
|
||||
BuildSystem:
|
||||
() => TestBuildSystem.all(BuildResult(success: true), (
|
||||
Target target,
|
||||
Environment environment,
|
||||
) {
|
||||
expect(environment.defines, <String, String>{
|
||||
'TargetFile': 'lib/a.dart',
|
||||
'HasWebPlugins': 'true',
|
||||
'ServiceWorkerStrategy': 'offline-first',
|
||||
'BuildMode': 'release',
|
||||
'DartDefines':
|
||||
'RkxVVFRFUl9WRVJTSU9OPTAuMC4w,RkxVVFRFUl9DSEFOTkVMPW1hc3Rlcg==,RkxVVFRFUl9HSVRfVVJMPWh0dHBzOi8vZ2l0aHViLmNvbS9mbHV0dGVyL2ZsdXR0ZXIuZ2l0,RkxVVFRFUl9GUkFNRVdPUktfUkVWSVNJT049MTExMTE=,RkxVVFRFUl9FTkdJTkVfUkVWSVNJT049YWJjZGU=,RkxVVFRFUl9EQVJUX1ZFUlNJT049MTI=',
|
||||
'DartObfuscation': 'false',
|
||||
'TrackWidgetCreation': 'false',
|
||||
'TreeShakeIcons': 'true',
|
||||
'UseLocalCanvasKit': 'true',
|
||||
});
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'Does not allow -O0 optimization level',
|
||||
() async {
|
||||
|
||||
Reference in New Issue
Block a user