-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Make target-spec json file extensions case-insensitive #127389
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
base: master
Are you sure you want to change the base?
Make target-spec json file extensions case-insensitive #127389
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @wesleywiser (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
These commits modify compiler targets. |
This comment has been minimized.
This comment has been minimized.
b2a0b72
to
6f2248d
Compare
Thanks for the fix, and welcome!
If you're up for it it's never a bad thing to have a regression test, even if it means you'll be the only one no longer crying :) You can just translate your test instructions into a rmake test (mirror a test that uses the newer |
This PR modifies cc @jieyouxu |
@bors try |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@bors try |
…sensitive, r=<try> Support target-spec json file extension in various cases Currently user's target json file can have only `json` ext, but cannot have `JSON' or any other strange form. This is a little fix with added support of case-insensitive file-ext for user specified target only. That means that not supported in following cases: - any directory traversal, such as in `$RUST_TARGET_PATH` - same for `rustc_target::spec::Target::search`, so it doesn't work with `JSON` on case-sensitive FS, but __works fine on case-insensitive FS__. - `$RUST_TARGET_PATH` dir traversal in the bootstrap is not touched too. ## Performance cost: Almost without changes. Comparison using `eq_ignore_ascii_case` for __only latest ext_len chars__ of the `OsStr` (as bytes). ## Testing How to test: 1. `rustc --print target-spec-json -Zunstable-options > ./some-target.JSON` 1. remove `is-builtin` field from the `some-target.JSON` or set to `false` 1. `rustc --print target-spec-json -Zunstable-options --target=some-target.JSON` should work 1. `rustc --print target-spec-json -Zunstable-options --target=some-target` should work on case-insensitive FS 1. `rustc --print cfg --target=some-target` should work too, on case-insensitive FS Tests added. ## Implementation note I've separated the comparison into a method for potential future use instead of just `str.ends_with(".json")` and to maintain compatibility. The method is public for the same reasons. Fixes rust-lang#127387 issue. try-job: test-various try-job: armhf-gnu try-job: x86_64-msvc try-job: aarch64-apple
Should I push just one commit instead of these few? |
…sensitive, r=<try> Support target-spec json file extension in various cases Currently user's target json file can have only `json` ext, but cannot have `JSON' or any other strange form. This is a little fix with added support of case-insensitive file-ext for user specified target only. That means that not supported in following cases: - any directory traversal, such as in `$RUST_TARGET_PATH` - same for `rustc_target::spec::Target::search`, so it doesn't work with `JSON` on case-sensitive FS, but __works fine on case-insensitive FS__. - `$RUST_TARGET_PATH` dir traversal in the bootstrap is not touched too. ## Performance cost: Almost without changes. Comparison using `eq_ignore_ascii_case` for __only latest ext_len chars__ of the `OsStr` (as bytes). ## Testing How to test: 1. `rustc --print target-spec-json -Zunstable-options > ./some-target.JSON` 1. remove `is-builtin` field from the `some-target.JSON` or set to `false` 1. `rustc --print target-spec-json -Zunstable-options --target=some-target.JSON` should work 1. `rustc --print target-spec-json -Zunstable-options --target=some-target` should work on case-insensitive FS 1. `rustc --print cfg --target=some-target` should work too, on case-insensitive FS Tests added. ## Implementation note I've separated the comparison into a method for potential future use instead of just `str.ends_with(".json")` and to maintain compatibility. The method is public for the same reasons. Fixes rust-lang#127387 issue. try-job: test-various try-job: armhf-gnu try-job: x86_64-msvc try-job: aarch64-apple
When being reviewed, it's perfectly fine to have intermediate commits, but if you think it helps review or otherwise makes your commits more logical/cleaner, feel free to group logical changes into individual commits (whatever makes more sense) and rebase/force-push if you need to. If you do rebase/force-push, it can help to either remark on the addressed review comments or post a short description on what's different since last rebase/force push or last review if the difference is significant. A reviewer may ask you to reorganize the commit history before merge to tidy it up. |
…sensitive, r=<try> Support target-spec json file extension in various cases Currently user's target json file can have only `json` ext, but cannot have `JSON' or any other strange form. This is a little fix with added support of case-insensitive file-ext for user specified target only. That means that not supported in following cases: - any directory traversal, such as in `$RUST_TARGET_PATH` - same for `rustc_target::spec::Target::search`, so it doesn't work with `JSON` on case-sensitive FS, but __works fine on case-insensitive FS__. - `$RUST_TARGET_PATH` dir traversal in the bootstrap is not touched too. ## Performance cost: Almost without changes. Comparison using `eq_ignore_ascii_case` for __only latest ext_len chars__ of the `OsStr` (as bytes). ## Testing How to test: 1. `rustc --print target-spec-json -Zunstable-options > ./some-target.JSON` 1. remove `is-builtin` field from the `some-target.JSON` or set to `false` 1. `rustc --print target-spec-json -Zunstable-options --target=some-target.JSON` should work 1. `rustc --print target-spec-json -Zunstable-options --target=some-target` should work on case-insensitive FS 1. `rustc --print cfg --target=some-target` should work too, on case-insensitive FS Tests added. ## Implementation note I've separated the comparison into a method for potential future use instead of just `str.ends_with(".json")` and to maintain compatibility. The method is public for the same reasons. Fixes rust-lang#127387 issue. try-job: test-various try-job: armhf-gnu try-job: x86_64-msvc try-job: aarch64-apple
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
So, what's next steps? Should I close this PR or wait some? |
If you see support for case insensitivity going beyond a one-off fix here (which could get by with a compiler lead's (Wesley's) approval), it is probably good to just file a Major Change Proposal (MCP) to propose a specific policy change. This is an issue template at the compiler team repo. That will give you a chance to explain what use case we are currently not supporting well, which specific changes will help improve it, and collect input about it. Please be patient; nobody is saying that this change is not desired or that you should close this PR. Its scope just needs to be better understood if it's not only target spec files that are causing problems. (Which the MCP should help clarify). |
Let me explain it. This patch touches only that part where validation of user- or cargo- input via cli-arg or env, but not any fs exercises like dir-traversal. So before this patch I can't do Well, there is test for user-input only. |
I would recommend waiting a bit to allow Wesley to provide you with better advice on which further steps to take. |
r? @davidtwco Apologies that this got lost in the cracks. I think it's reasonable if niche that we would want to support accepting arbitrary filenames here (with whatever case or extension is provided, as long as we can find the file and parse it). It makes sense for our behaviour here to be consistent, so I would like to make sure that this is feasible anywhere else that we accept filenames from users, and I want to check if @rust-lang/cargo have any concerns with that other than the consistency between cargo/rustc? If they don't, then we can file a MCP to agree on our policy going forward and then see this merged. |
My primary concern was us weighing whether consistency is important. Would this change to rustc be prescriptive for cargo? Whether Cargo should be consistent within itself is another question that would need to be considered and if there is an expectation for Cargo to match then we'd need to block on that decision. Out of curiosity, I just tried to |
Same here. Not only cargo and rustc but toolchain-wise including rustup, clippy and rustfmt. So I would say a policy where we accept where not |
Thinking about this, I do wonder why rustc needs to care about the file extension at all. Should we not just have a |
The main reason I see for an extension check is to allow the format to be inferred if a new one is added in the future. Us validating Another way to frame this is that the current behavior is consistent and we can always change it in the future but it a one-way door that can also constrain future decisions. |
Also, its easy to support case insensitive files when passed in but if a tool wants to support detecting the file, it requires scanning the whole directory. |
Hm, I think this is a case where I would draw a distinction between rustc and Cargo. I think rustc almost never cares about any part of the file name, even the If we want to carve out space for future formats we could have |
That's a good point, they wouldn't necessarily need to be consistent. I think I'd be okay if they weren't. If we're okay with that then it's just a matter of whether t-compiler have an opinion here. |
Cargo PR as second part of this story, waits this PR. This branch looks stale. Should I update or rebase it? |
Probably wait until T-compiler discusses this change in today's triage meeting, the conflict doesn't block the discussions. If the members attending triage meeting don't have immediate concerns, we can proceed by filing an MCP (you can draft one if you prefer, alternatively I can draft one on your behalf). |
Discussed during T-compiler triage on Zulip.
In short, in general we would be in favor of this change, and we would also be happy with an MCP documenting and detailing a bit more the intended scope of this change. (please feel free to add more relevant questions from the meeting) @rustbot label -i-compiler-nominated |
@davidtwco I wanted to check in as my point could have been missed and yours is ambiguous enough. I'm wondering if merging this PR is prescriptive to the Cargo team for merging rust-lang/cargo#14197.
|
I think it's okay for rustc to accept more than Cargo does. I'm entirely happen for Cargo to be more opinionated than rustc in circumstances like this.
I'm not sure this is exactly what we agreed - we're happy to accept a change that checks for target files without the mandatory |
I'm not sure I understand this. If we start supporting TOML spec files, would the compiler use a heuristic to determine which format it is? It seems unlikely that we would just drop JSON. I'm a little confused here. |
It's a good question but I think that's a slightly different issue. The rustc book currently says:
The discussion in the compiler team triage meeting concluded that if you write If we decide to add TOML support (and it seems like that should have been the correct format to use anyway), point 2 will have to be modified to look at the file extension or something. Obviously, that again raises the question of the extension case but our consensus was that if you told rustc to look for |
We could try parse it as JSON and then fall back to TOML if that fails when no extension is provided. |
@boozook |
Currently user's target json file can have only
json
ext, but cannot have `JSON' or any other strange form.This is a little fix with added support of case-insensitive file-ext for user specified target only.
That means that not supported in following cases:
$RUST_TARGET_PATH
rustc_target::spec::Target::search
, so it doesn't work withJSON
on case-sensitive FS, but works fine on case-insensitive FS.$RUST_TARGET_PATH
dir traversal in the bootstrap is not touched too.Performance cost:
Almost without changes.
Comparison using
eq_ignore_ascii_case
for only latest ext_len chars of theOsStr
(as bytes).Testing
How to test:
rustc --print target-spec-json -Zunstable-options > ./some-target.JSON
is-builtin
field from thesome-target.JSON
or set tofalse
rustc --print target-spec-json -Zunstable-options --target=some-target.JSON
should workrustc --print target-spec-json -Zunstable-options --target=some-target
should work on case-insensitive FSrustc --print cfg --target=some-target
should work too, on case-insensitive FSTests added.
Implementation note
I've separated the comparison into a method for potential future use instead of just
str.ends_with(".json")
and to maintain compatibility.The method is public for the same reasons.
Fixes #127387 issue.
try-job: test-various
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: aarch64-apple