Skip to content

Conversation

vojtechkral
Copy link
Contributor

I'm just setting the env var on the process itself, letting subprocesses inherit that, as it's easier than setting for each subprocess individually. I'm not entirely sure this is the right spot though.

Also, I should probably document this somewhere - what would be the best place?

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

Could this be done in a perhaps less invasive way than setting an env var? Could we just set it for child processes where it's relevant?

@vojtechkral
Copy link
Contributor Author

Sure, provided I'll be able to find the right / relevant places. I'll update...

@vojtechkral
Copy link
Contributor Author

vojtechkral commented Mar 5, 2017

Ok, so I restricted the env var setting to external subcommands. (I'm still not sure about #3744, I'll update for that one later...)

Edit: Updated setting env var for cargo test as well. In case this is reviewed favorably, please let me squash commits before merging...

@@ -91,6 +92,9 @@ fn run_unit_tests(options: &TestOptions,
};
let mut cmd = compilation.target_process(exe, pkg)?;
cmd.args(test_args);
if let Some(arg0) = env::args_os().next() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you follow the definition of target_process I think you'll find the fill_env function which is likely where this should go.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you add some tests for this as well?

@vojtechkral
Copy link
Contributor Author

Yeah, it occured to me tests would be nice too, this is a bit tricky though, I'm gonna need an 'answering subprocess'. I have no idea what the testing environment requirements are, can I assume it is unixy and can execute basic shell scripts?

@alexcrichton
Copy link
Member

Oh you can take a look at tests/*.rs, there should be tons of examples of child processes and such.

@vojtechkral
Copy link
Contributor Author

Uhh, lemme fix that...

@alexcrichton
Copy link
Member

Reading this again, I think that we may also want to store this somewhere in Config? Right now literally passing argv[0] is just passing whatever was passed on the command line, not necessarily an absolute path. Perhaps we could use current_exe to populate this, and cache that value in Config?

@vojtechkral
Copy link
Contributor Author

Yeah, I've just rewritten it using current_exe. I'll look at Config...

@vojtechkral
Copy link
Contributor Author

Does something like cargo_exe: LazyCell<PathBuf>, sound good to you?

@alexcrichton
Copy link
Member

Yeah sounds fine by me

@matklad
Copy link
Contributor

matklad commented Mar 7, 2017

Also, I should probably document this somewhere - what would be the best place?

http://doc.crates.io/environment-variables.html seems like a good option.

@alexcrichton
Copy link
Member

r=me with some docs @matklad pointed out, thanks @vojtechkral!

@alexcrichton alexcrichton reopened this Mar 7, 2017
@alexcrichton
Copy link
Member

(oops)

@@ -41,6 +41,8 @@ use term::color::{BLACK};

pub use util::{CargoError, CargoResult, CliError, CliResult, human, Config, ChainError};

pub const CARGO_ENV: &'static str = "CARGO";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something more verbose like CARGO_EXECUTABLE would be a tiny bit better, but we already use plain RUSTC and RUSRDOC variables for similar purposes, and in this regard just CARGO is indeed the best name here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a strong feeling one way or another (hehe) but I guess, like you said, CARGO is good for consistency with RUSTC ...

@vojtechkral
Copy link
Contributor Author

vojtechkral commented Mar 7, 2017

Writing the documentation makes me think whether maybe we should just call fill_env for external subcommands as well... Would that make sense @alexcrichton ? edit: Never mind, that's done on compilation object which we don't have with external subcommands...

@alexcrichton
Copy link
Member

Yeah those two code paths are unfortunately pretty different

@vojtechkral
Copy link
Contributor Author

(added doc + squashed)

@alexcrichton
Copy link
Member

@bors: r+

Thanks @vojtechkral!

@bors
Copy link
Contributor

bors commented Mar 8, 2017

📌 Commit 015a08a has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Mar 8, 2017

⌛ Testing commit 015a08a with merge 0806953...

bors added a commit that referenced this pull request Mar 8, 2017
Tell subprocesses the path to self in an env variable #3778

I'm just setting the env var on the process itself, letting subprocesses inherit that, as it's easier than setting for each subprocess individually. I'm not entirely sure this is the right spot though.

Also, I should probably document this somewhere - what would be the best place?
@bors
Copy link
Contributor

bors commented Mar 8, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 0806953 to master...

@bors bors merged commit 015a08a into rust-lang:master Mar 8, 2017
@vojtechkral vojtechkral deleted the cargo_env branch March 8, 2017 06:57
@ehuss ehuss added this to the 1.17.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants