Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding feature-flags to cargo publish and cargo package #6453

Merged
merged 5 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bin/cargo/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn cli() -> App {
))
.arg_target_triple("Build for the target triple")
.arg_target_dir()
.arg_features()
.arg_manifest_path()
.arg_jobs()
}
Expand All @@ -42,6 +43,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
allow_dirty: args.is_present("allow-dirty"),
target: args.target(),
jobs: args.jobs()?,
registry: None,
features: args._values_of("features"),
all_features: args.is_present("all-features"),
},
)?;
Ok(())
Expand Down
3 changes: 3 additions & 0 deletions src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn cli() -> App {
.arg_target_triple("Build for the target triple")
.arg_target_dir()
.arg_manifest_path()
.arg_features()
.arg_jobs()
.arg_dry_run("Perform all checks without uploading")
.arg(opt("registry", "Registry to publish to").value_name("REGISTRY"))
Expand All @@ -40,6 +41,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
jobs: args.jobs()?,
dry_run: args.is_present("dry-run"),
registry,
features: args._values_of("features"),
all_features: args.is_present("all-features"),
},
)?;
Ok(())
Expand Down
7 changes: 5 additions & 2 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct PackageOpts<'cfg> {
pub verify: bool,
pub jobs: Option<u32>,
pub target: Option<String>,
pub registry: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is registry added if it is never used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

I copied the registry field over from somewhere else and then implemented the init without realising it was actually never used 😅

pub features: Vec<String>,
pub all_features: bool,
}

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

pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
Expand Down Expand Up @@ -82,6 +84,9 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
allow_dirty: opts.allow_dirty,
target: opts.target.clone(),
jobs: opts.jobs,
registry: opts.registry.clone(),
features: opts.features.clone(),
all_features: opts.all_features,
},
)?
.unwrap();
Expand Down
64 changes: 64 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,3 +1298,67 @@ To proceed despite this, pass the `--no-verify` flag.",

p.cargo("package --no-verify").run();
}

#[test]
fn package_with_select_features() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["alternative-registries"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these tests have this cargo-feature?


[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"

[features]
required = []
optional = []
"#,
).file(
"src/main.rs",
"#[cfg(not(feature = \"required\"))]
compile_error!(\"This crate requires `required` feature!\");
fn main() {}",
).build();

p.cargo("package --features required")
.masquerade_as_nightly_cargo()
.with_status(0)
.run();
}

#[test]
fn package_with_all_features() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["alternative-registries"]

[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"

[features]
required = []
optional = []
"#,
).file(
"src/main.rs",
"#[cfg(not(feature = \"required\"))]
compile_error!(\"This crate requires `required` feature!\");
fn main() {}",
).build();

p.cargo("package --all-features")
.masquerade_as_nightly_cargo()
.with_status(0)
.run();
}
Loading