Skip to content

Commit

Permalink
Update to clap-3.1 and cargo-0.61
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero committed Apr 10, 2022
1 parent 3584f2b commit 696504d
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 103 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-c"
version = "0.9.8+cargo-0.60"
version = "0.9.9+cargo-0.61"
authors = ["Luca Barbato <lu_zero@gentoo.org>"]
description = "Helper program to build and install c-like libraries"
license = "MIT"
Expand All @@ -27,11 +27,11 @@ name = "cargo-ctest"
path = "src/bin/ctest.rs"

[dependencies]
cargo = "0.60"
cargo = "0.61"
cargo-util = "0.1"
semver = "1.0.3"
log = "0.4"
structopt = { version="0.3", features=["color"] }
clap = { version="3.1", features=["color", "derive", "cargo"] }
regex = "1"
cbindgen = "0.20"
toml = "0.5"
Expand Down
27 changes: 12 additions & 15 deletions src/bin/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cargo::util::command_prelude::ArgMatchesExt;
use cargo::CliResult;
use cargo::Config;

use structopt::clap::*;
use clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;
Expand All @@ -17,17 +17,14 @@ fn main() -> CliResult {
let cli_install = subcommand_install("install", "Install the crate C-API");
let cli_test = subcommand_test("test");

let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(
SubCommand::with_name("capi")
Command::new("capi")
.about("Build or install the crate C-API")
.arg(opt("version", "Print version info and exit").short("V"))
.arg(opt("version", "Print version info and exit").short('V'))
.subcommand(cli_build)
.subcommand(cli_install)
.subcommand(cli_test),
Expand All @@ -36,11 +33,11 @@ fn main() -> CliResult {
let args = app.clone().get_matches();

let (cmd, subcommand_args, default_profile) = match args.subcommand() {
("capi", Some(args)) => match args.subcommand() {
("build", Some(args)) => ("build", args, "dev"),
("test", Some(args)) => ("test", args, "dev"),
("install", Some(args)) => ("install", args, "release"),
(cmd, Some(args)) => {
Some(("capi", args)) => match args.subcommand() {
Some(("build", args)) => ("build", args, "dev"),
Some(("test", args)) => ("test", args, "dev"),
Some(("install", args)) => ("install", args, "release"),
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
18 changes: 7 additions & 11 deletions src/bin/cbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_build;
use cargo_c::config::*;

use structopt::clap::*;
use clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;

let subcommand = subcommand_build("cbuild", "Build the crate C-API");

let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);

let args = app.clone().get_matches();

let subcommand_args = match args.subcommand() {
("cbuild", Some(args)) => args,
(cmd, Some(args)) => {
Some(("cbuild", args)) => args,
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
17 changes: 7 additions & 10 deletions src/bin/cinstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ use cargo_c::cli::subcommand_install;
use cargo_c::config::config_configure;
use cargo_c::install::cinstall;

use structopt::clap::*;
use clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;

let subcommand = subcommand_install("cinstall", "Install the crate C-API");
let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);

let args = app.clone().get_matches();

let subcommand_args = match args.subcommand() {
("cinstall", Some(args)) => args,
(cmd, Some(args)) => {
Some(("cinstall", args)) => args,
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
17 changes: 6 additions & 11 deletions src/bin/ctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,22 @@ use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_test;
use cargo_c::config::*;

use structopt::clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;

let subcommand = subcommand_test("ctest");

let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);

let args = app.clone().get_matches();

let subcommand_args = match args.subcommand() {
("ctest", Some(args)) => args,
(cmd, Some(args)) => {
Some(("ctest", args)) => args,
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
29 changes: 17 additions & 12 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ fn load_manifest_capi_config(pkg: &Package) -> anyhow::Result<CApiConfig> {
fn compile_options(
ws: &Workspace,
config: &Config,
args: &ArgMatches<'_>,
args: &ArgMatches,
profile: InternedString,
compile_mode: CompileMode,
) -> anyhow::Result<CompileOptions> {
Expand Down Expand Up @@ -865,7 +865,7 @@ fn compile_with_exec<'a>(
exec: &Arc<dyn Executor>,
rustc_target: &target::Target,
root_output: &Path,
args: &ArgMatches<'_>,
args: &ArgMatches,
) -> CargoResult<HashMap<PackageId, PathBuf>> {
ws.emit_warnings()?;
let interner = UnitInterner::new();
Expand Down Expand Up @@ -954,7 +954,7 @@ pub struct CPackage {
impl CPackage {
fn from_package(
pkg: &mut Package,
args: &ArgMatches<'_>,
args: &ArgMatches,
libkinds: &[&str],
rustc_target: &target::Target,
root_output: &Path,
Expand Down Expand Up @@ -988,7 +988,7 @@ impl CPackage {
pub fn cbuild(
ws: &mut Workspace,
config: &Config,
args: &ArgMatches<'_>,
args: &ArgMatches,
default_profile: &str,
) -> anyhow::Result<(Vec<CPackage>, CompileOptions)> {
let rustc = config.load_global_rustc(Some(ws))?;
Expand All @@ -1002,13 +1002,18 @@ pub fn cbuild(
};

let rustc_target = target::Target::new(&target)?;
let libkinds = args.values_of("library-type").map_or_else(
|| match (rustc_target.os.as_str(), rustc_target.env.as_str()) {
("none", _) | (_, "musl") => vec!["staticlib"],
_ => vec!["staticlib", "cdylib"],
},
|v| v.collect::<Vec<_>>(),
);

let default_kind = || match (rustc_target.os.as_str(), rustc_target.env.as_str()) {
("none", _) | (_, "musl") => vec!["staticlib"],
_ => vec!["staticlib", "cdylib"],
};

let libkinds = if args._is_valid_arg("library-type") {
args.values_of("library-type")
.map_or_else(default_kind, |v| v.collect::<Vec<_>>())
} else {
default_kind()
};
let only_staticlib = !libkinds.contains(&"cdylib");
let only_cdylib = !libkinds.contains(&"staticlib");

Expand Down Expand Up @@ -1184,7 +1189,7 @@ pub fn cbuild(
pub fn ctest(
ws: &Workspace,
config: &Config,
args: &ArgMatches<'_>,
args: &ArgMatches,
packages: &[CPackage],
mut compile_opts: CompileOptions,
) -> CliResult {
Expand Down

0 comments on commit 696504d

Please sign in to comment.