[tool] Proposal to multiple defines for --dart-define-from-file#120878
[tool] Proposal to multiple defines for --dart-define-from-file#120878auto-submit[bot] merged 14 commits intoflutter:masterfrom ronnnnn:feat-multi-dart-define-from-file
Conversation
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
Thank you for contributing! You will need to get all CI tests (other than luci-flutter) passing before this will PR will be reviewed. |
fix: accept multi options
|
@christopherfujino |
| throwToolExit('Json config define file "--${FlutterOptions.kDartDefineFromFileOption}=$configJsonPath" format err, ' | ||
| 'please fix first! format err:\n$err'); | ||
| final List<String> configJsonPaths = stringsArg(FlutterOptions.kDartDefineFromFileOption); | ||
| if (configJsonPaths.isNotEmpty && configJsonPaths.every((String path) => globals.fs.isFileSync(path))) { |
There was a problem hiding this comment.
in the case one of these paths is not actually a file, I think we should throwToolExit() with a message explaining exactly what the user did wrong (I know we didn't handle this previously, but I think this is important).
| } on FormatException catch (err) { | ||
| throwToolExit('Json config define file "--${FlutterOptions.kDartDefineFromFileOption}=$configJsonPath" format err, ' | ||
| 'please fix first! format err:\n$err'); | ||
| final List<String> configJsonPaths = stringsArg(FlutterOptions.kDartDefineFromFileOption); |
There was a problem hiding this comment.
This is also tech debt from a previous change, but extending this code highlights the fact that this code is not dry, and changes to this block of code also need to be made to flutter_command.dart. Can you instead move this code to a helper function in flutter_command.dart (since AssembleCommand extends FlutterCommand it should be accessible in this file) that parses both the --dart-define-from-file and --dart-define options and returns a single List<String> of dartDefines?
|
@christopherfujino |
|
@christopherfujino |
| BuildSystem: () => TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) { | ||
| expect(environment.defines[kDartDefines], 'a0ludD0x,a0RvdWJsZT0xLjE=,bmFtZT1kZW5naGFpemh1,dGl0bGU9dGhpcyBpcyB0aXRsZSBmcm9tIGNvbmZpZyBqc29uIGZpbGU='); | ||
| BuildSystem: () => TestBuildSystem.all(BuildResult(success: false), (Target target, Environment environment) { | ||
| expect(environment.defines[kDartDefines], 'a0ludD0x,a0RvdWJsZT0xLjE=,bmFtZT1kZW5naGFpemh1,dGl0bGU9dGhpcyBpcyB0aXRsZSBmcm9tIGNvbmZpZyBqc29uIGZpbGU=,Ym9keT10aGlzIGlzIGJvZHkgZnJvbSBjb25maWcganNvbiBmaWxl'); |
There was a problem hiding this comment.
This is my first time seeing this test--what encoding is this?
There was a problem hiding this comment.
Also, are you intentionally now testing that this fails?
There was a problem hiding this comment.
These are encoded from dartDefines' key and value on encodeDartDefines in build_info.dart.
For example, kInt=1 is encoded to a0ludD0x.
I intended this test should success, this is my mistake. But, I found that assertions on this test file doesn't work as expected because of FakeBundleBuilder that do no-op on build function.
I'll investigate more and fix them to work correctly.
There was a problem hiding this comment.
I fixed to use real BundleBuilder so that we can inject BuildSystem on build_bundle_test.dart and assert environment properties.
I checked tests work as expected and also fix flutter_command.dart.
There was a problem hiding this comment.
Ahh, so base64. I'm skeptical this is the best way to assert here (given I had to decode it to code review), however, that can be a cleanup in a later PR.
|
@andrewkolos can you take another look and, if you approve, add |
|
I updated from upstream/master in an effort to unstuck the Google testing check. |
Overview
Make
--dart-define-from-fileoption define multiple times.Use case
In case of changing values for each environment of flavors and build types, multi
--dart-define-from-fileis needed.For example,
Links
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.