Skip to content

Commit 9f081ef

Browse files
committed
auto merge of #725 : alexcrichton/cargo/registry-fixes, r=brson
This PR contains a laundry list of improvements when using the registry as a source, and should be one of the last steps necessary for whipping cargo into shape to using the registry. Some of the highlights include: * All APIs have been updated to the registry's current interface * Lockfiles are now respected with registry sources * Conservatively updating dependencies should work * The network shouldn't be touched unless absolutely necessary * Lockfiles actually keep versions locked when using a newer registry with more versions * A new standalone lib was added for interoperating with the registry (HTTP-request-wise) * Packages are now verified before being published to the registry (this can be opted out of) * `cargo upload` was renamed to `cargo publish` The commit series is intended to be individually reviewable and each commit should compile and pass all tests independently (but still needs to be applied in order).
2 parents 737d9aa + f8acf4e commit 9f081ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2184
-805
lines changed

Cargo.lock

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ git = "https://github.com/alexcrichton/git2-rs"
3939
[dependencies.glob]
4040
git = "https://github.com/rust-lang/glob"
4141

42+
[dependencies.registry]
43+
path = "src/registry"
44+
4245
[[bin]]
4346
name = "cargo"
4447
test = false

src/bin/cargo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ macro_rules! each_subcommand( ($macro:ident) => ({
6868
$macro!(locate_project)
6969
$macro!(login)
7070
$macro!(new)
71+
$macro!(owner)
7172
$macro!(package)
7273
$macro!(pkgid)
74+
$macro!(publish)
7375
$macro!(read_manifest)
7476
$macro!(run)
7577
$macro!(test)
7678
$macro!(update)
77-
$macro!(upload)
7879
$macro!(verify_project)
7980
$macro!(version)
81+
$macro!(yank)
8082
}) )
8183

8284
/**

src/bin/git_checkout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
3030
})
3131
.map_err(|e| CliError::from_boxed(e, 1)));
3232

33-
let source_id = SourceId::for_git(&url, reference.as_slice(), None);
33+
let source_id = SourceId::for_git(&url, reference.as_slice());
3434

3535
let mut config = try!(Config::new(shell, None, None).map_err(|e| {
3636
CliError::from_boxed(e, 1)

src/bin/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
4040
};
4141

4242
let token = token.as_slice().trim().to_string();
43-
try!(ops::upload_login(shell, token).map_err(|e| {
43+
try!(ops::registry_login(shell, token).map_err(|e| {
4444
CliError::from_boxed(e, 101)
4545
}));
4646
Ok(None)

src/bin/owner.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use cargo::ops;
2+
use cargo::core::MultiShell;
3+
use cargo::util::{CliResult, CliError};
4+
use cargo::util::important_paths::find_root_manifest_for_cwd;
5+
6+
#[deriving(Decodable)]
7+
struct Options {
8+
arg_crate: Option<String>,
9+
flag_token: Option<String>,
10+
flag_add: Option<Vec<String>>,
11+
flag_remove: Option<Vec<String>>,
12+
flag_index: Option<String>,
13+
flag_verbose: bool,
14+
}
15+
16+
pub const USAGE: &'static str = "
17+
Manage the owners of a crate on the registry
18+
19+
Usage:
20+
cargo owner [options] [<crate>]
21+
22+
Options:
23+
-h, --help Print this message
24+
-a, --add LOGIN Login of a user to add as an owner
25+
-r, --remove LOGIN Login of a user to remove as an owner
26+
--index INDEX Registry index to modify owners for
27+
--token TOKEN API token to use when authenticating
28+
-v, --verbose Use verbose output
29+
30+
This command will modify the owners for a package on the specified registry (or
31+
default). Note that owners of a package can upload new versions, yank old
32+
versions, and also modify the set of owners, so take caution!
33+
";
34+
35+
pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
36+
shell.set_verbose(options.flag_verbose);
37+
let root = try!(find_root_manifest_for_cwd(None));
38+
try!(ops::modify_owners(&root, shell,
39+
options.arg_crate,
40+
options.flag_token,
41+
options.flag_index,
42+
options.flag_add,
43+
options.flag_remove).map_err(|e| {
44+
CliError::from_boxed(e, 101)
45+
}));
46+
Ok(None)
47+
}
48+
49+

src/bin/package.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cargo::util::important_paths::find_root_manifest_for_cwd;
77
struct Options {
88
flag_verbose: bool,
99
flag_manifest_path: Option<String>,
10+
flag_no_verify: bool,
1011
}
1112

1213
pub const USAGE: &'static str = "
@@ -18,19 +19,15 @@ Usage:
1819
Options:
1920
-h, --help Print this message
2021
--manifest-path PATH Path to the manifest to compile
22+
--no-verify Don't verify the contents by building them
2123
-v, --verbose Use verbose output
2224
2325
";
2426

2527
pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
2628
shell.set_verbose(options.flag_verbose);
27-
let Options {
28-
flag_manifest_path,
29-
..
30-
} = options;
31-
32-
let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone()));
33-
ops::package(&root, shell).map(|_| None).map_err(|err| {
29+
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
30+
ops::package(&root, shell, !options.flag_no_verify).map(|_| None).map_err(|err| {
3431
CliError::from_boxed(err, 101)
3532
})
3633
}

src/bin/upload.rs renamed to src/bin/publish.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ struct Options {
99
flag_token: Option<String>,
1010
flag_manifest_path: Option<String>,
1111
flag_verbose: bool,
12+
flag_no_verify: bool,
1213
}
1314

1415
pub const USAGE: &'static str = "
1516
Upload a package to the registry
1617
1718
Usage:
18-
cargo upload [options]
19+
cargo publish [options]
1920
2021
Options:
2122
-h, --help Print this message
2223
--host HOST Host to upload the package to
2324
--token TOKEN Token to use when uploading
25+
--no-verify Don't verify package tarball before publish
2426
--manifest-path PATH Path to the manifest to compile
2527
-v, --verbose Use verbose output
2628
@@ -32,11 +34,12 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
3234
flag_token: token,
3335
flag_host: host,
3436
flag_manifest_path,
37+
flag_no_verify: no_verify,
3538
..
3639
} = options;
3740

3841
let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone()));
39-
ops::upload(&root, shell, token, host).map(|_| None).map_err(|err| {
42+
ops::publish(&root, shell, token, host, !no_verify).map(|_| None).map_err(|err| {
4043
CliError::from_boxed(err, 101)
4144
})
4245
}

src/bin/yank.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use cargo::ops;
2+
use cargo::core::MultiShell;
3+
use cargo::util::{CliResult, CliError};
4+
use cargo::util::important_paths::find_root_manifest_for_cwd;
5+
6+
#[deriving(Decodable)]
7+
struct Options {
8+
arg_crate: Option<String>,
9+
flag_token: Option<String>,
10+
flag_vers: Option<String>,
11+
flag_index: Option<String>,
12+
flag_verbose: bool,
13+
flag_undo: bool,
14+
}
15+
16+
pub static USAGE: &'static str = "
17+
Remove a pushed crate from the index
18+
19+
Usage:
20+
cargo yank [options] [<crate>]
21+
22+
Options:
23+
-h, --help Print this message
24+
--vers VERSION The version to yank or un-yank
25+
--undo Undo a yank, putting a version back into the index
26+
--index INDEX Registry index to yank from
27+
--token TOKEN API token to use when authenticating
28+
-v, --verbose Use verbose output
29+
30+
The yank command removes a previously pushed crate's version from the server's
31+
index. This command does not delete any data, and the crate will still be
32+
available for download via the registry's download link.
33+
34+
Note that existing crates locked to a yanked version will still be able to
35+
download the yanked version to use it. Cargo will, however, not allow any new
36+
crates to be locked to any yanked version.
37+
";
38+
39+
pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
40+
shell.set_verbose(options.flag_verbose);
41+
let root = try!(find_root_manifest_for_cwd(None));
42+
try!(ops::yank(&root, shell,
43+
options.arg_crate,
44+
options.flag_vers,
45+
options.flag_token,
46+
options.flag_index,
47+
options.flag_undo).map_err(|e| {
48+
CliError::from_boxed(e, 101)
49+
}));
50+
Ok(None)
51+
}
52+
53+
54+

src/cargo/core/dependency.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use core::{SourceId,Summary};
21
use semver::VersionReq;
2+
3+
use core::{SourceId, Summary, PackageId};
34
use util::CargoResult;
45

56
/// Informations about a dependency requested by a Cargo manifest.
@@ -8,6 +9,7 @@ pub struct Dependency {
89
name: String,
910
source_id: SourceId,
1011
req: VersionReq,
12+
specified_req: Option<String>,
1113
transitive: bool,
1214
only_match_name: bool,
1315

@@ -31,14 +33,15 @@ impl Dependency {
3133
pub fn parse(name: &str,
3234
version: Option<&str>,
3335
source_id: &SourceId) -> CargoResult<Dependency> {
34-
let version = match version {
36+
let version_req = match version {
3537
Some(v) => try!(VersionReq::parse(v)),
3638
None => VersionReq::any()
3739
};
3840

3941
Ok(Dependency {
4042
only_match_name: false,
41-
req: version,
43+
req: version_req,
44+
specified_req: version.map(|s| s.to_string()),
4245
.. Dependency::new_override(name, source_id)
4346
})
4447
}
@@ -53,6 +56,7 @@ impl Dependency {
5356
optional: false,
5457
features: Vec::new(),
5558
default_features: true,
59+
specified_req: None,
5660
}
5761
}
5862

@@ -61,6 +65,10 @@ impl Dependency {
6165
&self.req
6266
}
6367

68+
pub fn get_specified_req(&self) -> Option<&str> {
69+
self.specified_req.as_ref().map(|s| s.as_slice())
70+
}
71+
6472
pub fn get_name(&self) -> &str {
6573
self.name.as_slice()
6674
}
@@ -93,6 +101,26 @@ impl Dependency {
93101
self
94102
}
95103

104+
/// Set the source id for this dependency
105+
pub fn source_id(mut self, id: SourceId) -> Dependency {
106+
self.source_id = id;
107+
self
108+
}
109+
110+
/// Set the version requirement for this dependency
111+
pub fn version_req(mut self, req: VersionReq) -> Dependency {
112+
self.req = req;
113+
self
114+
}
115+
116+
/// Lock this dependency to depending on the specified package id
117+
pub fn lock_to(self, id: &PackageId) -> Dependency {
118+
assert_eq!(self.source_id, *id.get_source_id());
119+
assert!(self.req.matches(id.get_version()));
120+
self.version_req(VersionReq::exact(id.get_version()))
121+
.source_id(id.get_source_id().clone())
122+
}
123+
96124
/// Returns false if the dependency is only used to build the local package.
97125
pub fn is_transitive(&self) -> bool { self.transitive }
98126
pub fn is_optional(&self) -> bool { self.optional }
@@ -103,12 +131,14 @@ impl Dependency {
103131

104132
/// Returns true if the package (`sum`) can fulfill this dependency request.
105133
pub fn matches(&self, sum: &Summary) -> bool {
106-
debug!("matches; self={}; summary={}", self, sum);
107-
debug!(" a={}; b={}", self.source_id, sum.get_source_id());
134+
self.matches_id(sum.get_package_id())
135+
}
108136

109-
self.name.as_slice() == sum.get_name() &&
110-
(self.only_match_name || (self.req.matches(sum.get_version()) &&
111-
&self.source_id == sum.get_source_id()))
137+
/// Returns true if the package (`id`) can fulfill this dependency request.
138+
pub fn matches_id(&self, id: &PackageId) -> bool {
139+
self.name.as_slice() == id.get_name() &&
140+
(self.only_match_name || (self.req.matches(id.get_version()) &&
141+
&self.source_id == id.get_source_id()))
112142
}
113143
}
114144

0 commit comments

Comments
 (0)