Skip to content
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

Pub run should support passing in flags to vm #1018

Closed
DartBot opened this issue Jun 5, 2015 · 42 comments
Closed

Pub run should support passing in flags to vm #1018

DartBot opened this issue Jun 5, 2015 · 42 comments
Assignees
Labels
status-blocked Blocked from making progress by another (referenced) issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2192312?v=3" align="left" width="96" height="96"hspace="10"> Issue by keertip
Originally opened as dart-lang/sdk#19569


A typical invocation of the vm to run command line apps from DartEditor would look like

dart --enable-checked-mode --debug:50677 --enable-vm-service:50678 --trace_service_pause_events --pause-isolates-on-start myapp.dart

and any other that the user may specify

DartEditor should be able to specify arguments to pass on to the vm when starting pub run from the editor.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent


Relatively soon, I want pub run to change from spawning a process to spawning an isolate for the entrypoint being run. (See: https://code.google.com/p/dart/issues/detail?id=19438).

If that happens, we wouldn't be able to have separate VM flags for the spawned app. Would it make sense to spawn the pub process itself with these settings? That would mean the user is also implicitly debugging pub. This could be good if they want to see what transformers are doing, but may be confusing otherwise.

What do you think?


cc @nex3.
Removed Type-Defect, Priority-Unassigned labels.
Added Type-Enhancement, Priority-High labels.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2156198?v=3" align="left" width="48" height="48"hspace="10"> Comment by kasperl


Added this to the 1.6 milestone.

@DartBot DartBot added type-enhancement A request for a change that isn't a bug Priority-Medium labels Jun 5, 2015
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent


Removed this from the 1.6 milestone.
Removed Priority-High label.
Added Priority-Medium label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/3766663?v=3" align="left" width="48" height="48"hspace="10"> Comment by nicolasgarnier


I would also need this for the test runner to be able to gather code coverage data from tests.

I guess that would still be OK with isolates though just a bit more handling/filtering to do.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Does the test runner run via pub run? Is that why you need it?

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/3766663?v=3" align="left" width="48" height="48"hspace="10"> Comment by nicolasgarnier


The test runner runs Standalone VM test (aka non Browser tests) using "pub run" and browser tests using "pub serve" that allows us to make sure eventual transformers are applied without having to run "pub build" first.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/3766663?v=3" align="left" width="48" height="48"hspace="10"> Comment by nicolasgarnier


By the way it would be great if we could also have "pub run" run the VM in un-checked mode (currently it always runs in checked mode). I'm asking about that here because it seem related (you could just make that a flag you optionally pass to the underlying VM)

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3


When we add support for this, we'll definitely allow explicit control of checked mode as well.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Possibly blocked by https://code.google.com/p/dart/issues/detail?id=21791 ?

@alexander-doroshko
Copy link

Without ability to pass --enable-vm-service:xxxx --pause_isolates_on_start is is not possible to debug tests that use test package. This feature is required for proper integration of test framework in WebStorm / IntelliJ IDEA. I'd kindly ask to reconsider its priority.
Cc @stevemessick

@kevmoo
Copy link
Member

kevmoo commented Oct 16, 2015

@alexander-doroshko FYI: there is a tracking bug on the test package for this: dart-lang/test#50

@nex3
Copy link
Member

nex3 commented Oct 16, 2015

Turning on Observatory and configuring it is blocked on dart-lang/sdk#23320.

@nex3 nex3 added the status-blocked Blocked from making progress by another (referenced) issue label Oct 16, 2015
@kasperpeulen
Copy link
Contributor

But issue dart-lang/sdk#23320 is closed and labeled as not planned on Apr 26. So does that mean we are not going to see debugging support of the test package in Webstorm? 😢

@kevmoo
Copy link
Member

kevmoo commented Nov 16, 2015

@kasperpeulen We have work to align our VM work with test package – but we will have great debug support in pkg/test. 😄

@rayk
Copy link

rayk commented May 13, 2016

Guys we are a year on... Debugging VM test is still not sorted....

Is there an update is there a plan?

@alexander-doroshko
Copy link

alexander-doroshko commented May 13, 2016

Yes, pub run starts the main app as a separate OS process (separate Dart VM) and user has no control on VM options for it.
I see 2 ways of solving it:

  • One is to add some options to pub run syntax that would be passed to a child process where the app runs. That's what this request is asking for.
  • Another approach is that pub run executes the main app in a separate isolate of the same VM rather than in a separate VM. In this case it will be possible to start pub run with some VM options and these VM options will be also applied to the main app. For example:
[Dart SDK]/bin/dart --pause_isolates_on_start --enable-vm-service:50412 [Dart SDK]/bin/snapshots/pub.dart.snapshot run test

This request is tracked as #1204.

2nd approach looks a bit better to me, but I'm not from the Dart team and do not make decisions.
Anyway I think one of these 2 tickets (this and #1204) can be closed in favor of another one.
// cc @nex3 @munificent

@nex3
Copy link
Member

nex3 commented May 16, 2016

@rayk: The issue is marked as blocked. Nothing is going to move forward here until it's unblocked.

Anyway I think one of these 2 tickets (this and #1204) can be closed in favor of another one.

@alexander-doroshko This is specifically tracking the addition of the functionality provided by VM options, which is an additional feature (or collection of features) that will need to be implemented on top of #1204.

@a14n
Copy link

a14n commented Jun 6, 2017

Any progress on this issue ?
Flutter uses an experimental langage feature (--assert_initializer) but it's not possible to use it in parts where pub run test is used to test (in flutter_tools).

@kevmoo
Copy link
Member

kevmoo commented Jun 6, 2017

@a14n
Copy link

a14n commented Jun 7, 2017

@kevmoo thanks I didn't try this env variable and it seems to work.

@aam
Copy link

aam commented Mar 1, 2018

cc @rmacnak-google @zanderso

@natebosch
Copy link
Member

We don't have plans of implementing an option other than DART_VM_OPTIONS environment variable. Please reopen if there are use cases not covered.

@DanTup
Copy link

DanTup commented Jun 26, 2018

@natebosch I used DART_VM_OPTIONS but discovered that because it's an env var it gets inherited by all VMs spawned down the tree. In my case since I'm passing --pause-isolates-on-start=true it means if any of my tests call out to Dart/Flutter/Pub they just hang because the spawned process is paused at startup (bug). I think there should really be a way to use args that only apply to the direct invocation from pub.

@munificent
Copy link
Member

That does sound like a valid use case. Re-opening but note that it doesn't necessarily mean we'll find the time to do this, just that I think it's reasonable for the issue to stick around. :)

@DanTup
Copy link

DanTup commented Jun 26, 2018

Do you have an idea of how it could work? Is it contributable?

I also can't guarantee time; but it bugs me that the test runner in VS Code is only going to be enabled for Flutter by default (behind a flag for Dart) because of a few issues like this, so I'm motivated to try and fix that :-)

@natebosch
Copy link
Member

if any of my tests call out to Dart/Flutter/Pub they just hang

I'm unsure of flutter, but calls to dart should not hang. The VM doesn't look at DART_VM_OPTIONS, that variable is unwrapped by the pub shell script. If you can set up your tests to always invoke dart instead of pub run you should not have an issue and you'll have full control over the flags you use.

If you have a use case where you can't avoid pub run today maybe we can solve it with #1811 so you could turn your pub run into a dart subprocess instead.

@DanTup
Copy link

DanTup commented Jun 26, 2018

Sorry, maybe I described it badly. The test is calling flutter packages get (as part of setup code). The hang is because it's inheriting --pause-isolates-on-start. I assumed it affected Dart because it affects flutter, but I think that's just because flutter is calling pub here.

Although there may be workarounds for my specific tests; I'm not confident in shipping things on-by-default for end uses with lots of edge cases and caveats (especially when the failure can be hard to debug - it took me a while to figure out my test timeouts where caused by being inside my test runner!).

@natebosch
Copy link
Member

Ah yeah, a pub get is going to honor the environment variable so you'd need to clear it out of the environment for the subprocess.

@DanTup
Copy link

DanTup commented Jun 27, 2018

Yeah; which is reasonable enough for me to do in these specific tests because they're mine and it's in test code, but doesn't make a great caveat for end-users (if you have tests that call pub/flutter, or even call production code that calls pub/flutter, you need to mess with the env vars) :(

@DanTup
Copy link

DanTup commented Jul 9, 2018

@munificent @natebosch Any thoughts on this?

Do you have an idea of how it could work? Is it contributable?

@natebosch
Copy link
Member

I don't know of a way to make this work. Today we invoke the executable in an Isolate and can't pass different VM args to an isolate. We'd need to do something like spawn an entirely separate process in the case where there are args. There will be some runtime and memory overhead.

@nex3
Copy link
Member

nex3 commented Jul 9, 2018

There are also semantic differences between running in an isolate and running in a subprocess, with respect to how the OS treats the executable and especially how its signals are handled.

@natebosch
Copy link
Member

Does inheritStdio resolve most of those differences? I think I remember seeing signals getting handled by the subprocess.

@nex3
Copy link
Member

nex3 commented Jul 9, 2018

I don't believe it affects signal handling, but I haven't tested extensively.

@DanTup
Copy link

DanTup commented Jul 11, 2018

I don't know of a way to make this work. Today we invoke the executable in an Isolate and can't pass different VM args to an isolate.

pub is just a shell script and currently reads the env args to pass to the VM:

# Allow extra VM options to be passed in through an environment variable.
if [[ $DART_VM_OPTIONS ]]; then
  read -a OPTIONS <<< "$DART_VM_OPTIONS"
  VM_OPTIONS+=("${OPTIONS[@]}")
fi

I think my request is just to let me pass that as a flag to pub instead (or alternatively, wipe out that env variable when spawning the VM so it's unset for the VM and child processes)?

@DanTup
Copy link

DanTup commented Jul 11, 2018

Hmm, though now I'm wondering why I can't just run the VM and pass the pub snapshot... I did try that previously, but it was when trying to bypass the runner so possibly the reason I gave up on it doesn't apply here.

I can't see anything complicated in the pub shell script, so I might give this a go..

@DanTup
Copy link

DanTup commented Jul 11, 2018

Well, the change the change seems to work fine - tests that used to hang when running under the test runner are working by just invoking the VM directly with the snapshot path. It's what @alexander-doroshko suggested way up ^^ there and I skipped over because of issues when I was trying to do something more complicated with it.

Unless anyone has a good reason not to, I'm going to ship like this (and remove the preview flag on using the test runner for VM tests) in the next version of Dart Code.

@natebosch
Copy link
Member

The link to the change is dead - can you update it?

@DanTup
Copy link

DanTup commented Jul 11, 2018

Rebase strikes! It's here (until it gets rebased again; it's not merged yet because of CI badness):

Dart-Code/Dart-Code@b4d80e0#diff-2c4d134c0921e50e0f44bfbf9be83300L37

It's fairly simple though; just swaps pub for dart, puts in the snapshot path from the SDK and passes the pause/port options directly instead of in the env variable.

@natebosch
Copy link
Member

That seems like a pretty reasonable approach. It's sensible that when you're invoking pub in this way you want to have full control and invoke dart directly rather than use the wrapping shell/batch script.

@natebosch
Copy link
Member

I thought some more about this and I think we're not going to be able to solve this in a way that makes everyone happy.

We could clear out DART_VM_OPTIONS in the pub shell script so that it's not inherited, but certain vm options like --root-certs-file are things that the users likely does want to get picked up by subprocess invocations of pub.

We could add support for arbitrary flags but we'd need to fall back to a subprocess VM instead of an isolate, but as pointed out above that has consequences around signal handling etc.

I think in the end pub shouldn't necessarily be the tool that handles all this knowledge around the Dart VM. It pushed a bit more complexity down to the tools invoking pub, but I think the right thing to do is move forward with #1811 which could give you a way to find the thing that pub would have ran, and then run it yourself with whatever flags to the VM you'd like.

We might not get that implemented right away but we also have some existing workarounds mentioned in this thread so I don't think there is any action for us to take on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-blocked Blocked from making progress by another (referenced) issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests