Skip to content

Conversation

@andrewkolos
Copy link
Contributor

In service of #143348

This will make testing of asset transformation hot reload behavior easier (specifically in that we can avoid having to write a test that looks like this:

testUsingContext('transforms assets declared with transformers', () async {
Cache.flutterRoot = Cache.defaultFlutterRoot(
platform: globals.platform,
fileSystem: fileSystem,
userMessages: UserMessages(),
);
final Environment environment = Environment.test(
fileSystem.currentDirectory,
processManager: globals.processManager,
artifacts: Artifacts.test(),
fileSystem: fileSystem,
logger: logger,
platform: globals.platform,
defines: <String, String>{},
);
await fileSystem.file('.packages').create();
fileSystem.file('pubspec.yaml')
..createSync()
..writeAsStringSync('''
name: example
flutter:
assets:
- path: input.txt
transformers:
- package: my_capitalizer_transformer
args: ["-a", "-b", "--color", "green"]
''');
fileSystem.file('input.txt')
..createSync(recursive: true)
..writeAsStringSync('abc');
await const CopyAssets().build(environment);
expect(logger.errorText, isEmpty);
expect(globals.processManager, hasNoRemainingExpectations);
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/input.txt'), exists);
}, overrides: <Type, Generator> {
Logger: () => logger,
FileSystem: () => fileSystem,
Platform: () => FakePlatform(),
ProcessManager: () => FakeProcessManager.list(
<FakeCommand>[
FakeCommand(
command: <Pattern>[
Artifacts.test().getArtifactPath(Artifact.engineDartBinary),
'run',
'my_capitalizer_transformer',
RegExp('--input=.*'),
RegExp('--output=.*'),
'-a',
'-b',
'--color',
'green',
],
onRun: (List<String> args) {
final ArgResults parsedArgs = (ArgParser()
..addOption('input')
..addOption('output')
..addOption('color')
..addFlag('aaa', abbr: 'a')
..addFlag('bbb', abbr: 'b'))
.parse(args);
expect(parsedArgs['aaa'], true);
expect(parsedArgs['bbb'], true);
expect(parsedArgs['color'], 'green');
final File input = fileSystem.file(parsedArgs['input'] as String);
expect(input, exists);
final String inputContents = input.readAsStringSync();
expect(inputContents, 'abc');
fileSystem.file(parsedArgs['output'])
..createSync()
..writeAsStringSync(inputContents.toUpperCase());
},
),
],
),
});

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 Feb 23, 2024
@andrewkolos andrewkolos force-pushed the di-config-into-dev-fs branch from 82820e8 to 964abc9 Compare February 23, 2024 07:29
@andrewkolos andrewkolos marked this pull request as ready for review February 23, 2024 07:50
/// Returns the asset build output directory.
String getAssetBuildDirectory() {
return globals.fs.path.join(getBuildDirectory(), 'flutter_assets');
String getAssetBuildDirectory([Config? config, FileSystem? fileSystem]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

when are these null? just tests? to me this pattern of optional parameters that fallback to grabbing globals is a code smell--but I can understand if always direct injecting would take a ridiculous amount of work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are ~20 references to getBuildDirectory (this is excluding tests and references from the below functions). Each of the functions below that call this have a few references each. I could try to refactor this now, but it could take anywhere between 30 minutes and an entire day.

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 good enough for me. can you add a TODO to make these required parameters then? I just want to avoid cargo-culting this pattern, if possible. But I think overall this is an improvement to the code--just want to make sure readers don't see this and think it's the blessed path :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. I'm currently attempting the refactor to make these required, and I'll settle for the TODO if it starts taking any significant amount of time.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me. we'll have to pay this cost sooner or later...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we end up moving forward with your idea of a single context object that we DI everywhere, wouldn't that make this work here moot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also this refactor would indeed be a significant amount of work unless we are okay with adding more globals.dart imports.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose you're right, let's leave it for now. We'd have to touch all these functions, but it'd be a different refactor

});

testUsingContext('DevFS tracks when FontManifest is updated', () async {
testWithoutContext('DevFS tracks when FontManifest is updated', () async {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

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.

ship it

@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 23, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 23, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 23, 2024

auto label is removed for flutter/flutter/144002, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 23, 2024
@auto-submit auto-submit bot merged commit 37c8df1 into flutter:master Feb 23, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Feb 24, 2024
flutter/flutter@39585e6...f6c1082

2024-02-24 [email protected] Roll Flutter Engine from 81035b7d56ef to 1d7d5e613d7e (1 revision) (flutter/flutter#144085)
2024-02-24 [email protected] Roll Flutter Engine from a148bdb63740 to 81035b7d56ef (2 revisions) (flutter/flutter#144083)
2024-02-24 [email protected] Roll Flutter Engine from 3c036c081534 to a148bdb63740 (1 revision) (flutter/flutter#144077)
2024-02-24 [email protected] Roll Flutter Engine from 738042295f97 to 3c036c081534 (2 revisions) (flutter/flutter#144073)
2024-02-24 [email protected] Roll Flutter Engine from ca2452074a49 to 738042295f97 (4 revisions) (flutter/flutter#144071)
2024-02-24 [email protected] Roll Flutter Engine from 9409b75e8f35 to ca2452074a49 (2 revisions) (flutter/flutter#144068)
2024-02-24 [email protected] Adding support for DDC modules when running Flutter Web in debug mode (flutter/flutter#141423)
2024-02-24 [email protected] Roll Flutter Engine from 733163c4e5d7 to 9409b75e8f35 (1 revision) (flutter/flutter#144061)
2024-02-23 [email protected] allow optional direct injection of Config instance into DevFS (flutter/flutter#144002)
2024-02-23 [email protected] Enable asset transformation for `flutter build` for iOS, Android, Windows, MacOS, Linux, and web (also `flutter run` without hot reload support) (flutter/flutter#143815)
2024-02-23 [email protected] Roll Flutter Engine from 5d1c0d4dc327 to 733163c4e5d7 (1 revision) (flutter/flutter#144058)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.24.4 to 3.24.5 (flutter/flutter#144059)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump codecov/codecov-action from 4.0.1 to 4.0.2 (flutter/flutter#144060)
2024-02-23 [email protected] Render the warm up frame in a proper rendering process (flutter/flutter#143290)
2024-02-23 [email protected] Roll Flutter Engine from fbc9b889aee9 to 5d1c0d4dc327 (2 revisions) (flutter/flutter#144049)
2024-02-23 [email protected] Roll Flutter Engine from b5bebfe43d29 to fbc9b889aee9 (3 revisions) (flutter/flutter#144041)
2024-02-23 [email protected] disable debug banner in m3 page test apps. (flutter/flutter#143857)
2024-02-23 [email protected] Relands "Changing `TextPainter.getOffsetForCaret` implementation to remove the logarithmic search (#143281)" (reverted in #143801) (flutter/flutter#143954)
2024-02-23 [email protected] Roll Flutter Engine from 5f99a6c3289e to b5bebfe43d29 (1 revision) (flutter/flutter#144035)
2024-02-23 [email protected] Implementing null-aware operators throughout the repository (flutter/flutter#143804)

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
LouiseHsu pushed a commit to LouiseHsu/packages that referenced this pull request Mar 7, 2024
flutter/flutter@39585e6...f6c1082

2024-02-24 [email protected] Roll Flutter Engine from 81035b7d56ef to 1d7d5e613d7e (1 revision) (flutter/flutter#144085)
2024-02-24 [email protected] Roll Flutter Engine from a148bdb63740 to 81035b7d56ef (2 revisions) (flutter/flutter#144083)
2024-02-24 [email protected] Roll Flutter Engine from 3c036c081534 to a148bdb63740 (1 revision) (flutter/flutter#144077)
2024-02-24 [email protected] Roll Flutter Engine from 738042295f97 to 3c036c081534 (2 revisions) (flutter/flutter#144073)
2024-02-24 [email protected] Roll Flutter Engine from ca2452074a49 to 738042295f97 (4 revisions) (flutter/flutter#144071)
2024-02-24 [email protected] Roll Flutter Engine from 9409b75e8f35 to ca2452074a49 (2 revisions) (flutter/flutter#144068)
2024-02-24 [email protected] Adding support for DDC modules when running Flutter Web in debug mode (flutter/flutter#141423)
2024-02-24 [email protected] Roll Flutter Engine from 733163c4e5d7 to 9409b75e8f35 (1 revision) (flutter/flutter#144061)
2024-02-23 [email protected] allow optional direct injection of Config instance into DevFS (flutter/flutter#144002)
2024-02-23 [email protected] Enable asset transformation for `flutter build` for iOS, Android, Windows, MacOS, Linux, and web (also `flutter run` without hot reload support) (flutter/flutter#143815)
2024-02-23 [email protected] Roll Flutter Engine from 5d1c0d4dc327 to 733163c4e5d7 (1 revision) (flutter/flutter#144058)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.24.4 to 3.24.5 (flutter/flutter#144059)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump codecov/codecov-action from 4.0.1 to 4.0.2 (flutter/flutter#144060)
2024-02-23 [email protected] Render the warm up frame in a proper rendering process (flutter/flutter#143290)
2024-02-23 [email protected] Roll Flutter Engine from fbc9b889aee9 to 5d1c0d4dc327 (2 revisions) (flutter/flutter#144049)
2024-02-23 [email protected] Roll Flutter Engine from b5bebfe43d29 to fbc9b889aee9 (3 revisions) (flutter/flutter#144041)
2024-02-23 [email protected] disable debug banner in m3 page test apps. (flutter/flutter#143857)
2024-02-23 [email protected] Relands "Changing `TextPainter.getOffsetForCaret` implementation to remove the logarithmic search (#143281)" (reverted in #143801) (flutter/flutter#143954)
2024-02-23 [email protected] Roll Flutter Engine from 5f99a6c3289e to b5bebfe43d29 (1 revision) (flutter/flutter#144035)
2024-02-23 [email protected] Implementing null-aware operators throughout the repository (flutter/flutter#143804)

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
@andrewkolos andrewkolos deleted the di-config-into-dev-fs branch April 29, 2024 18:17
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.

2 participants