Skip to content

Flutter SDK installed via package managers like Hermit are not detected/initialized correctly #3961

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

Closed
alecthomas opened this issue May 14, 2022 · 17 comments
Labels
in flutter Relates to running Flutter apps is bug
Milestone

Comments

@alecthomas
Copy link

alecthomas commented May 14, 2022

Describe the bug

The VSCode extensions are unable to find Flutter or Dart (see attached log below) if ./bin/dart or ./bin/flutter exist, even though FLUTTER_ROOT is set correctly. I would expect that with FLUTTER_ROOT explicitly set, it would be used by the extension. The flutter/dart command-line tools work perfectly FWIW.

Flutter is installed in /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0.
FLUTTER_ROOT is set export FLUTTER_ROOT=/Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0

I have a shell script wrapper around dart/flutter located in ~/Projects/flutter/bin (basically #!/bin/bash\nexec /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/$cmd). On the command line this works perfectly (screenshot below), but the VSCode extension preferences the wrapper scripts over FLUTTER_ROOT, resulting in it being unable to find Dart or the Flutter SDK.

I understand that this is not a common setup, but we use a tool called Hermit for managing hermetic environments which uses wrapper scripts to bootstrap tools, including Flutter.

To Reproduce

Install Flutter SDK into some location. Set FLUTTER_ROOT to that location then:

mkdir -p ~/test/bin
cd ~/test
echo 'exec $FLUTTER_ROOT/bin/flutter "$@"' > bin/flutter
echo 'exec $FLUTTER_ROOT/bin/dart "$@"' > bin/dart
chmod +x bin/{flutter,dart}
export PATH="$PWD/bin:$PATH"

flutter doctor
flutter create .
flutter run

The above all works.

Next do the following:

code .

This results in the extension reinitialising and failing with:
image

Expected behavior

I would expect that with FLUTTER_ROOT explicitly set, it would be used by the extension.

Screenshots

Command line working fine:
image

Extension log section
[3:16:59 pm] [General] [Info] Searching for flutter
[3:16:59 pm] [General] [Info]     Looking for flutter in:
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/.flutter
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/.flutter/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/vendor/flutter
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/vendor/flutter/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info]         /Users/aat/flutter-sdk
[3:16:59 pm] [General] [Info]         /Users/aat/flutter-sdk/bin
[3:16:59 pm] [General] [Info]         /google/flutter
[3:16:59 pm] [General] [Info]         /google/flutter/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info]         /Users/aat/bin
[3:16:59 pm] [General] [Info]         /opt/homebrew/bin
[3:16:59 pm] [General] [Info]         /opt/homebrew/bin
[3:16:59 pm] [General] [Info]         /opt/homebrew/sbin
[3:16:59 pm] [General] [Info]         /usr/local/bin
[3:16:59 pm] [General] [Info]         /usr/bin
[3:16:59 pm] [General] [Info]         /bin
[3:16:59 pm] [General] [Info]         /usr/sbin
[3:16:59 pm] [General] [Info]         /sbin
[3:16:59 pm] [General] [Info]         /opt/local/bin
[3:16:59 pm] [General] [Info]         /usr/local/munki
[3:16:59 pm] [General] [Info]         /usr/local/munki/bin
[3:16:59 pm] [General] [Info]         /Applications/kitty.app/Contents/MacOS
[3:16:59 pm] [General] [Info]         /Applications/kitty.app/Contents/MacOS/bin
[3:16:59 pm] [General] [Info]         /opt/homebrew/opt/fzf/bin
[3:16:59 pm] [General] [Info]     Found at:
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info] Following symlink: /Users/aat/Projects/flutter/bin/flutter ==> /Users/aat/Projects/flutter/bin/hermit
[3:16:59 pm] [General] [Info] Following symlink: /Users/aat/Projects/flutter/bin/flutter ==> /Users/aat/Projects/flutter/bin/hermit
[3:16:59 pm] [General] [Info]     Candidate paths to be post-filtered:
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info]         /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info]     Found at /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info]     Returning SDK path /Users/aat/Projects/flutter for flutter
[3:16:59 pm] [General] [Info] Flutter is not initialized, running 'flutter doctor' to force...
[3:16:59 pm] [General] [Info] (PROC 23519) Logging data for process...
[3:16:59 pm] [FlutterDaemon] [Info] Process /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/flutter terminated! 0, null
[3:17:01 pm] [General] [Info] (PROC 23519) [✓] Flutter (Channel stable, 3.0.0, on macOS 12.3.1 21E258 darwin-arm (Rosetta), locale en-AU)
[3:17:01 pm] [General] [Info] (PROC 23519)     • Flutter version 3.0.0 at /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:17:01 pm] [General] [Info] (PROC 23519)     • Upstream repository https://github.com/flutter/flutter.git
[3:17:01 pm] [General] [Info] (PROC 23519)     • Framework revision ee4e09cce0 (4 days ago), 2022-05-09 16:45:18 -0700
[3:17:01 pm] [General] [Info] (PROC 23519)     • Engine revision d1b9a6938a
[3:17:01 pm] [General] [Info] (PROC 23519)     • Dart version 2.17.0
[3:17:01 pm] [General] [Info] (PROC 23519)     • DevTools version 2.12.2
[3:17:01 pm] [General] [Info] (PROC 23519)
[3:17:01 pm] [General] [Info] (PROC 23519) [✗] Android toolchain - develop for Android devices
[3:17:01 pm] [General] [Info] (PROC 23519)     ✗ Unable to locate Android SDK.
[3:17:01 pm] [General] [Info] (PROC 23519)       Install Android Studio from: https://developer.android.com/studio/index.html
[3:17:01 pm] [General] [Info] (PROC 23519)       On first launch it will assist you in installing the Android SDK components.
[3:17:01 pm] [General] [Info] (PROC 23519)       (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
[3:17:01 pm] [General] [Info] (PROC 23519)       If the Android SDK has been installed to a custom location, please use
[3:17:01 pm] [General] [Info] (PROC 23519)       `flutter config --android-sdk` to update to that location.
[3:17:01 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[3:17:02 pm] [General] [Info] (PROC 23519)     • Xcode at /Applications/Xcode.app/Contents/Developer
[3:17:02 pm] [General] [Info] (PROC 23519)     • CocoaPods version 1.11.3
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] Chrome - develop for the web
[3:17:02 pm] [General] [Info] (PROC 23519)     • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [!] Android Studio (not installed)
[3:17:02 pm] [General] [Info] (PROC 23519)     • Android Studio not found; download from https://developer.android.com/studio/index.html
[3:17:02 pm] [General] [Info] (PROC 23519)       (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] IntelliJ IDEA Community Edition (version 2022.1)
[3:17:02 pm] [General] [Info] (PROC 23519)     • IntelliJ at /Users/aat/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5080.210/IntelliJ IDEA CE.app
[3:17:02 pm] [General] [Info] (PROC 23519)     • Flutter plugin can be installed from:
[3:17:02 pm] [General] [Info] (PROC 23519)       🔨 https://plugins.jetbrains.com/plugin/9212-flutter
[3:17:02 pm] [General] [Info] (PROC 23519)     • Dart plugin can be installed from:
[3:17:02 pm] [General] [Info] (PROC 23519)       🔨 https://plugins.jetbrains.com/plugin/6351-dart
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] VS Code (version 1.67.1)
[3:17:02 pm] [General] [Info] (PROC 23519)     • VS Code at /Applications/Visual Studio Code.app/Contents
[3:17:02 pm] [General] [Info] (PROC 23519)     • Flutter extension version 3.40.0
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:04 pm] [General] [Info] (PROC 23519) [✓] Connected device (2 available)
[3:17:04 pm] [General] [Info] (PROC 23519)     • macOS (desktop) • macos  • darwin-arm64   • macOS 12.3.1 21E258 darwin-arm (Rosetta)
    • Chrome (web)    • chrome • web-javascript • Google Chrome 101.0.4951.64
[3:17:04 pm] [General] [Info] (PROC 23519) [✓] HTTP Host Availability
[3:17:04 pm] [General] [Info] (PROC 23519)     • All required HTTP hosts are available
[3:17:04 pm] [General] [Info] (PROC 23519) ! Doctor found issues in 2 categories.
[3:17:04 pm] [General] [Info] (PROC 23519) exited (0, null)
[3:17:04 pm] [General] [Info] (PROC 23519) closed (0, null)
[3:17:04 pm] [General] [Info] Flutter initialized!
[3:17:04 pm] [General] [Info] Searching for dart
[3:17:04 pm] [General] [Info]     Looking for dart in:
[3:17:04 pm] [General] [Info]         /Users/aat/Projects/flutter/bin/cache/dart-sdk
[3:17:04 pm] [General] [Info]         /Users/aat/Projects/flutter/bin/cache/dart-sdk/bin
[3:17:04 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:17:04 pm] [General] [Info]         /Users/aat/Projects/flutter/bin
[3:17:04 pm] [General] [Info]         /Users/aat/bin
[3:17:04 pm] [General] [Info]         /opt/homebrew/bin
[3:17:04 pm] [General] [Info]         /opt/homebrew/bin
[3:17:04 pm] [General] [Info]         /opt/homebrew/sbin
[3:17:04 pm] [General] [Info]         /usr/local/bin
[3:17:04 pm] [General] [Info]         /usr/bin
[3:17:04 pm] [General] [Info]         /bin
[3:17:04 pm] [General] [Info]         /usr/sbin
[3:17:04 pm] [General] [Info]         /sbin
[3:17:04 pm] [General] [Info]         /opt/local/bin
[3:17:04 pm] [General] [Info]         /usr/local/munki
[3:17:04 pm] [General] [Info]         /usr/local/munki/bin
[3:17:04 pm] [General] [Info]         /Applications/kitty.app/Contents/MacOS
[3:17:04 pm] [General] [Info]         /Applications/kitty.app/Contents/MacOS/bin
[3:17:04 pm] [General] [Info]         /opt/homebrew/opt/fzf/bin
[3:17:04 pm] [General] [Info]         /Users/aat/Projects/flutter/bin/cache/dart-sdk
[3:17:04 pm] [General] [Info]         /Users/aat/Projects/flutter/bin/cache/dart-sdk/bin
[3:17:04 pm] [General] [Info]     Found at:
[3:17:04 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:17:04 pm] [General] [Info]         /Users/aat/Projects/flutter/bin
[3:17:04 pm] [General] [Info] Following symlink: /Users/aat/Projects/flutter/bin/dart ==> /Users/aat/Projects/flutter/bin/hermit
[3:17:04 pm] [General] [Info]     Candidate paths to be post-filtered:
[3:17:04 pm] [General] [Info]         /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:17:04 pm] [General] [Info]         /Users/aat/Projects/flutter
[3:17:04 pm] [General] [Info]     Returning SDK path undefined for dart
[3:17:04 pm] [General] [Info] Done!

Please complete the following information:

  • Operating System and version: 12.3.1 (21E258)
  • VS Code version: 1.67.1 (Universal)
  • Dart extension version: v3.40.0
  • Dart/Flutter SDK version: 3.0.0
@alecthomas
Copy link
Author

Ah I do see that the search order seems to be deliberate, which seems a bit odd to me, but either way I think that if flutter and dart work, then the VSCode extension should work too. But maybe it has no way of finding the real SDK location?

@DanTup
Copy link
Member

DanTup commented May 14, 2022

VS Code needs to locate a real SDK because it needs the path for some of its functionality (for example when debugging, we need to be able to translate dart:xxx URIs into paths to the source files inside your SDK folder). If your shell scripts were instead symlinks to the real SDK binaries, I would expect the SDK is found (because we resolve symlinks during the search).

Some questions:

  1. What's the purpose of the shell scripts you have wrapping the SDK?
  2. Could they be symlinks?
  3. Is it required that VS Code goes through them for other things to work?
  4. If it is required, is it required for every run, or would using the wrapper script only for the very first invocation of flutter and then using the real SDK binary directly work?

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label May 14, 2022
@alecthomas
Copy link
Author

Ah okay, that makes complete sense.

  1. The scripts are installed by Hermit, which is a bit like asdf.
  2. Unfortunately not.
  3. It is yes, the scripts will self-bootstrap Hermit, and auto-install the associated package (in this case Flutter).
  4. Yes this would work! On first invocation Hermit will install flutter into $CACHEDIR/hermit/pkg/flutter-3.0.0.

Interestingly the VSCode extension log does know about Hermit's installed Flutter location.

FTR this is Hermit's flutter package. It doesn't currently work out of the box because flutter requires its installation location to be mutable, which is slightly unfortunate, but I've been doing this manually, and I'm also thinking of adding a mutable = true option to Hermit to support this.

Within the aforementioned constraints of Hermit, I'd be interested in figuring out a way to make VSCode work with it. Let me know if there's anything I can do to help.

@DanTup
Copy link
Member

DanTup commented May 14, 2022

The scripts are installed by Hermit, which is a bit like asdf.

  1. I'm not familiar with either. Is it Hermit that is creating ~/Projects/flutter/bin? (Or more specifically, if other users are using Hermit, would their wrapped script be at this exact location too, or is this a custom script you have created?)

  2. Which of these paths do you have on PATH? Would it be reasonable/valid to have both of these (in this order) on PATH?

  • ~/Projects/flutter/bin
  • /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0

This setup doesn't sound completely different from Snap on Ubuntu. After installing the snap package there is a flutter binary that is not part of a valid SDK. If we fail to find an SDK but we do find that binary, we invoke the binary (and wait for it to complete, which can be slow if it's downloading Flutter) and then re-search for the SDK (and find the real SDK).

I wonder if we could add some setting (or env var) that would allow you to configure a path to a "flutter initialisation script" that we could invoke if no SDK is found as part of initialisation.

  1. Would that work for you? (You'd need to ensure that setting or env var can be set for any users that would need this to work).

@alecthomas
Copy link
Author

I'm not familiar with either. Is it Hermit that is creating ~/Projects/flutter/bin? (Or more specifically, if other users are using Hermit, would their wrapped script be at this exact location too, or is this a custom script you have created?)

The bin directory is created by hermit init . and is typically checked into a repository to make the development tooling required completely by each project self-contained. You can see an example here.

Which of these paths do you have on PATH? Would it be reasonable/valid to have both of these (in this order) on PATH?
~/Projects/flutter/bin
/Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0

It's typically just the former, but I could add the latter for the Flutter package. Actually let me try that now, it might Just Work.

I wonder if we could add some setting (or env var) that would allow you to configure a path to a "flutter initialisation script" that we could invoke if no SDK is found as part of initialisation.

That would absolutely work, thank you. In fact I tried to do this with the Hermit package by setting FLUTTER_ROOT, so doing it with a different envar will be fine.

@alecthomas
Copy link
Author

I tried adding the real SDK to the path but it still fails, which makes sense given that it always prioritises the project directory.

[10:06:26 pm] [General] [Info] Environment PATH:
[10:06:26 pm] [General] [Info]     /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[10:06:26 pm] [General] [Info]     /Users/aat/Projects/startup_namer/bin
[10:06:26 pm] [General] [Info]     /Users/aat/bin
...
[10:06:26 pm] [General] [Info]     Found at /Users/aat/Projects/startup_namer
[10:06:26 pm] [General] [Info]     Returning SDK path /Users/aat/Projects/startup_namer for flutter

@alecthomas
Copy link
Author

If we fail to find an SDK but we do find that binary, we invoke the binary (and wait for it to complete, which can be slow if it's downloading Flutter) and then re-search for the SDK (and find the real SDK).

Interesting, have you special-cased something for Snap?

@DanTup
Copy link
Member

DanTup commented May 16, 2022

I'm not familiar with either. Is it Hermit that is creating ~/Projects/flutter/bin? (Or more specifically, if other users are using Hermit, would their wrapped script be at this exact location too, or is this a custom script you have created?)

The bin directory is created by hermit init . and is typically checked into a repository

I'm a little confused.. I thought ~/Projects/flutter was outside of your project/repo (eg. a central location for all), but now I'm not so sure. If we added some env var (say FLUTTER_INIT_SCRIPT) that would allow VS Code to find and run that script if it didn't find an SDK, what would hat path be set to? (considering it presumably needs to be a single value for the whole system, and not per-project)

I tried adding the real SDK to the path but it still fails, which makes sense given that it always prioritises the project directory.

I'm not sure I understand what you tested here - what is /Users/aat/Projects/startup_namer? I thought the issue was that the Flutter SDK was not being located when not initialised, but this suggests you have two SDKs and the wrong one is being selected.

Interesting, have you special-cased something for Snap?

Yep, although it's not something I really want to extend in a non-generic way. I'd prefer to come up with something general that could be supported by many package managers without having each of them specifically coded here.

@alecthomas
Copy link
Author

The only SDK present is at /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0. ~/Projects/startup_namer and ~/Projects/flutter` are both sample Flutter project using Hermit.

If we added some env var (say FLUTTER_INIT_SCRIPT) that would allow VS Code to find and run that script if it didn't find an SDK

The only thing that concerns me here is that it's a fallback after the fairly slow failure to search for Flutter. Personally I would prefer an environment variable that specifies exactly where Flutter is, and that be used immediately. Perhaps FLUTTER_SDK_ROOT or something.. I'm not sure.

@DanTup
Copy link
Member

DanTup commented May 16, 2022

The only SDK present is at /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0.
~/Projects/startup_namer and ~/Projects/flutter are both sample Flutter project using Hermit

Are you able to post (or send to me at logs@dartcode.org) the full log that includes the search? We should not return a folder like ~/Projects/startup_namer as the SDK if it is not a valid SDK.

The only thing that concerns me here is that it's a fallback after the fairly slow failure to search for Flutter.

My intention for FLUTTER_INIT_SCRIPT was something that would only ever occur when Flutter has not been bootstrapped:

If Flutter is not bootstrapped:

  • searching PATH finds no valid SDK
  • FLUTTER_INIT_SCRIPT is defined, so it is run
  • search is re-run and finds the Flutter SDK that's now been set up (and is in PATH)

If Flutter is already bootstrapped:

  • searching PATH finds Flutter

I'm happy for FLUTTER_SDK_ROOT to be included in the search (if it's not already), but I don't think that solves the problem here. We need to be a real SDK (or a symlink to) in order for things to work, we can't point at wrapper scripts and not know where an SDK is.

@alecthomas
Copy link
Author

alecthomas commented May 16, 2022

Are you able to post (or send to me at logs@dartcode.org) the full log that includes the search? We should not return a folder like ~/Projects/startup_namer as the SDK if it is not a valid SDK.

I included the full log for ~/Projects/flutter in a collapsed section in the original ticket body. The only thing in ~/Projects/flutter/bin is theflutter and dart shell wrappers, no other Flutter-related files.

@alecthomas
Copy link
Author

alecthomas commented May 16, 2022

I've subsequently deleted ~/Projects/flutter but here's what's in startup_namer and the actual SDK root:

🐚 ~/Projects/startup_namer $ ls -l bin                                                                                                                    master
total 32
-rw-------  1 aat  staff  270 14 May 19:56 README.hermit.md
-rwx------  1 aat  staff  562 14 May 19:56 activate-hermit*
lrwxr-xr-x  1 aat  staff   18 14 May 16:16 dart@ -> .flutter-3.0.0.pkg
lrwxr-xr-x  1 aat  staff   18 14 May 16:16 flutter@ -> .flutter-3.0.0.pkg
-rwx------  1 aat  staff  804 14 May 19:56 hermit*
-rw-------  1 aat  staff   87 14 May 22:04 hermit.hcl
🐚 ~/Projects/startup_namer $ ls -l ~/Library/Caches/hermit/pkg/flutter-3.0.0                                                                              master
total 168
-rw-------   1 aat  staff   3606 12 May 04:38 AUTHORS
-rw-------   1 aat  staff    732 12 May 04:38 CODEOWNERS
-rw-------   1 aat  staff   2924 12 May 04:38 CODE_OF_CONDUCT.md
-rw-------   1 aat  staff   5764 12 May 04:38 CONTRIBUTING.md
-rw-------   1 aat  staff   1519 12 May 04:38 LICENSE
-rw-------   1 aat  staff   1107 12 May 04:38 PATENT_GRANT
-rw-------   1 aat  staff   5875 12 May 04:38 README.md
-rw-------   1 aat  staff  18786 12 May 04:38 TESTOWNERS
-rw-------   1 aat  staff  11722 12 May 04:38 analysis_options.yaml
drwx------   8 aat  staff    256 12 May 21:20 bin/
-rw-------   1 aat  staff   1829 12 May 04:38 dartdoc_options.yaml
drwx------  19 aat  staff    608 12 May 21:20 dev/
drwx------  16 aat  staff    512 12 May 21:20 examples/
-rw-------   1 aat  staff   1731 12 May 04:38 flutter_console.bat
-rw-------   1 aat  staff    296 12 May 04:38 flutter_root.iml
drwx------  13 aat  staff    416 12 May 21:20 packages/
-rw-------   1 aat  staff      5 15 May 18:57 version

@DanTup
Copy link
Member

DanTup commented May 16, 2022

Sorry, I missed the original log. I think I see what's happening

  • We find what looks like a Flutter binary at /Users/aat/Projects/flutter/bin/flutter
  • We see that it is a symlink, so we follow it (this is to catch cases where something like /usr/bin/flutter is a symlink to the real SDK location, which we need)
  • The symlink actually just points at hermit in the same directory (/Users/aat/Projects/flutter/bin/hermit)
  • We trim the bin/executable off the end to get /Users/aat/Projects/flutter and then ask "Does this look like a Flutter SDK?" and because it has a flutter binary in it, it does, so we return it as the SDK (but it's not)

So the problem here is that when we followed the symlink, we didn't realise that it didn't point at a flutter binary but hermit. This is actually a lot like snap (where it points at a snap binary) so rather than detecting snap with a full path, I'm going to try detecting just the binary name.

I'll publish a pre-release build you can test with once the changes are made to confirm it all works (no promises, but hopefully later today).

DanTup added a commit that referenced this issue May 16, 2022
…managers

Any symlinked binary that points at a binary that doesn't have the same name (like `snap` or `hermit`) is now considered an init script and will be used to initialize if an SDK is not found.

Fixes #3961.
@DanTup DanTup closed this as completed in 4bc199a May 16, 2022
@DanTup
Copy link
Member

DanTup commented May 16, 2022

@alecthomas can you try upgrading both extensions to the Pre-Release versions (v2.41.20220516) and restart VS Code and let me know if you still see any issues?

It should handle situations correctly now:

  • When Flutter is not initialized (eg. you have bin/flutter but /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0 has not been set up yet) in which case you should see VS Code say "Initializing Flutter" while it does that
  • When Flutter is already initialized (eg. /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0 has a complete SDK) it'll detect and use that

You shouldn't need to set FLUTTER_ROOT.

If anything doesn't work, please capture a new log from this version. Thanks!

@DanTup DanTup removed the awaiting info Requires more information from the customer to progress label May 16, 2022
@DanTup DanTup added this to the v3.42.0 milestone May 16, 2022
@DanTup DanTup changed the title VSCode extension unable to find Dart/Flutter using FLUTTER_ROOT if ./bin/dart/./bin/flutter are present Flutter SDK installed via package managers like Hermit are not detected/initialized correctly May 16, 2022
@DanTup DanTup added the in flutter Relates to running Flutter apps label May 16, 2022
@DanTup
Copy link
Member

DanTup commented May 16, 2022

You can switch to the pre-release versions from inside VS Code here:

Dart/Flutter pre-release versions

It may take a few minutes for them to show up as they've only just been published.

@alecthomas
Copy link
Author

Success!! Works absolutely flawlessly, thank you :)

@DanTup
Copy link
Member

DanTup commented May 16, 2022

Great! Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in flutter Relates to running Flutter apps is bug
Projects
None yet
Development

No branches or pull requests

2 participants