Skip to content

[tool] Proposal to multiple defines for --dart-define-from-file#120878

Merged
auto-submit[bot] merged 14 commits intoflutter:masterfrom
ronnnnn:feat-multi-dart-define-from-file
Mar 6, 2023
Merged

[tool] Proposal to multiple defines for --dart-define-from-file#120878
auto-submit[bot] merged 14 commits intoflutter:masterfrom
ronnnnn:feat-multi-dart-define-from-file

Conversation

@ronnnnn
Copy link
Contributor

@ronnnnn ronnnnn commented Feb 16, 2023

Overview

Make --dart-define-from-file option define multiple times.

Use case

In case of changing values for each environment of flavors and build types, multi --dart-define-from-file is needed.
For example,

// development x debug
flutter build apk --dart-define-from-file=define/flavor/development/android.json --dart-define-from-file=define/flavor/debug/android.json`.

// production x debug
flutter build apk --dart-define-from-file=define/flavor/production/android.json --dart-define-from-file=define/flavor/debug/android.json`.
packages
└ app
  └ define
    ├ build
    │ ├ debug
    │ │ ├ android.json
    │ │ └ ios.json
    │ └ release
    │   ├ android.json
    │   └ ios.json
    └ flavor
      ├ development
      │ ├ android.json
      │ └ ios.json
      └ production
        ├ android.json
        └ ios.json

Links

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.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 16, 2023
@ronnnnn ronnnnn marked this pull request as draft February 16, 2023 12:55
@flutter-dashboard
Copy link

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@ronnnnn ronnnnn marked this pull request as ready for review February 16, 2023 13:08
@christopherfujino
Copy link
Contributor

Thank you for contributing! You will need to get all CI tests (other than luci-flutter) passing before this will PR will be reviewed.

@ronnnnn ronnnnn marked this pull request as draft February 17, 2023 09:41
@ronnnnn ronnnnn marked this pull request as ready for review February 17, 2023 09:51
@ronnnnn
Copy link
Contributor Author

ronnnnn commented Feb 19, 2023

@christopherfujino
I have committed some additional changes and ready for reviews.

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))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@ronnnnn
Copy link
Contributor Author

ronnnnn commented Feb 24, 2023

@christopherfujino
Thank you for your reviews. I'll try to update them.

@ronnnnn
Copy link
Contributor Author

ronnnnn commented Feb 27, 2023

@christopherfujino
I updated from your reviews. I created two helper functions to extract dart defines because flutter_command.dart needs defineConfigJsonMap as a parameter of BuildInfo. What do you think about it?

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my first time seeing this test--what encoding is this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, are you intentionally now testing that this fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this PR and the cleanup!

@christopherfujino
Copy link
Contributor

@andrewkolos can you take another look and, if you approve, add autosubmit?

@andrewkolos
Copy link
Contributor

andrewkolos commented Mar 6, 2023

I updated from upstream/master in an effort to unstuck the Google testing check.

Copy link
Contributor

@andrewkolos andrewkolos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 6, 2023
@auto-submit auto-submit bot merged commit acc840e into flutter:master Mar 6, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants