-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Unify syntax to define environment declarations (--define
)
#44562
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
I'll initially tag this as dart-cli; @devoncarew is there a plan to unify this flag? |
There should be an effort to make this more consistent, and it's definitely an oversight that A temporary workaround is to provide |
@sigmundch can you or someone else take a look at the |
Thank you for the attention and for the tip about This flag is very important in the build pipeline because it provides (in pair with That the need for such a mechanism is strongly felt in the Dart community is testified by the multitude of related issues opened (as Please document {String|int|bool}.fromEnvironment) and of Dart packages that try to emulate it in various ways (with code generation, multiple entry point files, etc.), but all with severe drawbacks (i.e. dotenv, flutter_dotenv, envify, dynamic_config_generator, flutter_config, env_vars, dotenv2dart, etc). |
Another syntax-related issue concerns comma support:
Compile the source with: Output using
Output using
|
commands - Added support for --define to the VM and dart2js - Added support for -D and --define for `dart run` and `dart compile js` Remaining improvements: - Add support for providing multiple comma separated values for `dart run`, `dart`, and `dart2js` Related issue: #44562 TEST=Updated CLI tests and added new dart2js tests. Change-Id: I9379c7aee1eab377adb3438393d9ad79c4938cc4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178262 Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
…and" This reverts commit e83e784. Reason for revert: Failing on SIMARM and AOT bots Original change's description: > [ CLI ] Improved consistency of -D and --define across tools and > commands > > - Added support for --define to the VM and dart2js > - Added support for -D and --define for `dart run` and `dart compile js` > > Remaining improvements: > - Add support for providing multiple comma separated values for `dart > run`, `dart`, and `dart2js` > > Related issue: #44562 > > TEST=Updated CLI tests and added new dart2js tests. > > Change-Id: I9379c7aee1eab377adb3438393d9ad79c4938cc4 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178262 > Commit-Queue: Ben Konyi <bkonyi@google.com> > Reviewed-by: Sigmund Cherem <sigmund@google.com> > Reviewed-by: Siva Annamalai <asiva@google.com> TBR=bkonyi@google.com,asiva@google.com,sigmund@google.com Change-Id: I1c594ae7db551619cc3191ff7f832c4fc61a4171 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179081 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
…and commands" - Added support for --define to the VM and dart2js - Added support for -D and --define for `dart run` and `dart compile js` Remaining improvements: - Add support for providing multiple comma separated values for `dart run`, `dart`, and `dart2js` Related issue: #44562 TEST=Updated CLI tests and added new dart2js tests. This reverts commit e499377. Change-Id: I5f9275b829665eb5e8695403d67f230e752ab0e6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183180 Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
how to add environment variables to this works: this doesn't: |
- env vars cannot be piped to wasm binary (AFAIU, see bevyengine/bevy#5737 (comment)) - args can be passed though, but dart2js has a specificity: it only works with '-D' syntax, not '--define' as it seems (see dart-lang/sdk#44562 huge thanks @Mabsten) - logs from rust won't appear in the terminal, but can be seen in the browser's console spinned by puppeteer: this is why outputting to stdout is not particularly useful on web platform. since the browser gets spinned up and down very quickly, but you can peek at them either using --pause-isolates-on-exit on dart run command (more convenient), or by sleeping thread, etc
I don't think the Is this happening to anyone else? |
@pak3nuh would you mind filing a new issue? This one has been closed for quite awhile. |
Sure. Created issue #51791 |
The syntax to define environment declarations (to read with
String.fromEnvironment()
method and relateds) is very divergent between the various tools/dart sub-commands:(I tested the flags with Dart Sdk 2.12 (2.12.0-133.2.beta, on Windows x64))
dart2native
/dart compile exe
use the
-D
/--define
flag(cfr https://dart.dev/tools/dart2native );
/dart
dart run
does not support the define flags
UPDATE:
dart
supports the -D flag (also
dart -D run
is ok)although it is not mentioned in the help and in the doc
(cfr https://dart.dev/tools/dart-vm );
dart2js
use only the
-D
flag;(cfr https://dart.dev/tools/dart2js#options );
dart compile js
does not even support the
-D
flag, despite it being the substitute of thedart2js
command (I think);dartdevc
-usingwebdev
-require to use a build.yaml file or this command-line syntax (not tested):
webdev serve -- '--define=build_web_compilers:ddc=environment={"SOME_VAR":"some_value"}'
(cfr https://dart.dev/tools/webdev and https://pub.dev/packages/build_web_compilers );
flutter (from the Sdk 1.17)
use the
--dart-define
flag.The
--dart-define
flag is very useful in Flutter, for example to set a log level or an api token.Wouldn't it be useful if all the sub-commands of the new dart tool supported the define flag? Or maybe I'm missing an alternative that already exists?
The text was updated successfully, but these errors were encountered: