Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pluggable transformation of assets at build time using packages #141194

Closed
wants to merge 10 commits into from

Conversation

andrewkolos
Copy link
Contributor

@andrewkolos andrewkolos commented Jan 9, 2024

WIP

Most recent status update: happy path works appears to work for both flutter run and flutter build for at least web, iOS, and macOS)

Closes #101077

You can play with this feature using this project: https://github.com/andrewkolos/asset_transformers_test. Make sure your flutter checkout is on this branch and that you have cleaned out your local flutter tool cache (glob <flutter install dir>/bin/cache/flutter_tools*).

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.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jan 9, 2024
@andrewkolos andrewkolos added the a: assets Packaging, accessing, or using assets label Jan 9, 2024
@andrewkolos andrewkolos force-pushed the asset-transformation-2 branch 2 times, most recently from c539432 to 9e3252e Compare January 11, 2024 18:20
auto-submit bot pushed a commit that referenced this pull request Jan 23, 2024
…ew type, `AssetBundleEntry` (#142029)

Part of work on #141194

The [`AssetBundle`](https://github.com/flutter/flutter/blob/0833929c997c8a9db11c1e0df9a731ab17b77606/packages/flutter_tools/lib/src/asset.dart#L80) class contains two members, `entries` and `entryKinds`. `entries` contains asset data indexed by asset key. `entryKinds` contains the "kinds" of these assets, again indexed by asset key.

**Change.** Rather than have two separate maps, this PR proposes combining these maps into one by wrapping the asset data and kind into a single data type `AssetBundleEntry`.

**Purpose.** In #141194, I am considering associating more information with an asset. In particular, what transformers are meant to be applied to it when copying it to the build output. Rather than adding another map member onto `AssetBundle` (e.g. `entryTransformers`), I decided to make things neater by introducing the `AssetBundleEntry` type.
auto-submit bot pushed a commit that referenced this pull request Jan 25, 2024
Part of work on [#101077](#141194). This is done as a separate PR to avoid a massive diff.

## Context
1. The `FakeCommand` class accepts a list of patterns that's used to match a command given to its `FakeProcessManager`. Since `FakeCommand` can match a list of patterns, not just specifically strings, it can be used to match commands where the exact value of some arguments can't (easily) known ahead of time. For example, a part of the tool may invoke a command with an argument that is the path of a temporarily file that has a randomly-generated basename.
2. The `FakeCommand` class provides on `onRun` parameter, which is a callback that is run when the `FakeProcessManager` runs a command that matches the `FakeCommand` in question.

## Issue
In the event that a `FakeCommand` is constructed using patterns, the test code can't know the exact values used for arguments in the command. This PR proposes changing the type of `onRun` from `VoidCallback?` to `void Function(List<String>)?`. When run, the value `List<String>` parameter will be the full command that the `FakeCommand` matched.

Example:
```dart
FakeCommand(
  command: <Pattern>[
    artifacts.getArtifactPath(Artifact.engineDartBinary),
    'run',
    'vector_graphics_compiler',
    RegExp(r'--input=/.*\.temp'),
    RegExp(r'--output=/.*\.temp'),
  ],
  onRun: (List<String> command) {
    final outputPath = (() { 
      // code to parse `--output` from `command`
    })();
    testFileSystem.file(outputPath).createSync(recursive: true);
  },
)
```
auto-submit bot pushed a commit that referenced this pull request Jan 26, 2024
…oot (#142277)

Fixes #142285.

Part of work on #141194.

This is a refactor. There should be no changes in tool behavior.
auto-submit bot pushed a commit that referenced this pull request Feb 13, 2024
)

This is in service of #141194

This will make it easier to get the `flutter run -d <browser>` and `flutter build fuschia` cases easier to get under test.
@christopherfujino
Copy link
Member

Closing as superceded by smaller PRs

@andrewkolos andrewkolos deleted the asset-transformation-2 branch April 29, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: assets Packaging, accessing, or using assets tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a pluggable method for asset transformation
2 participants