-
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
Support relative URLs, closes #2252 #2253
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
match spec.to_url() { | ||
Ok(url) => return PackageIdSpec::from_url(url), | ||
Err(..) => {} | ||
} | ||
if !spec.contains("://") { |
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 had to move this up so that support for auto-inserting cargo://
runs before the attempt to parse the URL.
The good_parsing()
test (in src/cargo/core/package_id_spec.rs
) catches this:
ok("crates.io/foo", PackageIdSpec {
name: "foo".to_string(),
version: None,
url: Some(url("cargo://crates.io/foo").unwrap()),
});
Without this change, "crates.io/foo" would be parsed as a relative path to the current directory.
6ac87dd
to
c1f71fc
Compare
I think this is ready for some feedback. The build is failing on nightly, but I don't think that's me. |
@@ -40,3 +60,38 @@ fn mapper(s: &str) -> url::SchemeType { | |||
s => url::whatwg_scheme_type_mapper(s), | |||
} | |||
} | |||
|
|||
fn determine_base_url() -> Result<Url, String> { | |||
let current_dir = try!(env::current_dir().map_err(|s| { |
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.
It seems like it should be relative to the file that contains the URL rather than the directory cargo is invoked in?
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.
There are roughly 3 options, I think:
- Relative to the current working directory (as is). Shouldn't be too surprising to people, but I think it would mean that
cargo build
would now only work if you're in the project root. I think this is a regression. - Relative to the project root.
- Relative to the file that defines the URL (your suggestion).
I'm most in favor of option 2. However, both 2/3 would require plumbing. In option 3, all calls to to_url
would require an additional argument. In option 2, we could use CARGO_MANIFEST_DIR
to avoid the additional argument.
This may be a bit heavy-handed for adding support, as there's a number of locations throughout Cargo which rely on this path returning an error for relative paths. I'm a little skeptical that we want to fix the issue in question right now because the |
@alexcrichton is there something we can do that helps move towards #2212 but isn't quite a full blown implementation of a new registry type? For example, in #2212 I'd imagine there would be either a new protocol (e.g. |
Hm ok, this seems reasonable to land in the meantime then. Would it be possible to isolate this logic to just that of parsing |
Just to confirm (we spoke on IRC): this doesn't require adding a new scheme, just isolating the relative support to just that key. Would you like this to be relative to the |
Ah I'd make it relative to the directory containing the |
This commit adds a `ToUrlWithBase` trait which is used when parsing the value of `registry.index` from a Cargo config file. The base url is the file that contained the URL. The net effect is that you can now use relative URLs when specifying a registry.
I took a crack at this. It worked on a test repository but I haven't added tests yet. Before:
After
Note in the second case it still failed to build (I don't have a test repository setup), but the path was right. I've started on adding a test but was fighting with |
Yeah this is looking pretty good to me, let me know if you need any help writing tests! It's also fine to avoid a whole new trait for just one caller, that method can just be inlined somewhere. |
I was going to inline it and then I wasn't sure if making |
Ah you may want to make a helper method in the url module to create the parser, but that shouldn't be too bad. |
Good idea. Will do. I don't need help with the tests, I just ran out of time. Basically, |
☔ The latest upstream changes (presumably #2486) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing due to inactivity, but feel free to resubmit with a rebase! |
See #2252 for a description of the problem.
This PR adds support for having a relative URL to a registry. The registry is considered relative to the
.cargo/config
file that defined the URL.