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

Skip to content

Flutter "version" file in repo root is missing and being created then deleted by the tool on branches named master/main #142521

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

Open
Tracked by #130635
DanTup opened this issue Jan 30, 2024 · 23 comments
Assignees
Labels
P2 Important issues not at the top of the work list team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team

Comments

@DanTup
Copy link
Contributor

DanTup commented Jan 30, 2024

Steps to reproduce

I'm on the latest master (commit ccb2b44) and I noticed a number of things not working as expected in VS Code. It turns out, Dart-Code thinks I'm on Flutter version 0.0.0 and is therefore disabling all functionality that requires a specific Flutter version. This seems to be because I don't have the version file in the repo root.

I found #133097 while searching which seems to describe the same issue, however I'm on a much newer version than that (cc @christopherfujino )

Expected results

There should be a file named version in the root of the repository.

Actual results

There is no file.

Code sample

N/A

Screenshots or Video

PS C:\Dev\Google\flutter> flutter --version
Flutter 3.19.0-13.0.pre.32 • channel master • [email protected]:DanTup/flutter.git
Framework • revision ccb2b4439a (5 hours ago) • 2024-01-30 14:59:24 +0800
Engine • revision 438e9b4d7d
Tools • Dart 3.4.0 (build 3.4.0-82.0.dev) • DevTools 2.31.0
PS C:\Dev\Google\flutter> ls

    Directory: C:\Dev\Google\flutter

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          30/01/2024    11:24                .github
d----          19/12/2023    12:02                .vscode
d----          19/12/2023    12:02                bin
d----          30/01/2024    11:24                dev
d----          19/12/2023    12:02                examples
d----          01/06/2023    20:01                packages
-a---          30/01/2024    11:24         187181 .ci.yaml
-a---          01/06/2023    20:01            858 .gitattributes
-a---          19/12/2023    12:02           2932 .gitignore
-a---          19/12/2023    12:02          11615 analysis_options.yaml
-a---          30/01/2024    11:24           4714 AUTHORS
-a---          19/12/2023    12:02           2939 CODE_OF_CONDUCT.md
-a---          30/01/2024    11:24            489 CODEOWNERS
-a---          30/01/2024    11:24          11619 CONTRIBUTING.md
-a---          30/01/2024    11:24           2035 dartdoc_options.yaml
-a---          01/06/2023    20:01           1731 flutter_console.bat
-a---          01/06/2023    20:01           1544 LICENSE
-a---          01/06/2023    20:01           1124 PATENT_GRANT
-a---          30/01/2024    11:24           7055 README.md
-a---          30/01/2024    11:24          27988 TESTOWNERS

PS C:\Dev\Google\flutter>

Logs

No response

Flutter Doctor output

PS C:\Dev\Google\flutter> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel master, 3.19.0-13.0.pre.32, on Microsoft Windows [Version 10.0.22621.3007], locale en-GB)
    ! Warning: `dart` on your path resolves to C:\Dev\Tools\Dart\Stable\bin\dart.exe, which is not inside your current Flutter SDK checkout at
      C:\Dev\Google\flutter. Consider adding C:\Dev\Google\flutter\bin to the front of your path.
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.4)
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.85.2)
[✓] VS Code (version 1.86.0-insider)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.
@DanTup
Copy link
Contributor Author

DanTup commented Jan 30, 2024

This is very odd... I can repro running from source and added some prints, and it seems like it is creating the file:

PS C:\Dev\Google\flutter\packages\flutter_tools> ../../bin/dart .\bin\flutter_tools.dart --version; ls ../..
Ensuring version file (_FlutterVersionGit)!
Inside _FlutterVersionGit.ensureVersionFile
Writing 3.19.0-13.0.pre.32 to LocalFile: 'C:\Dev\Google\flutter\version' using ErrorHandlingFileSystem
Calling LocalFile("C:\Dev\Google\flutter\version").writeAsStringSync()
Calling LocalFile("C:\Dev\Google\flutter\bin\cache\flutter.version.json").writeAsStringSync()
Flutter 3.19.0-13.0.pre.32 • channel master • [email protected]:DanTup/flutter.git
Framework • revision ccb2b4439a (5 hours ago) • 2024-01-30 14:59:24 +0800
Engine • revision 438e9b4d7d
Tools • Dart 3.4.0 (build 3.4.0-82.0.dev) • DevTools 2.31.0

And nothing in the delete calls prints, so it doesn't seem like it's being deleted.

I'll try to debug a bit more shortly... This could be a big issue if widespread, because VS Code uses this version to switch quite a bit of Dart-Code functionality.

@DanTup
Copy link
Contributor Author

DanTup commented Jan 30, 2024

@christopherfujino here is the issue:

Inside _FlutterVersionGit.ensureVersionFile
Writing 3.19.0-13.0.pre.32 to LocalFile: 'C:\Dev\Google\flutter\version' using ErrorHandlingFileSystem
Calling LocalFile("C:\Dev\Google\flutter\version").writeAsStringSync()
Exists now? true
Calling LocalFile("C:\Dev\Google\flutter\bin\cache\flutter.version.json").writeAsStringSync()
Exists now? true
Deleting the new version file!!!!!!
Deleting the legacy version file!!!!!!

The files are being deleted by:

legacyVersionFile.deleteSync();

Stack trace is like:

#0      new FlutterVersion (package:flutter_tools/src/version.dart:111:26)
#1      FlutterVersion.fetchTagsAndGetVersion (package:flutter_tools/src/version.dart:178:12)
#2      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:338:65)
<asynchronous suspension>
#3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#4      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:294:5)

It's created here on line 311 and then deleted because of the call on line 338:

image

Doesn't seem to affect beta, but I haven't yet figured out why, since most of the code seems the same.

@DanTup
Copy link
Contributor Author

DanTup commented Jan 30, 2024

Ok, the reason this doesn't happen on beta is because of this early exit, which prevents the constructor running that deletes the file:

if (channel != 'master' && channel != 'main') {
return this;
}

So the issue is isolated to branches named master/main.

@DanTup DanTup changed the title Flutter "version" file in repo root is missing and not being created by the tool Flutter "version" file in repo root is missing and being created then deleted by the tool on branches named master/main Jan 30, 2024
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Jan 30, 2024
@darshankawar
Copy link
Member

Thanks for the detailed report and analysis. Labeling this for tracking.

@darshankawar darshankawar added tool Affects the "flutter" command-line tool. See also t: labels. team-tool Owned by Flutter Tool team and removed in triage Presently being triaged by the triage team labels Jan 30, 2024
@eliasyishak
Copy link
Contributor

@christopherfujino leaving to you for prioritizing

@DanTup
Copy link
Contributor Author

DanTup commented May 8, 2024

Not sure if it's the same thing, but I just noticed that the GitHub actions are often failing the coverage step because the Flutter version is reported as 0.0.0-unknown:

image

Example: https://github.com/flutter/flutter/actions/runs/8999603670/job/24722091985

@christopherfujino
Copy link
Contributor

Not sure if it's the same thing, but I just noticed that the GitHub actions are often failing the coverage step because the Flutter version is reported as 0.0.0-unknown:

image

Example: https://github.com/flutter/flutter/actions/runs/8999603670/job/24722091985

TIL we try to upload coverage from actions

@DanTup
Copy link
Contributor Author

DanTup commented Aug 21, 2024

This came up again in Dart-Code/Dart-Code#5226, where we were using old versions of DevTools page IDs because we thought we were on an old version of the Flutter SDK.

@christopherfujino @andrewkolos does anyone know why we have a difference in this path for master/main? If we remove the if statement quoted above (so that master/main did the same as other branches, and never triggered the delete), would anything break? 🤔

@christopherfujino
Copy link
Contributor

@christopherfujino @andrewkolos does anyone know why we have a difference in this path for master/main? If we remove the if statement quoted above (so that master/main did the same as other branches, and never triggered the delete), would anything break? 🤔

We have a difference on master/main because what we report as the version changes as new tags are added upstream. If we removed the if statement, once we cache the version, this would remain as long as you're on the same commit, even if we publish a beta from an OLDER commit, and our version should now reflect that it is AFTER the beta.

@DanTup
Copy link
Contributor Author

DanTup commented Aug 21, 2024

Ah, gotcha. Should there be an ensureVersionFile call somewhere after that fetchTagsAndGetVersions() then? Oddly, I can't see where fetchTagsAndGetVersions() (or the constructor it calls) actually fetches any tags (seems like it just calls gitLog 🤔).

@DanTup
Copy link
Contributor Author

DanTup commented Aug 22, 2024

Some additional info I just noticed:

  • running flutter doctor results in the file being deleted and not replaced
  • running flutter --version results in the file being deleted and not replaced
  • running flutter --help results in the file remaining (or not being deleted)

Seems like Dart-Code is triggering this sometimes when you have a Flutter SDK with no Dart SDK because we force it to initialize by calling flutter doctor (and showing the output to the user). If we call flutter --help afterwards, then we'll have a good version number, but it is slightly weird.

DanTup added a commit to Dart-Code/Dart-Code that referenced this issue Aug 22, 2024
… the version file

This may help avoid flutter/flutter#142521 until there's a better fix.

Also fixes #5226.
@christopherfujino
Copy link
Contributor

Some additional info I just noticed:

  • running flutter doctor results in the file being deleted and not replaced
  • running flutter --version results in the file being deleted and not replaced
  • running flutter --help results in the file remaining (or not being deleted)

Seems like Dart-Code is triggering this sometimes when you have a Flutter SDK with no Dart SDK because we force it to initialize by calling flutter doctor (and showing the output to the user). If we call flutter --help afterwards, then we'll have a good version number, but it is slightly weird.

Let me carve out some time today to dig in a little bit. I'll take me a while to get back up to speed on all the convoluted logic here (I remember thinking I could implement this in a few days, but it actually took me weeks, I've already had to fix a bad bug, and clearly there's another one).

@DanTup
Copy link
Contributor Author

DanTup commented Aug 22, 2024

Thanks! I implemented a few tweaks in Dart-Code (such as calling flutter --help directly after flutter doctor in the case where we force initialization) which I think will reduce the chance of hitting this, but it's pretty hacky and it'd be nice to remove them if it's not a ton of work here.

@christopherfujino
Copy link
Contributor

christopherfujino commented Aug 22, 2024

@DanTup Ahh, as I read this issue carefully, am I correct in understanding that dart-code is parsing $FLUTTER_ROOT/version in order to conditionally disable some features? If that is the case, the fix here is migrating to use $FLUTTER_ROOT/bin/cache/flutter.version.json.

I (mistakenly) thought that the only tool that was reading this was pub, which was migrated here: dart-lang/pub#4113.

Does devtools also parse this file @kenzieschmoll ?

@DanTup
Copy link
Contributor Author

DanTup commented Aug 24, 2024

Ah, that sounds reasonable. Currently we're just reading the version the same way for Dart and Flutter (Dart also has a version), but reading the JSON if it is there should work too. If it's only the "legacy" file being removed, this will remove the need for my other workaround too. I've filed Dart-Code/Dart-Code#5231 about this.

DanTup added a commit to Dart-Code/Dart-Code that referenced this issue Aug 27, 2024
@DanTup
Copy link
Contributor Author

DanTup commented Aug 27, 2024

I've switched Dart-Code to reading the new JSON file first and just using the legacy version file if it fails to find (or parse a version from) the JSON file.

As such, I/Dart-Code doesn't care so much about this behaviour now - if this version file is considered legacy and shouldn't be used, this issue could be closed.

(although it may also be worth checking with @helin24 / @jwren whether IntelliJ uses the original file)

@DanTup
Copy link
Contributor Author

DanTup commented Dec 17, 2024

Ahh, as I read this issue carefully, am I correct in understanding that dart-code is parsing $FLUTTER_ROOT/version in order to conditionally disable some features? If that is the case, the fix here is migrating to use $FLUTTER_ROOT/bin/cache/flutter.version.json.

Today I noticed that this file is also not present in my Flutter checkout. Combined with the version file missing, that means Dart-Code is currently treated the Flutter version as unknown (and as 999.999 for all version checks).

If I run an invalid command like flutter foo, the file appears (as does the legacy one), but if I then run flutter doctor, the files both get deleted again.

So it seems that migrating to the new version file hasn't actually solved the problem.

@kenzieschmoll
Copy link
Member

I (mistakenly) thought that the only tool that was reading this was pub, which was migrated here: dart-lang/pub#4113.

Does devtools also parse this file @kenzieschmoll ?

Late on the response here... but this is the only other place I am aware of. It looks like it is using the correct file path:
https://github.com/dart-lang/sdk/blob/master/pkg/dtd_impl/lib/src/service/unified_analytics_service.dart/#L158

@andrewkolos andrewkolos removed their assignment Feb 4, 2025
@bkonyi
Copy link
Contributor

bkonyi commented Feb 11, 2025

I'm assuming this is still an issue @DanTup?

@bkonyi bkonyi self-assigned this Feb 11, 2025
@bkonyi bkonyi added the triaged-tool Triaged by Flutter Tool team label Feb 11, 2025
@DanTup
Copy link
Contributor Author

DanTup commented Feb 12, 2025

@bkonyi it is. Here you can see both the legacy version file and the flutter.version.json file disappear when I run flutter doctor (and both come back when I run flutter help):

flutterversion.mp4

@matanlurey
Copy link
Contributor

@bkonyi Any progress? I think this is possibly also the cause of #157627.

@bkonyi
Copy link
Contributor

bkonyi commented Feb 13, 2025

Any progress? I think this is possibly also the cause of #157627.

Nope, I haven't had a chance to look into this and probably won't for a while. I'm the only one on the tools team at the moment so I don't have cycles to investigate, I just didn't want this triaged issue to disappear into the void by leaving it unassigned.

@bkonyi
Copy link
Contributor

bkonyi commented May 2, 2025

I had some time to look into this, and it looks like we're deleting the version files when we [create a FlutterVersion instance with fetchTags == true:

    // if we are fetching tags, ignore cached versionFile
    if (fetchTags && versionFile.existsSync()) {
      versionFile.deleteSync();
      final File legacyVersionFile = fs.file(fs.path.join(flutterRoot, 'version'));
      if (legacyVersionFile.existsSync()) {
        legacyVersionFile.deleteSync();
      }
    }

AFAICT, there's not a follow up call to FlutterVersion.ensureVersionFile() when we take that path when there probably should be. I'll pull together a quick PR to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Important issues not at the top of the work list team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team
Projects
None yet
Development

No branches or pull requests

8 participants