Skip to content

Commit

Permalink
Auto merge of #3089 - carols10cents:crates-io-registry-url, r=alexcri…
Browse files Browse the repository at this point in the history
…chton

Make crates-io registry URL optional in config; ignore all changes to source.crates-io

Hi! When I was working on the instructions for source replacement [in this crates.io PR](rust-lang/crates.io#440), I found that when I'm replacing `source.crates-io`, [I still have to specify some value for `registry`](https://github.com/rust-lang/crates.io/pull/440/files#diff-04c6e90faac2675aa89e2176d2eec7d8R177), or else I get this:

```
error: no source URL specified for `source.crates-io`, need either `registry` or `local-registry` defined
```

This seems weird and annoying to me: cargo definitely knows the registry URL for crates-io, and I'm trying to replace it anyway.

So the first commit in this PR makes it optional, so that you don't have to specify a registry url for crates-io: it uses `SourceId::crates_io`, like it would if we didn't have any source configs at all.

~~The second commit in this PR might go too far, and/or might break existing uses of cargo, I'm not sure. In my opinion, `source.crates-io` should only be able to be replaced and never changed directly-- crates-io should always be crates-io, and I should be able to assume that in any project. So the second commit ignores all modifications to `source.crates-io`'s `registry`, `local-registry`, and `directory`, and warns that they're being ignored.~~

~~I tried to search github to see if anyone was using these keys with `source.crates-io`, but since github's search ignores `.` (ARE YOU LISTENING GITHUB? I WOULD LIKE TO SEARCH WITH PUNCTUATION PLEASE), there's a lot of false positives to wade through. I didn't see anything in the first few pages though.~~

I'm happy to make whatever modifications to this!
  • Loading branch information
bors committed Sep 27, 2016
2 parents 4215ef8 + 2490f3f commit 26dcd3e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ a lock file compatible with `{orig}` cannot be generated in this situation
path.push(s);
srcs.push(try!(SourceId::for_directory(&path)));
}
if name == "crates-io" && srcs.is_empty() {
srcs.push(try!(SourceId::crates_io(self.config)));
}

let mut srcs = srcs.into_iter();
let src = try!(srcs.next().chain_error(|| {
Expand Down
48 changes: 48 additions & 0 deletions tests/local-registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,51 @@ unable to verify that `foo v0.0.1` is the same as when the lockfile was generate
"));
}

#[test]
fn crates_io_registry_url_is_optional() {
let root = paths::root();
t!(fs::create_dir(&root.join(".cargo")));
t!(t!(File::create(root.join(".cargo/config"))).write_all(br#"
[source.crates-io]
replace-with = 'my-awesome-local-registry'
[source.my-awesome-local-registry]
local-registry = 'registry'
"#));

Package::new("foo", "0.0.1")
.local(true)
.file("src/lib.rs", "pub fn foo() {}")
.publish();

let p = project("bar")
.file("Cargo.toml", r#"
[project]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
foo = "0.0.1"
"#)
.file("src/lib.rs", r#"
extern crate foo;
pub fn bar() {
foo::foo();
}
"#);

assert_that(p.cargo_process("build"),
execs().with_status(0).with_stderr(&format!("\
[UNPACKING] foo v0.0.1 ([..])
[COMPILING] foo v0.0.1
[COMPILING] bar v0.0.1 ({dir})
[FINISHED] [..]
",
dir = p.url())));
assert_that(p.cargo("build"), execs().with_status(0).with_stderr("\
[FINISHED] [..]
"));
assert_that(p.cargo("test"), execs().with_status(0));
}

0 comments on commit 26dcd3e

Please sign in to comment.