Skip to content

Commit d48c4e1

Browse files
Allow empty dart defines in flutter assemble (flutter#177198)
When building https://github.com/flutter/samples/tree/main/add_to_app/multiple_flutters, the `[CP-User] Run Flutter Build multiple_flutters_module Script` step failed with: ``` Showing Recent Messages [ +3 ms] Improperly formatted define flag: [ ] #0 throwToolExit (package:flutter_tools/src/base/common.dart:34:3) #1 AssembleCommand._parseDefines (package:flutter_tools/src/commands/assemble.dart:279:9) ``` the command was: ``` /Users/<User>/flutter/bin/flutter --verbose assemble --no-version-check --output=/Users/<User>/Library/Developer/Xcode/DerivedData/MultipleFluttersIos-<Hash>/Build/Products/Debug-iphonesimulator/ -dTargetPlatform=ios -dTargetFile=lib/main.dart -dBuildMode=debug -dConfiguration=Debug -dIosArchs=arm64 -dSdkRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.0.sdk -dSplitDebugInfo= -dTreeShakeIcons=false -dTrackWidgetCreation=true -dDartObfuscation=false -dAction=build -dFrontendServerStarterPath= --ExtraGenSnapshotOptions= --DartDefines= --ExtraFrontEndOptions= -dSrcRoot=/Users/<User>/flutter_debug/samples/add_to_app/multiple_flutters/multiple_flutters_ios -dTargetDeviceOSVersion=26.0 -dCodesignIdentity=- debug_ios_bundle_flutter_assets ``` the empty `--DartDefines=` comes from https://github.com/flutter/flutter/blob/68cddc9bf5c449d5a55fe48ebb9b446ef76ae6b0/packages/flutter_tools/bin/xcode_backend.dart#L660 This PR makes `_parseDefines` ignore these empty dart defines. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 8c67d8c commit d48c4e1

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

packages/flutter_tools/lib/src/commands/assemble.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class AssembleCommand extends FlutterCommand {
249249
output = globals.fs.path.join(_flutterProject.directory.path, output);
250250
}
251251
final Artifacts artifacts = globals.artifacts!;
252-
final result = Environment(
252+
return Environment(
253253
outputDir: globals.fs.directory(output),
254254
buildDir: _flutterProject.directory
255255
.childDirectory('.dart_tool')
@@ -269,12 +269,14 @@ class AssembleCommand extends FlutterCommand {
269269
engineVersion: artifacts.usesLocalArtifacts ? null : globals.flutterVersion.engineRevision,
270270
generateDartPluginRegistry: true,
271271
);
272-
return result;
273272
}
274273

275274
Map<String, String> _parseDefines(List<String> values) {
276275
final results = <String, String>{};
277276
for (final chunk in values) {
277+
if (chunk.isEmpty) {
278+
continue;
279+
}
278280
final int indexEquals = chunk.indexOf('=');
279281
if (indexEquals == -1) {
280282
throwToolExit('Improperly formatted define flag: $chunk');

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,10 @@ abstract class FlutterCommand extends Command<void> {
16031603
});
16041604

16051605
if (argParser.options.containsKey(FlutterOptions.kDartDefinesOption)) {
1606-
dartDefines.addAll(stringsArg(FlutterOptions.kDartDefinesOption));
1606+
final Iterable<String> defines = stringsArg(
1607+
FlutterOptions.kDartDefinesOption,
1608+
).where((string) => string.isNotEmpty);
1609+
dartDefines.addAll(defines);
16071610
}
16081611

16091612
return dartDefines;

packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,35 @@ void main() {
8585
},
8686
);
8787

88+
testUsingContext(
89+
'flutter assemble can parse empty defines',
90+
() async {
91+
final CommandRunner<void> commandRunner = createTestCommandRunner(
92+
AssembleCommand(
93+
buildSystem: TestBuildSystem.all(BuildResult(success: true), (
94+
Target target,
95+
Environment environment,
96+
) {
97+
expect(environment.defines, const {'DeferredComponents': 'false'});
98+
}),
99+
),
100+
);
101+
await commandRunner.run(<String>[
102+
'assemble',
103+
'-o Output',
104+
'--DartDefines=',
105+
'debug_macos_bundle_flutter_assets',
106+
]);
107+
108+
expect(testLogger.traceText, contains('build succeeded.'));
109+
},
110+
overrides: <Type, Generator>{
111+
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
112+
FileSystem: () => MemoryFileSystem.test(),
113+
ProcessManager: () => FakeProcessManager.any(),
114+
},
115+
);
116+
88117
testUsingContext(
89118
'flutter assemble can parse inputs',
90119
() async {

0 commit comments

Comments
 (0)