Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flutter_tools] cache flutter sdk version to disk #124558

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

Merged
merged 41 commits into from
Jun 15, 2023

Conversation

christopherfujino
Copy link
Contributor

@christopherfujino christopherfujino commented Apr 11, 2023

Fixes #112833

Most of the actual changes here are in packages/flutter_tools/lib/src/version.dart, while the rest is largely just addressing changes to the constructor of FlutterVersion which now has different dependencies.

This change makes FlutterVersion an interface with two concrete implementations:

  1. _FlutterVersionGit which is mostly the previous implementation, and
  2. _FlutterVersionFromFile which will read a new .version.json file from the root of the repo

The FlutterVersion constructor is now a factory that first checks if .version.json exists, and if so returns an instance of _FlutterVersionFromGit else it returns the fallback _FlutterVersionGit which will end up writing .version.json so that we don't need to re-calculate the version on the next invocation.

.version.json will be deleted in the bash/batch entrypoints any time we need to rebuild he tool (this will usually be because the user did flutter upgrade or flutter channel, or manually changed the commit with git).

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 11, 2023
@@ -123,7 +123,10 @@ function upgrade_flutter () (
# * STAMP_PATH is an empty file, or
# * Contents of STAMP_PATH is not what we are going to compile, or
# * pubspec.yaml last modified after pubspec.lock
if [[ ! -f "$SNAPSHOT_PATH" || ! -s "$STAMP_PATH" || "$(cat "$STAMP_PATH")" != "$compilekey" || "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]]; then
if [[ ! -f "$SNAPSHOT_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.

This is just a formatting change that makes it more legible

@christopherfujino christopherfujino force-pushed the add-version-json branch 2 times, most recently from fd582af to c2e57ee Compare April 21, 2023 21:55
@christopherfujino christopherfujino changed the title [flutter_tools] persist version information to disk [flutter_tools] cache flutter sdk version to disk Apr 27, 2023
@flutter-dashboard flutter-dashboard bot added the a: text input Entering text in a text field or keyboard related problems label Apr 27, 2023
@christopherfujino christopherfujino marked this pull request as ready for review May 1, 2023 21:42
@christopherfujino christopherfujino removed the a: text input Entering text in a text field or keyboard related problems label May 4, 2023
@flutter-dashboard flutter-dashboard bot added the a: text input Entering text in a text field or keyboard related problems label May 4, 2023
.gitignore Outdated
@@ -39,6 +39,7 @@
/dev/integration_tests/**/Pods
/packages/flutter/coverage/
version
.version.json
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately if a user tries out a beta flutter version that generates this file, then switches back to stable that doesn't, it won't be gitignored.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it worth getting a hot fix into stable that just adds this into the gitignore as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zanderso what do you think? Having a dirty checkout of the framework would cause flutter upgrade to fail, so I think it would make sense to cherrypick this. If not, then we should probably land the gitignore change first, and then only land the rest of this once that's reached stable.

Copy link
Member

Choose a reason for hiding this comment

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

Can the .version.json live in a directory that's already .gitignore'd? Maybe bin/cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good idea!

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like moving into the cache directory is causing errors when trying to find the version file.

We may need to first create the version file recursively before we try to write to it now that it is in a nested directory?

@andrewkolos
Copy link
Contributor

Is this vulnerable to the staleness concerns you had with #111392?

@christopherfujino
Copy link
Contributor Author

christopherfujino commented May 6, 2023

Is this vulnerable to the staleness concerns you had with #111392?

Good question, but this is covered by https://github.com/flutter/flutter/pull/124558/files#diff-092e00109d9e1589fbc7c6de750e29a6ae512b2dd44e85d60028953561201605R91

    // if we are fetching tags, ignore cached versionFile
    if (fetchTags && versionFile.existsSync()) {
      versionFile.deleteSync();
    }

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 with minor question.

I still advise a second thorough review from @eliasyishak.

@eliasyishak
Copy link
Contributor

LGTM with minor question.

I still advise a second thorough review from @eliasyishak.

Yep still reviewing on my end as well

@christopherfujino christopherfujino force-pushed the add-version-json branch 2 times, most recently from b4b62aa to 8d4c751 Compare May 10, 2023 22:20
@github-actions github-actions bot removed the tool Affects the "flutter" command-line tool. See also t: labels. label May 25, 2023
@goderbauer goderbauer added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 1, 2023
@github-actions github-actions bot added the a: text input Entering text in a text field or keyboard related problems label Jun 10, 2023
@christopherfujino christopherfujino added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 15, 2023
@auto-submit auto-submit bot merged commit 3246808 into flutter:master Jun 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 15, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 15, 2023
flutter/flutter@95be76a...b0188cd

2023-06-15 [email protected] [web] Pass creation params to the platform view factory (flutter/flutter#128146)
2023-06-15 [email protected] [flutter_tools] cache flutter sdk version to disk (flutter/flutter#124558)
2023-06-14 [email protected] Fix inconsistently suffixed macOS flavored bundle directory (flutter/flutter#127997)
2023-06-14 [email protected] Update golden tests for material (flutter/flutter#128839)
2023-06-14 [email protected] Update getChildrenSummaryTree to handle Diagnosticable as input. (flutter/flutter#128833)
2023-06-14 [email protected] Improve the error message for non-normalized constraints (flutter/flutter#127906)
2023-06-14 [email protected] ContextAction.isEnabled needs a context (flutter/flutter#127721)
2023-06-14 [email protected] Remove temporary default case for PointerSignalKind (flutter/flutter#128900)
2023-06-14 [email protected] Respect allowlisted count of leaks. (flutter/flutter#128823)
2023-06-14 [email protected] Unpin flutter_plugin_android_lifecycle (flutter/flutter#128898)

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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
whesse added a commit that referenced this pull request Jun 19, 2023
@christopherfujino christopherfujino deleted the add-version-json branch August 2, 2023 22:26
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
fluttermirroringbot pushed a commit that referenced this pull request Aug 23, 2023
Fixes #133093

When I introduced the new, more robust version file `//flutter/bin/cache/version.json` in #124558, I changed `class FlutterVersion` into an abstract interface, implemented by `_FlutterVersionFromGit` (which is essentially the previous behavior) and `_FlutterVersionFromFile`, which merely reads the data it would have computed via git from `//flutter/bin/cache/version.json`.

While doing this, I made `_FlutterVersionFromGit.ensureVersionFile()` to be a no-op, since I assumed this would not be necessary since we already had a version file in the cache. However, this method was what was previously responsible for ensuring `//flutter/version` existed on disk. This means that if, for whatever reason, the user had `//flutter/bin/cache/flutter.version.json` present but NOT `//flutter/version`, the tool would have never created that file, and they would hit the tool crash seen in #133093.

This fixes the tool by ensuring `//flutter/version` exists regardless of if we're hydrating `FlutterVersion` from `//flutter/bin/cache/flutter.version.json` or not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems 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.

Flutter SDK should cache version to disk
5 participants