flutter/flutter

`flutter update-packages` does not update version file used by pub

goderbauer opened this issue · 0 comments

There are likely other situations where this happens, but this is how I was able to consistently reproduce the problem:

  1. Clone flutter from a fork (it's important that it's cloned from a fork because those are missing tags): git clone git@github.com:goderbauer/flutter.git
  2. Run ./bin/flutter update-packages -v inside the cloned repository and notice it fails because pub cannot determine the current version of the flutter SDK, it incorrectly thinks it is 0.0.0-unknown. This is because the clone from the fork is missing the version tags.
  3. Add the upstream repository (git remote add upstream git@github.com:flutter/flutter.git) and fetch tags (git fetch upstream)
  4. Check that you have all the tags now (git tag)
  5. Run /bin/flutter update-packages -v - unexpectedly it still fails with the same error. 🔥

Surprisingly, the problem goes away when you run flutter doctor. After that, /bin/flutter update-packages -v succeeds.

Speculation of what is going wrong: The pub tool obtains the current version of the flutter SDK from the bin/cache/flutter.version.json file, which is maintained by the flutter tool. The file is created when flutter update-packages is run for the first time in step 2 above. At this point, due to the missing version tags, the version cannot be determined and 0.0.0-unknown is written into that file. After the tags have been fetched, the flutter tool needs to update the version file when update packages is run a second time in step 5 above, but it fails to do that, causing pub to fail again because it still sees the incorrect old version in the version file.

The version file is updated when running flutter doctor, so that subsequent calls to flutter update-packages then pass.

Conclusion: The pub tool relies on the version file to be up-to-date. So, whenever the flutter tool calls out to pub it needs to make sure that the version file is up-to-date to avoid this failure mode.

cc @christopherfujino in case you have additional context.