mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Adding support for no-default-features
to package and publish
This commit is contained in:
parent
8c3bf82f8e
commit
b29e37968a
@ -45,6 +45,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
|||||||
jobs: args.jobs()?,
|
jobs: args.jobs()?,
|
||||||
features: args._values_of("features"),
|
features: args._values_of("features"),
|
||||||
all_features: args.is_present("all-features"),
|
all_features: args.is_present("all-features"),
|
||||||
|
no_default_features: args.is_present("no-default-features"),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -43,6 +43,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
|||||||
registry,
|
registry,
|
||||||
features: args._values_of("features"),
|
features: args._values_of("features"),
|
||||||
all_features: args.is_present("all-features"),
|
all_features: args.is_present("all-features"),
|
||||||
|
no_default_features: args.is_present("no-default-features"),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -28,6 +28,7 @@ pub struct PackageOpts<'cfg> {
|
|||||||
pub target: Option<String>,
|
pub target: Option<String>,
|
||||||
pub features: Vec<String>,
|
pub features: Vec<String>,
|
||||||
pub all_features: bool,
|
pub all_features: bool,
|
||||||
|
pub no_default_features: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
static VCS_INFO_FILE: &'static str = ".cargo_vcs_info.json";
|
static VCS_INFO_FILE: &'static str = ".cargo_vcs_info.json";
|
||||||
@ -450,7 +451,7 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
|
|||||||
config,
|
config,
|
||||||
build_config: BuildConfig::new(config, opts.jobs, &opts.target, CompileMode::Build)?,
|
build_config: BuildConfig::new(config, opts.jobs, &opts.target, CompileMode::Build)?,
|
||||||
features: opts.features.clone(),
|
features: opts.features.clone(),
|
||||||
no_default_features: false,
|
no_default_features: opts.no_default_features,
|
||||||
all_features: opts.all_features,
|
all_features: opts.all_features,
|
||||||
spec: ops::Packages::Packages(Vec::new()),
|
spec: ops::Packages::Packages(Vec::new()),
|
||||||
filter: ops::CompileFilter::Default {
|
filter: ops::CompileFilter::Default {
|
||||||
|
@ -40,7 +40,8 @@ pub struct PublishOpts<'cfg> {
|
|||||||
pub dry_run: bool,
|
pub dry_run: bool,
|
||||||
pub registry: Option<String>,
|
pub registry: Option<String>,
|
||||||
pub features: Vec<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<()> {
|
pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
|
||||||
@ -86,6 +87,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
|
|||||||
jobs: opts.jobs,
|
jobs: opts.jobs,
|
||||||
features: opts.features.clone(),
|
features: opts.features.clone(),
|
||||||
all_features: opts.all_features,
|
all_features: opts.all_features,
|
||||||
|
no_default_features: opts.no_default_features,
|
||||||
},
|
},
|
||||||
)?
|
)?
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1358,3 +1358,34 @@ fn package_with_all_features() {
|
|||||||
.with_status(0)
|
.with_status(0)
|
||||||
.run();
|
.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();
|
||||||
|
}
|
||||||
|
@ -38,7 +38,8 @@ See [..]
|
|||||||
[UPLOADING] foo v0.0.1 ([CWD])
|
[UPLOADING] foo v0.0.1 ([CWD])
|
||||||
",
|
",
|
||||||
reg = publish::registry_path().to_str().unwrap()
|
reg = publish::registry_path().to_str().unwrap()
|
||||||
)).run();
|
))
|
||||||
|
.run();
|
||||||
|
|
||||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||||
// Skip the metadata payload and the size of the tarball
|
// Skip the metadata payload and the size of the tarball
|
||||||
@ -112,7 +113,8 @@ See [..]
|
|||||||
[UPLOADING] foo v0.0.1 ([CWD])
|
[UPLOADING] foo v0.0.1 ([CWD])
|
||||||
",
|
",
|
||||||
reg = publish::registry_path().to_str().unwrap()
|
reg = publish::registry_path().to_str().unwrap()
|
||||||
)).run();
|
))
|
||||||
|
.run();
|
||||||
|
|
||||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||||
// Skip the metadata payload and the size of the tarball
|
// Skip the metadata payload and the size of the tarball
|
||||||
@ -188,7 +190,8 @@ See [..]
|
|||||||
[UPLOADING] foo v0.0.1 ([CWD])
|
[UPLOADING] foo v0.0.1 ([CWD])
|
||||||
",
|
",
|
||||||
reg = publish::registry_path().to_str().unwrap()
|
reg = publish::registry_path().to_str().unwrap()
|
||||||
)).run();
|
))
|
||||||
|
.run();
|
||||||
|
|
||||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||||
// Skip the metadata payload and the size of the tarball
|
// Skip the metadata payload and the size of the tarball
|
||||||
@ -266,7 +269,8 @@ See [..]
|
|||||||
[UPLOADING] foo v0.0.1 ([CWD])
|
[UPLOADING] foo v0.0.1 ([CWD])
|
||||||
",
|
",
|
||||||
reg = publish::registry_path().to_str().unwrap()
|
reg = publish::registry_path().to_str().unwrap()
|
||||||
)).run();
|
))
|
||||||
|
.run();
|
||||||
|
|
||||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||||
// Skip the metadata payload and the size of the tarball
|
// Skip the metadata payload and the size of the tarball
|
||||||
@ -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\
|
repository and specify it with a path and version\n\
|
||||||
(crate `foo` has repository path `git://path/to/nowhere`)\
|
(crate `foo` has repository path `git://path/to/nowhere`)\
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -371,7 +376,8 @@ fn path_dependency_no_version() {
|
|||||||
[ERROR] all path dependencies must have a version specified when publishing.
|
[ERROR] all path dependencies must have a version specified when publishing.
|
||||||
dependency `bar` does not specify a version
|
dependency `bar` does not specify a version
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -402,7 +408,8 @@ fn unpublishable_crate() {
|
|||||||
[ERROR] some crates cannot be published.
|
[ERROR] some crates cannot be published.
|
||||||
`foo` is marked as unpublishable
|
`foo` is marked as unpublishable
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -441,7 +448,8 @@ bar
|
|||||||
|
|
||||||
to proceed despite this, pass the `--allow-dirty` flag
|
to proceed despite this, pass the `--allow-dirty` flag
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -555,7 +563,8 @@ fn ignore_when_crate_ignored() {
|
|||||||
homepage = "foo"
|
homepage = "foo"
|
||||||
repository = "foo"
|
repository = "foo"
|
||||||
"#,
|
"#,
|
||||||
).nocommit_file("bar/src/main.rs", "fn main() {}");
|
)
|
||||||
|
.nocommit_file("bar/src/main.rs", "fn main() {}");
|
||||||
p.cargo("publish")
|
p.cargo("publish")
|
||||||
.cwd(p.root().join("bar"))
|
.cwd(p.root().join("bar"))
|
||||||
.arg("--index")
|
.arg("--index")
|
||||||
@ -583,7 +592,8 @@ fn new_crate_rejected() {
|
|||||||
homepage = "foo"
|
homepage = "foo"
|
||||||
repository = "foo"
|
repository = "foo"
|
||||||
"#,
|
"#,
|
||||||
).nocommit_file("src/main.rs", "fn main() {}");
|
)
|
||||||
|
.nocommit_file("src/main.rs", "fn main() {}");
|
||||||
p.cargo("publish --index")
|
p.cargo("publish --index")
|
||||||
.arg(publish::registry().to_string())
|
.arg(publish::registry().to_string())
|
||||||
.with_status(101)
|
.with_status(101)
|
||||||
@ -623,7 +633,8 @@ See [..]
|
|||||||
[UPLOADING] foo v0.0.1 ([CWD])
|
[UPLOADING] foo v0.0.1 ([CWD])
|
||||||
[WARNING] aborting upload due to dry run
|
[WARNING] aborting upload due to dry run
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
|
|
||||||
// Ensure the API request wasn't actually made
|
// Ensure the API request wasn't actually made
|
||||||
assert!(!publish::upload_path().join("api/v1/crates/new").exists());
|
assert!(!publish::upload_path().join("api/v1/crates/new").exists());
|
||||||
@ -666,7 +677,8 @@ Caused by:
|
|||||||
|
|
||||||
consider adding `cargo-features = [\"alternative-registries\"]` to the manifest
|
consider adding `cargo-features = [\"alternative-registries\"]` to the manifest
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -704,7 +716,8 @@ fn registry_not_in_publish_list() {
|
|||||||
[ERROR] some crates cannot be published.
|
[ERROR] some crates cannot be published.
|
||||||
`foo` is marked as unpublishable
|
`foo` is marked as unpublishable
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -737,7 +750,8 @@ fn publish_empty_list() {
|
|||||||
[ERROR] some crates cannot be published.
|
[ERROR] some crates cannot be published.
|
||||||
`foo` is marked as unpublishable
|
`foo` is marked as unpublishable
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -801,7 +815,8 @@ fn block_publish_no_registry() {
|
|||||||
[ERROR] some crates cannot be published.
|
[ERROR] some crates cannot be published.
|
||||||
`foo` is marked as unpublishable
|
`foo` is marked as unpublishable
|
||||||
",
|
",
|
||||||
).run();
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -871,3 +886,38 @@ fn publish_with_all_features() {
|
|||||||
.with_stderr_contains("[UPLOADING] foo v0.0.1 ([CWD])")
|
.with_stderr_contains("[UPLOADING] foo v0.0.1 ([CWD])")
|
||||||
.run();
|
.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();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user