-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add std::process::Command::envs() #38856
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
Conversation
Command::envs() adds a vector of key-value pairs to the child process environment all at once. Suggested in rust-lang#38526.
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. |
The tidy check error will go away if you rename the feature to something else. A feature called |
Ah, I misunderstood how that works. I thought that I was expressing "this was added to the 'process' feature in version 1.16". It sounds like you're saying the contents of a 'feature' are permanently frozen once laid down. Is that right? Is it necessary to give this its own feature tag, then, and what would an appropriate name be? If not, what should be done instead? (Please bear with me; I haven't even fully learned the language itself, never mind the procedures for adding stuff to the library. Much of the relevant documentation only talks about bigger "new features" than adding a single function to an existing module.) |
Yep. A good name would be |
@aturon Thanks. That should be fixed now, and I also figured out how to make the test actually run, so my only remaining concern is I need someone to check whether I got the new function's type signature right. |
@zackw you should be able to run the tests by doing |
@achanda I figured that out for myself this morning, but thanks. |
cc @rust-lang/libs, new proposed unstable API. |
@zachW We would want to land this API as unstable initially, to give it some time for feedback before committing to it fully. |
Regarding the function signature, you might consider generalizing to take an |
Looks good to me, and yeah I'd be in favor of generalizing to |
I agree with this, but I have gotten stuck trying to implement it. Consider
Shouldn't it be possible to take a read-only iterator over a borrowed collection? |
@zackw oh I think you'd take just |
@alexcrichton It's more subtle than that. If we can't make this work for both
fails to compile with
I asked about this on Stack Overflow and was told that an adaptor trait is required. I'm hesitant to make up a one-off adaptor trait for a standard library function, though; it seems like if we're going to go that way, something like E_net4's |
Oh right yeah that's a very good point that slices by default yield references, so they wouldn't work here. Ok I think we can scratch that idea then and we should stick with slices, sorry for the runaround! |
Thinking about it some more, I can make the above program work if I change it like so...
Abstractly, having this API expect the Item type you get from
and I could perfectly well make that So maybe we should go ahead with |
Yeah it's true that you can still go from an iterator of a references-to-tuples to an iterator of tuples relatively easy, but it's definitely not the most ergonomic. I'd be fine either way in terms of this API, I think the use cases should just drive it (e.g. does it come from a vec or hash map more often? |
* Command::envs() now takes anything that is IntoIterator<Item=(K, V)> where both K and V are AsRef<OsStr>. * Since we're not 100% sure that's the right signature, envs() is now marked unstable. (You can use envs() with HashMap<str, str> but not Vec<(str, str)>, for instance.) * Update the test to match. * By analogy, args() now takes any IntoIterator<Item=S>, S: AsRef<OsStr>. This should be uncontroversial.
I don't know the answer to that question (and I'm not sure anyone does, yet); the thing that I wanted it for doesn't particularly care. The revision I just pushed uses the version that works with maps but not vec-of-tuples, and marks it unstable. It also includes the generalization of |
I think I'm OK with an API like this. Should the generalization of |
@BurntSushi Yeah, it's probably a good idea. |
I've started crater
|
Toolchains built, testing crates. |
Five of the six failures appear to all have the same basic cause: calling pub fn run_args(cmd: &str, args: &[String], shell: bool) -> Result<(Output)> {
let output;
if args.len() > 0 {
if !shell {
output = try!(Command::new(cmd).args(&args).output());
} else {
... The skia-sys' build system is too convoluted for the problem to be obvious, but if
is the actual primary failure (which I'm not certain of) then I don't see how it can be caused by this change. |
@zackw Thanks for the analysis! That fallout doesn't seem too bad (and this kind of change is definitely permitted under our semver guidelines). That said, it'd be good to try to make PRs against these repos before landing the change. Otherwise, I'm 👍 on going forward. @alexcrichton? |
Sounds good to me! |
📌 Commit 2580950 has been approved by |
I'm sorry, I don't have time to do that this week. |
Add std::process::Command::envs() `Command::envs()` adds a vector of key-value pairs to the child process environment all at once. Suggested in #38526. This is not fully baked and frankly I'm not sure it even _works_, but I need some help finishing it up, and this is the simplest way to show you what I've got. The problems I know exist and don't know how to solve, from most to least important, are: * [ ] I don't know if the type signature of the new function is correct. * [x] The new test might not be getting run. I didn't see it go by in the output of `x.py test src/libstd --stage 1`. * [x] The tidy check says ``process.rs:402: different `since` than before`` which I don't know what it means. r? @brson
☀️ Test successful - status-appveyor, status-travis |
ring is fixed in briansmith/ring#430 |
just as a side note, the example in the documentation is not displayed as code block for some reason (instead as text with three ` at begin and end... At last with the documentation you get shipped with rustup/nightly. |
Command::envs()
adds a vector of key-value pairs to the childprocess environment all at once. Suggested in #38526.
This is not fully baked and frankly I'm not sure it even works, but I need some help finishing it up, and this is the simplest way to show you what I've got. The problems I know exist and don't know how to solve, from most to least important, are:
x.py test src/libstd --stage 1
.process.rs:402: different `since` than before
which I don't know what it means.r? @brson