Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6486 +/- ##
==========================================
- Coverage 81.97% 81.94% -0.03%
==========================================
Files 173 173
Lines 14034 14069 +35
Branches 2879 2889 +10
==========================================
+ Hits 11504 11529 +25
- Misses 2064 2072 +8
- Partials 466 468 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cdb2288 to
ae661b2
Compare
ae661b2 to
b3c6149
Compare
DanTupBot
left a comment
There was a problem hiding this comment.
Overall this is a clean, well-tested implementation of the bin/dart --version approach agreed in #6455, with clear handling of version-file invalidation, spawn errors, and signal termination.
This needs work for two small edge cases in src/extension/sdk/flutter.ts (a Windows bin\mingit\cmd regression in dart.bat, and disposing/checking the shared cancellationToken across the fallback call), plus one minor test-helper deduplication suggestion.
|
|
||
| const dartScript = path.join(target.flutterSdkPath, flutterDartPath); | ||
| const flutterScript = path.join(target.flutterSdkPath, flutterPath); | ||
| if (existsAndIsFileSync(dartScript) && hasFlutterVersion(target.flutterSdkPath)) { |
There was a problem hiding this comment.
On Windows, bin/flutter.bat adds Flutter's bundled mingit (%FLUTTER_ROOT%\bin\mingit\cmd) to PATH before calling bin/internal/shared.bat, whereas bin/dart.bat omits that block.
If a Windows user relies on bundled mingit without git on their system PATH, bin/dart.bat --version will fail inside shared.bat -> update_engine_version.ps1 (git -C ... ls-files) with exit code 1, showing a Flutter initialization error notification and never falling back to flutter.bat --suppress-analytics --help.
Skipping the bin/dart.bat fast-path when bin/mingit/cmd exists on Windows (e.g., !(isWin && existsAndIsDirectorySync(path.join(target.flutterSdkPath, "bin", "mingit", "cmd")))) would avoid regressing those setups.
There was a problem hiding this comment.
Intentionally not adding a workaround for bin/mingit/cmd here — the missing PATH entry in bin/dart.bat is being fixed upstream in Flutter, and very few users rely on the bundled MinGit archive without Git installed.
There was a problem hiding this comment.
This is being fixed in Flutter at flutter/flutter#197390. We don't need to add workarounds for older SDK versions, as the number of users using the archive, on Windows, with no Git is likely very small.
| */ | ||
| function runFlutterHelp(logger: Logger, flutterScript: string, cancellationToken: CancellationToken): Promise<void> { | ||
| const proc = safeToolSpawn(undefined, flutterScript, ["--suppress-analytics", "--help"]); | ||
| function runFlutterInitCommand(logger: Logger, script: string, args: string[], cancellationToken: CancellationToken): Promise<void> { |
There was a problem hiding this comment.
Now that initializeFlutter can call runFlutterInitCommand twice with the same cancellationToken (when falling back from dart --version to flutter --suppress-analytics --help), two cancellation edge cases apply:
- The
cancellationToken.onCancellationRequested(...)subscription registered below isn't disposed when the first command finishes, so cancelling during the fallback command will invoke both listeners (loggingUser canceled!twice and callingproc.kill()on the already-exited first process). Disposing the subscription when the promise settles avoids keeping stale listeners around. - If cancellation is requested right as
dart --versioncompletes (before the fallback starts),runFlutterInitCommandwill still spawn the fallback process before cancellation triggers. Checkingif (cancellationToken.isCancellationRequested)up front (or before the fallback call ininitializeFlutter) avoids spawning a second process after cancellation.
There was a problem hiding this comment.
Good catch — addressed both edge cases in commit 70b506060:
- Disposed the
cancellationToken.onCancellationRequested(...)subscription synchronously whenrunFlutterInitCommandsettles (both on success and failure). - Checked
cancellationToken.isCancellationRequestedat the start ofrunFlutterInitCommandbefore spawning (and skipped the fallback info log ininitializeFlutterif already cancelled).
Also added unit tests in src/test/dart/utils/sdk.test.ts covering both cases.
| }); | ||
|
|
||
| describe("Flutter initialization", () => { | ||
| function isolatePathEnv(): void { |
There was a problem hiding this comment.
Nit: isolatePathEnv() duplicates useIsolatedSdkSearch() in the sibling describe("Dart SDK search precedence") block above (and similar inline setup in the preceding tests). Lifting useIsolatedSdkSearch() up to describe("scanWorkspace") would let all of them share one helper.
There was a problem hiding this comment.
Lifted useIsolatedSdkSearch() up to describe("scanWorkspace") in commit 70b506060 and removed isolatePathEnv() in favor of reusing it (leaving unrelated pre-existing tests untouched to keep the PR diff focused).
DanTupBot
left a comment
There was a problem hiding this comment.
All feedback has been addressed in 70b506060 (disposing the cancellation listener on settlement, guarding against spawning the fallback after cancellation, adding targeted tests for both cases, and reusing useIsolatedSdkSearch()), and skipping a bin/mingit/cmd workaround makes sense given the upstream fix in flutter/flutter#197390.
LGTM!
Fixes #6455.
Part of #6454.
Summary
Updates
ensureFlutterInitialized()to run<flutter>/bin/dart --version(bin/dart.bat --versionon Windows) instead offlutter --suppress-analytics --helpon the warm path:bin/dartandbin/flutterrun Flutter'sbin/internal/shared.{sh,bat}lock andupdate_dart_sdkcheck before executing Dart, ensuringbin/cache/dart-sdkis up to date before spawning the analysis server without relying on brittle stamp-file parsing in Dart-Code.flutter_tools.snapshot(~81 MB) on every startup cuts initialization time significantly.shared.{sh,bat}deleteversionandbin/cache/flutter.version.jsonon cache invalidation whilebin/dart --versionnever launchesflutter_toolsto regenerateflutter.version.json, we checkgetSdkVersion()(withnullLogger) before and afterbin/dart --versionand fall back toflutter --suppress-analytics --helpwhen no valid Flutter version can be read.runFlutterInitCommand()handles process"error"events and non-zero/signal exits (code !== 0) using a guardedsettledfailure path so spawn failures (e.g.EACCES) or signals cannot hang activation or register as success, disposes the cancellation listener when each command settles, and rejects before spawning if cancellation was already requested.Exact Command Scenarios
bin/cache/flutter.version.jsonorversion)bin/dart --version(orbin/dart.bat --version)flutter_tools.snapshot.flutter upgradebin/dart --version(orbin/dart.bat --version)flutter upgradealready regeneratedflutter.version.jsonandflutter_tools.snapshot, so no fallback runs.flutter.version.jsonwith a valid legacyversionfilebin/dart --version(orbin/dart.bat --version)getSdkVersion()falls back to the legacyversionfile, keeping the fast path without regenerating JSON.git clone, missing version files, or corruptedflutter.version.jsonwith no legacyversionfileflutter --suppress-analytics --helphasFlutterVersion()returnsfalseupfront, sobin/dart --versionis skipped andflutterruns once to updatedart-sdkand generateflutter.version.json.git pull/git checkoutwithout runningflutterfirst (stale version file still on disk)bin/dart --version(orbin/dart.bat --version)2.
flutter --suppress-analytics --helpbin/dart --versionupdatesbin/cache/dart-sdkandshared.{sh,bat}deletesversionandbin/cache/flutter.version.json; detecting the missing version file immediately triggersflutter --suppress-analytics --helpto regenerateflutter.version.jsonbeforescanWorkspace()readsFlutterCapabilities.sdkInitScript(e.g. Snap / Hermit before SDK folder exists)<initScript> --suppress-analytics --helpinitScriptdirectly.bin/dart/bin/dart.batflutter --suppress-analytics --helpbin/dartis not on disk.bin/dart --version"error", non-zero exit, signal termination (code === null), or 5s progress cancel; logs error, shows notification with Show Log, does not spawn fallbackflutter --help, and allows workspace scanning to continue.Benchmarks
Windows (
run 1+ 10 interleaved warm runs mirroring Dart-Code's.batspawning):bin\flutter.bat --suppress-analytics --help: run 11405.4 ms, warm median1236.4 msbin\dart.bat --version: run 1559.0 ms, warm median551.4 ms(~685 ms / 55.4% saved on warm runs, ~846 ms saved on run 1)bin\cache\dart-sdk\bin\dart.exe --version(noshared.bat): warm median8.4 msLinux (isolated clone of Flutter 3.50.1, 5 warm runs):
bin/flutter --suppress-analytics --help: median136.8 msbin/dart --version: median47.9 msVerification
bin/cache/dart-sdk,bin/dart --versiondownloads and restoresdart-sdk, and a subsequentflutter --suppress-analytics --helpleaves the restoreddart-sdkdirectory/binary inodes untouched.npm run lint,npm run build,npm run build-tests.BOT=dart npm run test src/test/dart/utils/sdk.test.ts(59 passing, covering warm JSON/legacy version files, corrupted JSON with and without legacyversion, missing version files, cache invalidation fallback, missingbin/dart, non-zero exit / spawn error / signal termination without fallback, cancellation listener disposal across fallback, and skipping fallback spawn if already cancelled).BOT=flutter npm run test src/test/flutter/flutter_daemon.test.ts(11 passing, activating against the real local Flutter SDK).