Skip to content

Commit

Permalink
auto merge of #725 : alexcrichton/cargo/registry-fixes, r=brson
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
bors committed Oct 27, 2014
2 parents 737d9aa + f8acf4e commit 9f081ef
Show file tree
Hide file tree
Showing 48 changed files with 2,184 additions and 805 deletions.
22 changes: 15 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ git = "https://github.com/alexcrichton/git2-rs"
[dependencies.glob]
git = "https://github.com/rust-lang/glob"

[dependencies.registry]
path = "src/registry"

[[bin]]
name = "cargo"
test = false
Expand Down
4 changes: 3 additions & 1 deletion src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ macro_rules! each_subcommand( ($macro:ident) => ({
$macro!(locate_project)
$macro!(login)
$macro!(new)
$macro!(owner)
$macro!(package)
$macro!(pkgid)
$macro!(publish)
$macro!(read_manifest)
$macro!(run)
$macro!(test)
$macro!(update)
$macro!(upload)
$macro!(verify_project)
$macro!(version)
$macro!(yank)
}) )

/**
Expand Down
2 changes: 1 addition & 1 deletion src/bin/git_checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
})
.map_err(|e| CliError::from_boxed(e, 1)));

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

let mut config = try!(Config::new(shell, None, None).map_err(|e| {
CliError::from_boxed(e, 1)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
};

let token = token.as_slice().trim().to_string();
try!(ops::upload_login(shell, token).map_err(|e| {
try!(ops::registry_login(shell, token).map_err(|e| {
CliError::from_boxed(e, 101)
}));
Ok(None)
Expand Down
49 changes: 49 additions & 0 deletions src/bin/owner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use cargo::ops;
use cargo::core::MultiShell;
use cargo::util::{CliResult, CliError};
use cargo::util::important_paths::find_root_manifest_for_cwd;

#[deriving(Decodable)]
struct Options {
arg_crate: Option<String>,
flag_token: Option<String>,
flag_add: Option<Vec<String>>,
flag_remove: Option<Vec<String>>,
flag_index: Option<String>,
flag_verbose: bool,
}

pub const USAGE: &'static str = "
Manage the owners of a crate on the registry
Usage:
cargo owner [options] [<crate>]
Options:
-h, --help Print this message
-a, --add LOGIN Login of a user to add as an owner
-r, --remove LOGIN Login of a user to remove as an owner
--index INDEX Registry index to modify owners for
--token TOKEN API token to use when authenticating
-v, --verbose Use verbose output
This command will modify the owners for a package on the specified registry (or
default). Note that owners of a package can upload new versions, yank old
versions, and also modify the set of owners, so take caution!
";

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
shell.set_verbose(options.flag_verbose);
let root = try!(find_root_manifest_for_cwd(None));
try!(ops::modify_owners(&root, shell,
options.arg_crate,
options.flag_token,
options.flag_index,
options.flag_add,
options.flag_remove).map_err(|e| {
CliError::from_boxed(e, 101)
}));
Ok(None)
}


11 changes: 4 additions & 7 deletions src/bin/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cargo::util::important_paths::find_root_manifest_for_cwd;
struct Options {
flag_verbose: bool,
flag_manifest_path: Option<String>,
flag_no_verify: bool,
}

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

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
shell.set_verbose(options.flag_verbose);
let Options {
flag_manifest_path,
..
} = options;

let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone()));
ops::package(&root, shell).map(|_| None).map_err(|err| {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
ops::package(&root, shell, !options.flag_no_verify).map(|_| None).map_err(|err| {
CliError::from_boxed(err, 101)
})
}
7 changes: 5 additions & 2 deletions src/bin/upload.rs → src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ struct Options {
flag_token: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_no_verify: bool,
}

pub const USAGE: &'static str = "
Upload a package to the registry
Usage:
cargo upload [options]
cargo publish [options]
Options:
-h, --help Print this message
--host HOST Host to upload the package to
--token TOKEN Token to use when uploading
--no-verify Don't verify package tarball before publish
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output
Expand All @@ -32,11 +34,12 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
flag_token: token,
flag_host: host,
flag_manifest_path,
flag_no_verify: no_verify,
..
} = options;

let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone()));
ops::upload(&root, shell, token, host).map(|_| None).map_err(|err| {
ops::publish(&root, shell, token, host, !no_verify).map(|_| None).map_err(|err| {
CliError::from_boxed(err, 101)
})
}
54 changes: 54 additions & 0 deletions src/bin/yank.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use cargo::ops;
use cargo::core::MultiShell;
use cargo::util::{CliResult, CliError};
use cargo::util::important_paths::find_root_manifest_for_cwd;

#[deriving(Decodable)]
struct Options {
arg_crate: Option<String>,
flag_token: Option<String>,
flag_vers: Option<String>,
flag_index: Option<String>,
flag_verbose: bool,
flag_undo: bool,
}

pub static USAGE: &'static str = "
Remove a pushed crate from the index
Usage:
cargo yank [options] [<crate>]
Options:
-h, --help Print this message
--vers VERSION The version to yank or un-yank
--undo Undo a yank, putting a version back into the index
--index INDEX Registry index to yank from
--token TOKEN API token to use when authenticating
-v, --verbose Use verbose output
The yank command removes a previously pushed crate's version from the server's
index. This command does not delete any data, and the crate will still be
available for download via the registry's download link.
Note that existing crates locked to a yanked version will still be able to
download the yanked version to use it. Cargo will, however, not allow any new
crates to be locked to any yanked version.
";

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
shell.set_verbose(options.flag_verbose);
let root = try!(find_root_manifest_for_cwd(None));
try!(ops::yank(&root, shell,
options.arg_crate,
options.flag_vers,
options.flag_token,
options.flag_index,
options.flag_undo).map_err(|e| {
CliError::from_boxed(e, 101)
}));
Ok(None)
}



46 changes: 38 additions & 8 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::{SourceId,Summary};
use semver::VersionReq;

use core::{SourceId, Summary, PackageId};
use util::CargoResult;

/// Informations about a dependency requested by a Cargo manifest.
Expand All @@ -8,6 +9,7 @@ pub struct Dependency {
name: String,
source_id: SourceId,
req: VersionReq,
specified_req: Option<String>,
transitive: bool,
only_match_name: bool,

Expand All @@ -31,14 +33,15 @@ impl Dependency {
pub fn parse(name: &str,
version: Option<&str>,
source_id: &SourceId) -> CargoResult<Dependency> {
let version = match version {
let version_req = match version {
Some(v) => try!(VersionReq::parse(v)),
None => VersionReq::any()
};

Ok(Dependency {
only_match_name: false,
req: version,
req: version_req,
specified_req: version.map(|s| s.to_string()),
.. Dependency::new_override(name, source_id)
})
}
Expand All @@ -53,6 +56,7 @@ impl Dependency {
optional: false,
features: Vec::new(),
default_features: true,
specified_req: None,
}
}

Expand All @@ -61,6 +65,10 @@ impl Dependency {
&self.req
}

pub fn get_specified_req(&self) -> Option<&str> {
self.specified_req.as_ref().map(|s| s.as_slice())
}

pub fn get_name(&self) -> &str {
self.name.as_slice()
}
Expand Down Expand Up @@ -93,6 +101,26 @@ impl Dependency {
self
}

/// Set the source id for this dependency
pub fn source_id(mut self, id: SourceId) -> Dependency {
self.source_id = id;
self
}

/// Set the version requirement for this dependency
pub fn version_req(mut self, req: VersionReq) -> Dependency {
self.req = req;
self
}

/// Lock this dependency to depending on the specified package id
pub fn lock_to(self, id: &PackageId) -> Dependency {
assert_eq!(self.source_id, *id.get_source_id());
assert!(self.req.matches(id.get_version()));
self.version_req(VersionReq::exact(id.get_version()))
.source_id(id.get_source_id().clone())
}

/// Returns false if the dependency is only used to build the local package.
pub fn is_transitive(&self) -> bool { self.transitive }
pub fn is_optional(&self) -> bool { self.optional }
Expand All @@ -103,12 +131,14 @@ impl Dependency {

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

self.name.as_slice() == sum.get_name() &&
(self.only_match_name || (self.req.matches(sum.get_version()) &&
&self.source_id == sum.get_source_id()))
/// Returns true if the package (`id`) can fulfill this dependency request.
pub fn matches_id(&self, id: &PackageId) -> bool {
self.name.as_slice() == id.get_name() &&
(self.only_match_name || (self.req.matches(id.get_version()) &&
&self.source_id == id.get_source_id()))
}
}

Expand Down
Loading

0 comments on commit 9f081ef

Please sign in to comment.