Skip to content

Conversation

@cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Mar 11, 2021

When dependencies are changed in the middle of run, hot reload and hot restart should update generated_main accordingly.

Fixes #76219

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 feature I am adding, or Hixie said the 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
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

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

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 11, 2021
@google-cla google-cla bot added the cla: yes label Mar 11, 2021
@cyanglaz cyanglaz marked this pull request as draft March 11, 2021 20:30
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: prefer relative imports for flutter_tools

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: doc comment describing what this is for.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be read from the environment configuration - see the KernelSnapshot target for an example, think it is called target or something like that

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should only skip if generateDartPluginRegistry is false

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh, smart :D

@cyanglaz cyanglaz force-pushed the dart_restraint_hot_reload branch from 5c8472f to 8b62bbd Compare March 12, 2021 01:16
@cyanglaz cyanglaz force-pushed the dart_restraint_hot_reload branch from 843ffba to 2c823cc Compare March 15, 2021 21:57
@cyanglaz cyanglaz marked this pull request as ready for review March 15, 2021 21:58
@cyanglaz cyanglaz requested a review from jonahwilliams March 15, 2021 21:58
/// Construct a [DartPluginRegistrantTarget].
///
/// If `project` is unset, a [FlutterProject] based on environment is used.
DartPluginRegistrantTarget({FlutterProject project}) {
Copy link
Contributor Author

@cyanglaz cyanglaz Mar 15, 2021

Choose a reason for hiding this comment

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

the project param is mainly configurable for testing. In tests, i needed a FlutterProject.fromDirectoryTest

If there are better solution to this, please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can add a @VisibleForTesting annotation on it if it isn't meant to be normally used

@jonahwilliams
Copy link
Contributor

Analyzing 3 directories...                                      

   info • Sort directive sections alphabetically • packages/flutter_tools/lib/src/build_system/targets/dart_plugin_registrant.dart:10:1 • directives_ordering
   info • Unused import: 'package:flutter_tools/src/build_system/targets/localizations.dart' • packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart:12:8 • unused_import
   info • Unused import: 'package:flutter_tools/src/localizations/gen_l10n.dart' • packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart:13:8 • unused_import
   info • Unused import: 'package:flutter_tools/src/localizations/localizations_utils.dart' • packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart:14:8 • unused_import
   info • Unused import: 'package:flutter_tools/src/plugins.dart' • packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart:15:8 • unused_import
   info • Unused import: 'package:mockito/mockito.dart' • packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart:17:8 • unused_import

///
/// If `project` is unset, a [FlutterProject] based on environment is used.
DartPluginRegistrantTarget({FlutterProject project}) {
_project = project;
Copy link
Contributor

Choose a reason for hiding this comment

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

do this in an initializer and make it final

/// Construct a [DartPluginRegistrantTarget].
///
/// If `project` is unset, a [FlutterProject] based on environment is used.
DartPluginRegistrantTarget({FlutterProject project}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this constructor should be const

@cyanglaz cyanglaz changed the title [wip] regenerate generated_main if deps changed in hot reload/restart regenerate generated_main if deps changed in hot reload/restart Mar 18, 2021
Copy link
Contributor Author

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

@jonahwilliams Fixed review comments. PTAL

@cyanglaz cyanglaz force-pushed the dart_restraint_hot_reload branch from aa6787d to 280989a Compare March 22, 2021 18:50
@cyanglaz cyanglaz requested a review from jonahwilliams March 23, 2021 16:20
@jonahwilliams
Copy link
Contributor

Holding off on landing this until we re-visting the dart plugin registrant

@cyanglaz cyanglaz requested a review from blasten March 29, 2021 16:00
@jonahwilliams jonahwilliams marked this pull request as draft April 1, 2021 20:34
// so the resident compiler can find it.
final File newMainDart = buildDir.parent.childFile('generated_main.dart');
if (await generateMainDartWithPluginRegistrant(
await generateMainDartWithPluginRegistrant(
Copy link

Choose a reason for hiding this comment

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

I thought this would now be handled by the target DartPluginRegistrantTarget. no?

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 thought DartPluginRegistrantTarget only happens in hot reload not compile. At least that's the behavior in my manual testing.

@jonahwilliams Is there a way to always handle this in DartPluginRegistrantTarget, both in compile and hot reload/restart?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should run before the first compile, but that should be easy to checl

Copy link

Choose a reason for hiding this comment

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

This is fixed in 829756e

final String renderedTemplate = globals.templateRenderer
.renderString(template, context, htmlEscapeValues: false);
final File file = globals.fs.file(filePath);
final FileSystem fs = fileSystem ?? globals.fs;
Copy link

Choose a reason for hiding this comment

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

what about just globals.fs? it'd be more consistent with the use of globals in line 28

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this adds the possibility to over write fileSystem which makes test easier.


final CompositeTarget compositeTarget = CompositeTarget(<Target>[
const GenerateLocalizationsTarget(),
const DartPluginRegistrantTarget(),
Copy link

Choose a reason for hiding this comment

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

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regenerate Dart plugin registrant after a hot restart

3 participants