Skip to content

Commit

Permalink
Adding support for no-default-features to package and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
spacekookie committed Jan 9, 2019
1 parent 8c3bf82 commit b29e379
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/bin/cargo/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
jobs: args.jobs()?,
features: args._values_of("features"),
all_features: args.is_present("all-features"),
no_default_features: args.is_present("no-default-features"),
},
)?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
registry,
features: args._values_of("features"),
all_features: args.is_present("all-features"),
no_default_features: args.is_present("no-default-features"),
},
)?;
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct PackageOpts<'cfg> {
pub target: Option<String>,
pub features: Vec<String>,
pub all_features: bool,
pub no_default_features: bool,
}

static VCS_INFO_FILE: &'static str = ".cargo_vcs_info.json";
Expand Down Expand Up @@ -450,7 +451,7 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
config,
build_config: BuildConfig::new(config, opts.jobs, &opts.target, CompileMode::Build)?,
features: opts.features.clone(),
no_default_features: false,
no_default_features: opts.no_default_features,
all_features: opts.all_features,
spec: ops::Packages::Packages(Vec::new()),
filter: ops::CompileFilter::Default {
Expand Down
4 changes: 3 additions & 1 deletion src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ pub struct PublishOpts<'cfg> {
pub dry_run: bool,
pub registry: Option<String>,
pub features: Vec<String>,
pub all_features: bool
pub all_features: bool,
pub no_default_features: bool,
}

pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
Expand Down Expand Up @@ -86,6 +87,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
jobs: opts.jobs,
features: opts.features.clone(),
all_features: opts.all_features,
no_default_features: opts.no_default_features,
},
)?
.unwrap();
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,3 +1358,34 @@ fn package_with_all_features() {
.with_status(0)
.run();
}

#[test]
fn package_no_default_features() {
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
[features]
default = ["required"]
required = []
"#,
).file(
"src/main.rs",
"#[cfg(not(feature = \"required\"))]
compile_error!(\"This crate requires `required` feature!\");
fn main() {}",
).build();

p.cargo("package --no-default-features")
.masquerade_as_nightly_cargo()
.with_stderr_contains("error: This crate requires `required` feature!")
.with_status(101)
.run();
}
80 changes: 65 additions & 15 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ See [..]
[UPLOADING] foo v0.0.1 ([CWD])
",
reg = publish::registry_path().to_str().unwrap()
)).run();
))
.run();

let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
Expand Down Expand Up @@ -112,7 +113,8 @@ See [..]
[UPLOADING] foo v0.0.1 ([CWD])
",
reg = publish::registry_path().to_str().unwrap()
)).run();
))
.run();

let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
Expand Down Expand Up @@ -188,7 +190,8 @@ See [..]
[UPLOADING] foo v0.0.1 ([CWD])
",
reg = publish::registry_path().to_str().unwrap()
)).run();
))
.run();

let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
Expand Down Expand Up @@ -266,7 +269,8 @@ See [..]
[UPLOADING] foo v0.0.1 ([CWD])
",
reg = publish::registry_path().to_str().unwrap()
)).run();
))
.run();

let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
Expand Down Expand Up @@ -335,7 +339,8 @@ specify a crates.io version as a dependency or pull it into this \
repository and specify it with a path and version\n\
(crate `foo` has repository path `git://path/to/nowhere`)\
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -371,7 +376,8 @@ fn path_dependency_no_version() {
[ERROR] all path dependencies must have a version specified when publishing.
dependency `bar` does not specify a version
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -402,7 +408,8 @@ fn unpublishable_crate() {
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -441,7 +448,8 @@ bar
to proceed despite this, pass the `--allow-dirty` flag
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -555,7 +563,8 @@ fn ignore_when_crate_ignored() {
homepage = "foo"
repository = "foo"
"#,
).nocommit_file("bar/src/main.rs", "fn main() {}");
)
.nocommit_file("bar/src/main.rs", "fn main() {}");
p.cargo("publish")
.cwd(p.root().join("bar"))
.arg("--index")
Expand Down Expand Up @@ -583,7 +592,8 @@ fn new_crate_rejected() {
homepage = "foo"
repository = "foo"
"#,
).nocommit_file("src/main.rs", "fn main() {}");
)
.nocommit_file("src/main.rs", "fn main() {}");
p.cargo("publish --index")
.arg(publish::registry().to_string())
.with_status(101)
Expand Down Expand Up @@ -623,7 +633,8 @@ See [..]
[UPLOADING] foo v0.0.1 ([CWD])
[WARNING] aborting upload due to dry run
",
).run();
)
.run();

// Ensure the API request wasn't actually made
assert!(!publish::upload_path().join("api/v1/crates/new").exists());
Expand Down Expand Up @@ -666,7 +677,8 @@ Caused by:
consider adding `cargo-features = [\"alternative-registries\"]` to the manifest
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -704,7 +716,8 @@ fn registry_not_in_publish_list() {
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -737,7 +750,8 @@ fn publish_empty_list() {
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -801,7 +815,8 @@ fn block_publish_no_registry() {
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
",
).run();
)
.run();
}

#[test]
Expand Down Expand Up @@ -871,3 +886,38 @@ fn publish_with_all_features() {
.with_stderr_contains("[UPLOADING] foo v0.0.1 ([CWD])")
.run();
}

#[test]
fn publish_with_no_default_features() {
publish::setup();

let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
[features]
default = ["required"]
required = []
"#,
)
.file(
"src/main.rs",
"#[cfg(not(feature = \"required\"))]
compile_error!(\"This crate requires `required` feature!\");
fn main() {}",
)
.build();

p.cargo("publish --no-default-features --index")
.arg(publish::registry().to_string())
.with_stderr_contains("error: This crate requires `required` feature!")
.with_status(101)
.run();
}

0 comments on commit b29e379

Please sign in to comment.