-
Notifications
You must be signed in to change notification settings - Fork 229
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
Remove duplicate global invocation on Windows #3055
Conversation
In the Batch file defined in `_createBinStub`, the script attempts to call the package using the dart snapshot. If it fails, the Batch script uses `dart pub global` directly. However, the `dart pub global` command is still present even when using the snapshot works. This PR removes the second call so that package is only run once. This is especially important/urgent because a lot of executable packages focus on project management, and make sensitive changes to the files in a user's project. Having those changes run twice can cause errant behavior.
pub/lib/src/global_packages.dart Lines 752 to 765 in 26576f6
Adding the |
Okay, I figured it out. The error is not the duplicate All tests in |
@@ -750,7 +750,7 @@ To recompile executables, first run `global deactivate ${dep.name}`. | |||
assert(p.isAbsolute(snapshot)); | |||
invocation = ''' | |||
if exist "$snapshot" ( | |||
dart "$snapshot" %* | |||
call dart "$snapshot" %* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If dart
from PATH
is actually dart.bat
then using call
makes a difference, because invoking a bat script from another bat script will stop the original bat script from working.
How that triggers this to be run twice I don't understand.
hmm, can this cause problems when dart
is not a dart.bat
file, which is the case when installed from the Dart SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no clue how but from several hours of investigating, I found that even when the if branch of the errorlevel 253
if statement runs, the goto error
line doesn't run. I put an echo before and after and both are printed -- it's almost like the goto is skipped. Using call
somehow prevents this from happening. My only guess is that something in dart.bat
, or one of the batch files it calls, must be changing something or setting a conflicting label, and that using call
tells CMD to use Dart in a separate context. I couldn't find anything concrete though.
When dart
is really dart.exe
(in flutter/bin/cache/dart-sdk/bin/dart.exe
, the place dart.bat
forwards to), call
still works. I ran all the binstub tests for both versions of PATH, making sure to close cmd.exe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, it isn't the dart snapshot
that runs twice. Instead, the goto error
line is skipped, even when the if statement is run. That causes the first dart pub global run
command to run as well, effectively running the executable twice.
That's why so many fixes out there (and my initial draft for this PR) simply deleted the first dart pub global run
line. But that broke some tests, this is the proper solution.
The review for this change is here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM - @jonasfj do you have anything more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Are we going to land this? |
I added a specific regression test. |
In the Batch file defined in_createBinStub
, the script attempts to call the package using the dart snapshot. If it fails, the Batch script usesdart pub global
directly. However, thedart pub global
command is still present even when using the snapshot works. This PR removes the second call so that package is only run once. This is especially important/urgent because a lot of executable packages focus on project management, and make sensitive changes to the files in a user's project. Having those changes run twice can cause errant behavior.EDIT: Adding a
call
before the dart command in the generated binstub fixes an error where, if the user hasflutter\bin\dart.bat
ahead offlutter\bin\cache\dart-sdk\bin\dart.exe
in their PATH, the script gets called twice. I tried tracking down the cause but couldn't. All I know is that something happens in flutter'sdart.bat
that really messes with the binstub, and won't even let the simplegoto error
statement run properly. Usingcall
fixes that... somehow.Fixes #2934