-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Pub build/serve/run does not support defining environment variables #15806
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
Comments
Yeah, this would be good to support. Might also be nice to be able to specify these in the pubspec. Removed Type-Defect label. |
Added Area-Pub label. |
Removed Priority-Unassigned label. |
I'm not a big fan of the ability to define arbitrary environment variables in the pubspec. It seems out-of-scope. Users have the means to define their environment variables via the OS; if a variable is specific to a project and not to a user's configuration, it's not really an environment variable anyway. If the use case for this is just passing flags to dart2js, this should be merged into issue #14664. |
These "environment variables" are an entirely unrelated concept to the OS's environment variables. They're a way of passing in constants to Dart code from outside. See: https://api.dartlang.org/docs/channels/stable/latest/dart_core/bool.html#fromEnvironment They are passed to the command-line VM using "-D<name> <value>" (I think? I'm not aware of any actual documentation of this feature). |
Pub build and pub serve are currently focused on web applications. Dartium does not support these "environment variables" yet, so we'd be unable to support this in pub serve. Given that, we won't support it in pub build yet because that would lead to diverging behavior between the app in development and in production. Once Dartium supports this, we can look into figuring out how we want to pass this along to it. Marked this as being blocked by #15925. |
Ugh, "environment variable" is not a good name for that concept. Now we have two notions of "environment variable" that refer to completely separate ways of passing in constants to Dart code from outside. |
Issue #16370 has been merged into this issue. |
Added Pub-Build label. |
Here's the use case: We have a build process. We compile our app with dart2js. We set environment variable for the VERSION, via -DVERSION=1.2.3 dart2js correctly "bakes" in that VERSION value into the compiled code. pub build is the "canonical" way to build a Dart app. However, we can't pass in the environment variable via pub build tool via command line. Often times, the build step is part of a larger workflow, driven by a script. We don't want to physically edit the pubspec.yaml file in the build workflow when we change this VERSION, we'd like to set these values from the command line. cc @johnmccutchan. |
This comment was originally written by @zoechi I think a very simple solution to all these "configurable pubspec.yaml" issues would be to add support for reading the pubspec.yaml file from stdin. This would allow all kind of solutions
An ugly workaround is to rename the pubspec.yaml, save a customized file as pubspec.yaml, run |
This comment was originally written by @paulevans or... you know pub could just pass on the environment to the transformers it runs :) |
Passing in an entire pubspec via stdin seems vastly like overkill, especially since you need to make sure that it has everything else identical to the current pubspec. At that point you might as well just write a script to temporarily modify the existing pubspec. |
This comment was originally written by @zoechi It allows a lot of flexibility without adding much complexity to pub. I don't see why this should be overkill. It would be simple to use a few $xxx and do shell string interpolation or similar. |
Related conversation on Twitter: https://twitter.com/paulecoyote/status/590892034900131840 This blog post talks about String.fromEnvironment() but this technique doesn't work with pub build: http://blog.sethladd.com/2013/12/compile-time-dead-code-elimination-with.html |
This comment was originally written by @zoechi I'm not sure what you mean by "doesn't work with pub build". I created a simple example here https://github.com/zoechi/build_variables/blob/master/pubspec.yaml#L15 and I think it works. Maybe I misunderstood your problem. |
Sorry I wasn't clear. I meant "we are unable to set environment variables from the command line when we use pub build" |
This comment was originally written by @Fox32 Our current workaround is using a transformer that updates a template dart file that comes with the project. The template file defines some constants that also allow for dead code removal. Right now the transformer gets the values to insert into the template file from OS environment variables that we have to define in the current shell before running pub build. I could imagine a implementation were pub can have additional build parameters that barback passes to each transformer's constructor via the BarbackSettings class. The further behavior is up to the transformer, but $dart2js could use them as environment variables. |
I haven't confirmed, but I imagine that pub run and pub serve don't support passing -D all the way through. I might be wrong, though. Changed the title to: "Pub build/serve/run does not support defining environment variables". |
This issue has been moved to dart-lang/pub#798. |
This issue was originally filed by @butlermatt
Currently dart2js supports -D option to define environment variables. See Seth's blog post:
http://blog.sethladd.com/2013/12/compile-time-dead-code-elimination-with.html
Currently pub build will not accept (let alone pass) -D arguments to dart2js.
The text was updated successfully, but these errors were encountered: