-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Throw error if CARGO_TARGET_DIR is an empty string #8939
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (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. |
Thanks for the PR! I'm a bit uncomfortable reinterpreting a request for Could this perhaps instead return an error? |
Yeup @alexcrichton. It makes sense that if the env variable is empty is probably the users fault. So returning an error makes more sense! I have made the changes. Now it returns a error: |
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.
Thanks! Can you add a test for this as well?
Also, is there any reason that we shouldn't handle the other cases set to empty strings as well?
I would prefer not to do this. The Unix convention is for empty variables to act as if they're unset - if you look at how PAGER and GIT_PAGER behave, it means you can use See also dandavison/delta#386. |
I guess then if dir.to_str()? == "" {
Ok(Some(Filesystem::new(self.cwd.join("target"))))
} is the right thing to do. As if we trim it then its actually users mistake and we do not need to check that as when we exe a command like |
@jyn514 can you explain when you think the build directory may wish to be configured in a one-off context like that? And why |
I use this for testing cargo plugins. I have a global |
So should I make it return an error, make it behave as if the variable is unset or unset the variable and run the program as normal. @alexcrichton |
@Andy-Python-Programmer the case just below the one you modified, accessing |
@alexcrichton I am not sure as we should only handle the case when the user has set the env var. Cause target will be |
I'm personally not sure why we would only handle the case of the env var. Why would the env var require special handling but not other methods of configuration? |
Because we cannot set the config variable in the other methods of config to `` I guess. |
Sorry I'm not really understanding your responses. Let me try to be more clear. If you set My point is that if you set: [build]
target-dir = '' or |
Ah yes that makes sense. I will just do that 🙃 |
Now if you set [build]
target-dir = '' or |
Could you be sure to add a test for the config case and a test for the env case as well? |
Following up on this: I think this is a good idea, and I think we should merge this as soon as we have tests for the other cases. |
Just a question => #[cargo_test]
fn cargo_target_empty_env() {
let config = ConfigBuilder::new().env("CARGO_TARGT_DIR", "").build(); for the env test I think this is the right way to set the env in the config. So will I need to add a case to also check self.env? |
It may make more sense to have more of an "integration test" for this where you build a whole project and execute |
All good. |
Now: Case 1If you set the environment variable to "". It will error out saying: Case 2[build]
target-dir = '' If you set the target diectory to "" in the config file it will error out saying: I hope I did this right this time :) |
@bors: r+ Thanks! |
📌 Commit b5b2e48 has been approved by |
⌛ Testing commit b5b2e48 with merge 439a2016b7306bfe948a788f89607e8cceb7876a... |
💔 Test failed - checks-actions |
@bors: retry |
☀️ Test successful - checks-actions |
Update cargo 12 commits in 572e201536dc2e4920346e28037b63c0f4d88b3c..c68432f1e5cbbc09833699a951b1b5b059651dff 2021-02-24 16:51:20 +0000 to 2021-03-02 18:26:29 +0000 - Don't panic when printing JSON with non-utf8 paths (rust-lang/cargo#9226) - Detect changes for JSON spec targets. (rust-lang/cargo#9223) - Fix `cargo_target_empty_cfg` test with env var. (rust-lang/cargo#9225) - Correct default cargo new edition (rust-lang/cargo#9202) - Update split-debuginfo docs around the default. (rust-lang/cargo#9224) - Minor update to registry API error messages. (rust-lang/cargo#9213) - Some minor code cleanup. (rust-lang/cargo#9214) - doc: Fix spelling worksapce->workspace (rust-lang/cargo#9212) - Update SPDX version in docs. (rust-lang/cargo#9209) - Throw error if CARGO_TARGET_DIR is an empty string (rust-lang/cargo#8939) - testsuite: Use split debuginfo on macos. (rust-lang/cargo#9207) - testsuite: Improve performance when using rustup. (rust-lang/cargo#9206)
This pull request makes the target dir to be target/ if
CARGO_TARGET_DIR
is `` with spaces trimmed and not delete the current project.Fixes: #8866