Skip to content

Conversation

@andrewkolos
Copy link
Contributor

@andrewkolos andrewkolos commented Mar 7, 2024

In service of #143348

When invoking a package to transform an asset, we set FLUTTER_BUILD_MODE to the CLI name of the build mode being used. Inspired by #101077 (comment):

Do transformers know whether they get executed in debug or release mode? I kinda imagine that being useful. Ex: There's a transformer that optimizes the file size of images. Depending on the amount and size of the images, that could take a significant amount of time. Therefore, I might want to only execute it in release builds.

Note for the reviewer: the interesting part of this change can be found in the commit set environment variable to build mode when running asset transformer…. The rest of the change is updating call sites with a new argument.

Pre-launch Checklist

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

@andrewkolos andrewkolos added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 7, 2024
@andrewkolos andrewkolos force-pushed the add-build-mode-env-variable-to-asset-transformer-environment branch from f030d69 to aadd25a Compare March 10, 2024 21:09
@andrewkolos andrewkolos marked this pull request as ready for review March 11, 2024 17:41
@andrewkolos andrewkolos force-pushed the add-build-mode-env-variable-to-asset-transformer-environment branch from f5f85eb to 579912d Compare March 11, 2024 17:42
_dartBinaryPath = dartBinaryPath,
_buildMode = buildMode;

static const String buildModeEnvVar = 'FLUTTER_BUILD_MODE';
Copy link
Contributor Author

@andrewkolos andrewkolos Mar 11, 2024

Choose a reason for hiding this comment

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

I have an internal instinct telling me that these should be namespaced, but FLUTTER_ASSET_TRANFORMER__BUILD_MODE feels a bit verbose. I think we are fine here.

@andrewkolos
Copy link
Contributor Author

andrewkolos commented Mar 11, 2024

I do think a better solution would be to allow users to define separate asset configurations per build mode. For purely demonstrative purposes, consider this example fictional pubspec:

flutter:
  assets:
    - path: assets/hello.png
      buildModes: ["debug"]
    - path: assets/hello.png
      buildModes: ["profile", "release"]
      transformers:
        - package: optimizer
          args: --quality 95

However, this would be 1) harder to implement and maintain and 2) would call for a bunch of design discussion. I think this PR is still useful as a stop gap. I imagine, for example, an image optimization transformer could provide an option like "--release-only" which tells the transformer to just copy the file as-is when not running in release mode.

flutter:
  assets:
    - path: assets/hello.png
      transformers:
        - package: optimizer
          args: --release-only --quality 95

Future<void> build(Environment environment) async {
final String? buildModeEnvironment = environment.defines[kBuildMode];
if (buildModeEnvironment == null) {
throw MissingDefineException(kBuildMode, name);
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if we'll ever hit this. merging this and then seeing if we need to roll back sounds good to me, though.

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

@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 11, 2024
@auto-submit auto-submit bot merged commit 83fad74 into flutter:master Mar 11, 2024
@andrewkolos andrewkolos added the revert Autorevert PR (with "Reason for revert:" comment) label Mar 11, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 11, 2024

A reason for requesting a revert of flutter/flutter/144752 could
not be found or the reason was not properly formatted. Begin a comment with 'Reason for revert:' to tell the bot why
this issue is being reverted.

@auto-submit auto-submit bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Mar 11, 2024
@andrewkolos andrewkolos added the revert Autorevert PR (with "Reason for revert:" comment) label Mar 11, 2024
@andrewkolos
Copy link
Contributor Author

Reason for revert: compilation issue has turned the tree red

auto-submit bot pushed a commit that referenced this pull request Mar 11, 2024
@auto-submit auto-submit bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Mar 11, 2024
auto-submit bot added a commit that referenced this pull request Mar 11, 2024
…ses (#144752)" (#144957)

Reverts: #144752
Initiated by: andrewkolos
Reason for reverting: compilation issue has turned the tree red
Original PR Author: andrewkolos

Reviewed By: {christopherfujino}

This change reverts the following previous change:
In service of #143348

When invoking a package to transform an asset, we set `FLUTTER_BUILD_MODE` to the CLI name of the build mode being used. Inspired by #101077 (comment):

> Do transformers know whether they get executed in debug or release mode? I kinda imagine that being useful. Ex: There's a transformer that optimizes the file size of images. Depending on the amount and size of the images, that could take a significant amount of time. Therefore, I might want to only execute it in release builds.

Note for the reviewer: the interesting part of this change can be found in the commit [set environment variable to build mode when running asset transformer…](579912d). The rest of the change is updating call sites with a new argument.
@christopherfujino
Copy link
Contributor

christopherfujino commented Mar 11, 2024

Reason for revert: compilation issue has turned the tree red

For posterity can you link a failing a build? (This is something I always check when reviewing re-lands)

@andrewkolos
Copy link
Contributor Author

Reason for revert: compilation issue has turned the tree red

For posterity can you link a failing a build? (This is something I always check when reviewing re-lands)

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8753729103951007409/+/u/flutter_config_--clear-features/stdout

Building flutter tool...
Resolving dependencies...
Got dependencies.
flutter/packages/flutter_tools/lib/src/bundle_builder.dart:177:61: Error: Required named parameter 'buildMode' must be provided.
  final AssetTransformer assetTransformer = AssetTransformer(
                                                            ^
flutter/packages/flutter_tools/lib/src/build_system/tools/asset_transformer.dart:22:3: Context: Found this candidate, but the arguments don't match.
  AssetTransformer({

@Jasguerrero
Copy link
Contributor

@CaseyHillers is it possible to get the presubmit google testing run for this PR? I see the check passed but it failed postsubmit

@andrewkolos
Copy link
Contributor Author

@CaseyHillers is it possible to get the presubmit google testing run for this PR? I see the check passed but it failed postsubmit

The PR branch was stale—it branched off master before #144734 landed. That PR introduced a new AssetTransformer call site, while this PR modified the signature of AssetTransformer. I'm assuming this is why the checks initially passed.

@Jasguerrero
Copy link
Contributor

The PR branch was stale—it branched off master before #144734 landed. That PR introduced a new AssetTransformer call site, while this PR modified the signature of AssetTransformer. I'm assuming this is why the checks initially passed.

Interesting. Thanks for the explanation @andrewkolos!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 12, 2024
Manual roll requested by [email protected]

flutter/flutter@3bb2e59...1ca8873

2024-03-12 [email protected] Update integration tests regexes. (flutter/flutter#144847)
2024-03-11 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fail tests on exceptions raised after test completed (#144706)" (flutter/flutter#144970)
2024-03-11 [email protected] Make TabController communicating creation in constructor. (flutter/flutter#144912)
2024-03-11 [email protected] Fail tests on exceptions raised after test completed (flutter/flutter#144706)
2024-03-11 [email protected] Refactoring `if` chains into `switch` statements (flutter/flutter#144905)
2024-03-11 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Expose build mode in environment of asset transformer processes (#144752)" (flutter/flutter#144957)
2024-03-11 [email protected] Expose build mode in environment of asset transformer processes (flutter/flutter#144752)
2024-03-11 [email protected] Roll Flutter Engine from 9196947bc687 to 6745955bb49e (2 revisions) (flutter/flutter#144946)
2024-03-11 [email protected] Skip test temporarily until headingLevel is added in engine (issue 41â�¦ (flutter/flutter#135077)
2024-03-11 [email protected] Roll Flutter Engine from 3b0b59bb224d to 9196947bc687 (1 revision) (flutter/flutter#144934)
2024-03-11 [email protected] Roll Packages from 0badb43 to d489d84 (3 revisions) (flutter/flutter#144931)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request Apr 22, 2024
…es" (#144958)

Relands #144752, which had to be reverted because the branch was stale. The original branch branched off `master` before #144734 landed. That PR introduced a new `AssetTransformer` call site.

This PR branch is identical to the original but with a new commit that addresses the new call site, [update new call sites](6bb5296).
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
…es" (flutter#144958)

Relands flutter#144752, which had to be reverted because the branch was stale. The original branch branched off `master` before flutter#144734 landed. That PR introduced a new `AssetTransformer` call site.

This PR branch is identical to the original but with a new commit that addresses the new call site, [update new call sites](flutter@6bb5296).
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 14, 2024
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