-
Notifications
You must be signed in to change notification settings - Fork 231
Pub build/serve/run does not support defining environment variables #798
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
<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent Yeah, this would be good to support. Might also be nice to be able to specify these in the pubspec. Removed Type-Defect label. |
<img src="https://avatars.githubusercontent.com/u/3276024?v=3" align="left" width="48" height="48"hspace="10"> Comment by anders-sandholm Added Area-Pub label. |
<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent Removed Priority-Unassigned label. |
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3 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 #694. |
<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent
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). |
<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent 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 dart-lang/sdk#15925. |
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3
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. |
<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent Issue #829 has been merged into this issue. |
<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd Added Pub-Build label. |
<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd 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. |
<img src="https://avatars.githubusercontent.com/u/405837?v=3" align="left" width="48" height="48"hspace="10"> Comment 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 |
<img src="https://avatars.githubusercontent.com/u/719048?v=3" align="left" width="48" height="48"hspace="10"> Comment by paulevans or... you know pub could just pass on the environment to the transformers it runs :) |
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3 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. |
<img src="https://avatars.githubusercontent.com/u/405837?v=3" align="left" width="48" height="48"hspace="10"> Comment 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. |
<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd 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 |
<img src="https://avatars.githubusercontent.com/u/405837?v=3" align="left" width="48" height="48"hspace="10"> Comment 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. |
<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd Sorry I wasn't clear. I meant "we are unable to set environment variables from the command line when we use pub build" |
<img src="https://avatars.githubusercontent.com/u/648527?v=3" align="left" width="48" height="48"hspace="10"> Comment 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. |
<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd 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". |
Based on what |
As of Pub 1.20.1 there is no environment variables passing support.
|
See the comment before yours
|
You are right @zoechi. However, this issue is about supporting env vars by pub.
In each case |
@koorgoo Better create a separate issue for the feature that you described above. |
There should already be an issue about disambiguate that. |
@Fox32, as a newbie I misunderstood environment variable term. |
We are no longer supporting transformers or We'll be updating the tooling section of the Dart website in the coming weeks with more formal documentation on how to get started. |
<img src="https://avatars.githubusercontent.com/u/1148886?v=3" align="left" width="96" height="96"hspace="10"> Issue by butlermatt
Originally opened as dart-lang/sdk#15806
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: