Skip to content

Commit b78beb1

Browse files
authored
Auto merge of #3060 - rillian:package_path_deps, r=alexcrichton
Reject path-based dependencies in `cargo package` `cargo publish` will complain if a package manifest contains a path, rather than registry+version-based dependency. Make `cargo package` do the same so that issue is caught sooner in developer workflow.
2 parents 8c2250f + 3227546 commit b78beb1

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub fn package(ws: &Workspace,
3535
try!(check_metadata(pkg, config));
3636
}
3737

38+
try!(verify_dependencies(&pkg));
39+
3840
if opts.list {
3941
let root = pkg.root();
4042
let mut list: Vec<_> = try!(src.list_files(&pkg)).iter().map(|file| {
@@ -112,13 +114,27 @@ fn check_metadata(pkg: &Package, config: &Config) -> CargoResult<()> {
112114
things.push_str(&missing.last().unwrap());
113115

114116
try!(config.shell().warn(
115-
&format!("manifest has no {things}. \
117+
&format!("manifest has no {things}.\n\
116118
See http://doc.crates.io/manifest.html#package-metadata for more info.",
117119
things = things)))
118120
}
119121
Ok(())
120122
}
121123

124+
// check that the package dependencies are safe to deploy.
125+
fn verify_dependencies(pkg: &Package) -> CargoResult<()> {
126+
for dep in pkg.dependencies() {
127+
if dep.source_id().is_path() {
128+
if !dep.specified_req() {
129+
bail!("all path dependencies must have a version specified \
130+
when packaging.\ndependency `{}` does not specify \
131+
a version.", dep.name())
132+
}
133+
}
134+
}
135+
Ok(())
136+
}
137+
122138
fn check_not_dirty(p: &Package, src: &PathSource) -> CargoResult<()> {
123139
if let Ok(repo) = git2::Repository::discover(p.root()) {
124140
if let Some(workdir) = repo.workdir() {

tests/package.rs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn simple() {
3737
assert_that(p.cargo_process("package"),
3838
execs().with_status(0).with_stderr(&format!("\
3939
[WARNING] manifest has no documentation[..]
40+
See [..]
4041
[PACKAGING] foo v0.0.1 ({dir})
4142
[VERIFYING] foo v0.0.1 ({dir})
4243
[COMPILING] foo v0.0.1 ({dir}[..])
@@ -82,8 +83,8 @@ fn metadata_warning() {
8283
assert_that(p.cargo_process("package"),
8384
execs().with_status(0).with_stderr(&format!("\
8485
warning: manifest has no description, license, license-file, documentation, \
85-
homepage or repository. See \
86-
http://doc.crates.io/manifest.html#package-metadata for more info.
86+
homepage or repository.
87+
See http://doc.crates.io/manifest.html#package-metadata for more info.
8788
[PACKAGING] foo v0.0.1 ({dir})
8889
[VERIFYING] foo v0.0.1 ({dir})
8990
[COMPILING] foo v0.0.1 ({dir}[..])
@@ -104,8 +105,8 @@ http://doc.crates.io/manifest.html#package-metadata for more info.
104105
"#);
105106
assert_that(p.cargo_process("package"),
106107
execs().with_status(0).with_stderr(&format!("\
107-
warning: manifest has no description, documentation, homepage or repository. See \
108-
http://doc.crates.io/manifest.html#package-metadata for more info.
108+
warning: manifest has no description, documentation, homepage or repository.
109+
See http://doc.crates.io/manifest.html#package-metadata for more info.
109110
[PACKAGING] foo v0.0.1 ({dir})
110111
[VERIFYING] foo v0.0.1 ({dir})
111112
[COMPILING] foo v0.0.1 ({dir}[..])
@@ -165,6 +166,7 @@ fn package_verbose() {
165166
assert_that(cargo.clone().arg("package").arg("-v").arg("--no-verify"),
166167
execs().with_status(0).with_stderr("\
167168
[WARNING] manifest has no description[..]
169+
See http://doc.crates.io/manifest.html#package-metadata for more info.
168170
[PACKAGING] foo v0.0.1 ([..])
169171
[ARCHIVING] [..]
170172
[ARCHIVING] [..]
@@ -175,6 +177,7 @@ fn package_verbose() {
175177
.cwd(p.root().join("a")),
176178
execs().with_status(0).with_stderr("\
177179
[WARNING] manifest has no description[..]
180+
See http://doc.crates.io/manifest.html#package-metadata for more info.
178181
[PACKAGING] a v0.0.1 ([..])
179182
[ARCHIVING] [..]
180183
[ARCHIVING] [..]
@@ -198,6 +201,7 @@ fn package_verification() {
198201
assert_that(p.cargo("package"),
199202
execs().with_status(0).with_stderr(&format!("\
200203
[WARNING] manifest has no description[..]
204+
See http://doc.crates.io/manifest.html#package-metadata for more info.
201205
[PACKAGING] foo v0.0.1 ({dir})
202206
[VERIFYING] foo v0.0.1 ({dir})
203207
[COMPILING] foo v0.0.1 ({dir}[..])
@@ -206,6 +210,38 @@ fn package_verification() {
206210
dir = p.url())));
207211
}
208212

213+
#[test]
214+
fn path_dependency_no_version() {
215+
let p = project("foo")
216+
.file("Cargo.toml", r#"
217+
[project]
218+
name = "foo"
219+
version = "0.0.1"
220+
authors = []
221+
license = "MIT"
222+
description = "foo"
223+
224+
[dependencies.bar]
225+
path = "bar"
226+
"#)
227+
.file("src/main.rs", "fn main() {}")
228+
.file("bar/Cargo.toml", r#"
229+
[package]
230+
name = "bar"
231+
version = "0.0.1"
232+
authors = []
233+
"#)
234+
.file("bar/src/lib.rs", "");
235+
236+
assert_that(p.cargo_process("package"),
237+
execs().with_status(101).with_stderr("\
238+
[WARNING] manifest has no documentation, homepage or repository.
239+
See http://doc.crates.io/manifest.html#package-metadata for more info.
240+
[ERROR] all path dependencies must have a version specified when packaging.
241+
dependency `bar` does not specify a version.
242+
"));
243+
}
244+
209245
#[test]
210246
fn exclude() {
211247
let p = project("foo")
@@ -225,6 +261,7 @@ fn exclude() {
225261
assert_that(p.cargo_process("package").arg("--no-verify").arg("-v"),
226262
execs().with_status(0).with_stderr("\
227263
[WARNING] manifest has no description[..]
264+
See http://doc.crates.io/manifest.html#package-metadata for more info.
228265
[PACKAGING] foo v0.0.1 ([..])
229266
[ARCHIVING] [..]
230267
[ARCHIVING] [..]
@@ -251,6 +288,7 @@ fn include() {
251288
assert_that(p.cargo_process("package").arg("--no-verify").arg("-v"),
252289
execs().with_status(0).with_stderr("\
253290
[WARNING] manifest has no description[..]
291+
See http://doc.crates.io/manifest.html#package-metadata for more info.
254292
[PACKAGING] foo v0.0.1 ([..])
255293
[ARCHIVING] [..]
256294
[ARCHIVING] [..]
@@ -360,6 +398,7 @@ fn ignore_nested() {
360398
assert_that(p.cargo_process("package"),
361399
execs().with_status(0).with_stderr(&format!("\
362400
[WARNING] manifest has no documentation[..]
401+
See http://doc.crates.io/manifest.html#package-metadata for more info.
363402
[PACKAGING] nested v0.0.1 ({dir})
364403
[VERIFYING] nested v0.0.1 ({dir})
365404
[COMPILING] nested v0.0.1 ({dir}[..])
@@ -408,6 +447,7 @@ fn package_weird_characters() {
408447
assert_that(p.cargo_process("package"),
409448
execs().with_status(101).with_stderr("\
410449
warning: [..]
450+
See [..]
411451
[PACKAGING] foo [..]
412452
[ERROR] failed to prepare local package for uploading
413453
@@ -448,6 +488,7 @@ fn repackage_on_source_change() {
448488
// Check that cargo rebuilds the tarball
449489
assert_that(pro, execs().with_status(0).with_stderr(&format!("\
450490
[WARNING] [..]
491+
See [..]
451492
[PACKAGING] foo v0.0.1 ({dir})
452493
[VERIFYING] foo v0.0.1 ({dir})
453494
[COMPILING] foo v0.0.1 ({dir}[..])

tests/publish.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fn simple() {
6060
execs().with_status(0).with_stderr(&format!("\
6161
[UPDATING] registry `{reg}`
6262
[WARNING] manifest has no documentation, [..]
63+
See [..]
6364
[PACKAGING] foo v0.0.1 ({dir})
6465
[UPLOADING] foo v0.0.1 ({dir})
6566
",
@@ -357,6 +358,7 @@ fn dry_run() {
357358
execs().with_status(0).with_stderr(&format!("\
358359
[UPDATING] registry `[..]`
359360
[WARNING] manifest has no documentation, [..]
361+
See [..]
360362
[PACKAGING] foo v0.0.1 ({dir})
361363
[VERIFYING] foo v0.0.1 ({dir})
362364
[COMPILING] foo v0.0.1 [..]

0 commit comments

Comments
 (0)