-
Notifications
You must be signed in to change notification settings - Fork 316
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
feat: Allow environment variables in run configurations #5885
feat: Allow environment variables in run configurations #5885
Conversation
Allow users to set their own env vars per run-configuration. It is not respected everywhere (see the list below), but it works on our example projects. Main features: - Env vars should work when **run**ing and **debug**ging any binary. - Env vars should work when **run**ning any test. - Env vars should work when **debug**ging Go and Java tests. Env vars for C++ test debugging are implemented internally, but they're part of a larger patch and I'll need some more work to untangle that.
This looks like a smallish change, but it's in a deep part of the codebase. I've tested it locally on the workflows listed, but please do give it a shot. It can use as many eyes as we can give it. |
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 manually tested it for Java, it is not working when running a single test method but works when running the whole test class. I also think we need to also add unit tests.
.../com/google/idea/blaze/base/run/confighandler/BlazeCommandGenericRunConfigurationRunner.java
Outdated
Show resolved
Hide resolved
.../com/google/idea/blaze/base/run/confighandler/BlazeCommandGenericRunConfigurationRunner.java
Outdated
Show resolved
Hide resolved
golang/src/com/google/idea/blaze/golang/run/BlazeGoRunConfigurationRunner.java
Outdated
Show resolved
Hide resolved
java/src/com/google/idea/blaze/java/run/BlazeJavaRunProfileState.java
Outdated
Show resolved
Hide resolved
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.
@mai93 Thanks for the comments! I've tried to address the inline ones there, but for the broader points:
I manually tested it for Java, it is not working when running a single test method but works when running the whole test class.
I've found that it works on a single method just fine (as long as I add the env vars to the new config as well). I've added example run configurations to the greetings_project
to demonstrate, but please let me know if you still see that.
I also think we need to also add unit tests
I haven't done this yet, but will look into where it makes sense to add them. Thanks!
.../com/google/idea/blaze/base/run/confighandler/BlazeCommandGenericRunConfigurationRunner.java
Outdated
Show resolved
Hide resolved
golang/src/com/google/idea/blaze/golang/run/BlazeGoRunConfigurationRunner.java
Outdated
Show resolved
Hide resolved
.../com/google/idea/blaze/base/run/confighandler/BlazeCommandGenericRunConfigurationRunner.java
Outdated
Show resolved
Hide resolved
4ac71a1
to
01a8224
Compare
I have added a few unit tests, particularly for java tests. Unfortunately, I haven't seen any unit or integration tests for the biggest changes (namely, how the processes are actually spawned). |
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 left small comments and I tested it manually on Java, it is working fine. Thanks @blorente!
golang/src/com/google/idea/blaze/golang/run/BlazeGoRunConfigurationRunner.java
Outdated
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/run/state/EnvironmentVariablesState.java
Show resolved
Hide resolved
@@ -11,5 +11,5 @@ gazelle_target: //:gazelle | |||
import_run_configurations: | |||
# Test that validates that macro expansion works, as per issue: | |||
# https://github.com/bazelbuild/intellij/issues/4112#event-7958662669 | |||
# This configuration should be executed on both 'run' (the green arrow) and 'debug' (the bug) modes. | |||
# This configuration should only be executed on both 'run' (the green arrow) mode. |
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.
Sorry if I misunderstood it, but in the PR description it says that Env vars should work for go debugging. has this changed?
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 should have written a better comment, sorry about that.
The main issue is that, because of how we pass env vars to debuggers, the IntelliJ macros (e.g. $ProjectName$
) are not expanded. So, the env vars get passed, but the macros don't get expanded.
I've added a new run configuration to test env vars, which works on both run and debug.
...om/google/idea/blaze/base/run/BlazeCommandRunConfigurationGenericHandlerIntegrationTest.java
Show resolved
Hide resolved
@mai93 Thanks for the review! Comments addressed, please take a look when you have time. |
Thanks @blorente! LGTM, leaving the merge for you if you want someone else to take a look as well. |
Given the amount of time this has been active internally I'm pretty confident of merging after your review, but I'm happy to work on fixing issues (or writing documentation about where env vars do and don't work). |
Checklist
Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See
the Contributions section in the README for more
details.
Discussion thread for this change
Issue Number: #2042
Replaces #4138
Description of this change
Allow users to set their own env vars per run-configuration. It is not respected everywhere (see the list below), but it works on our example projects.
Main features:
$WorkspacePath$
) are not supported in Debug mode.This work was based off of @victoriaroseb 's initial implementation.