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 9, 2022
1 parent 3584f2b commit cfccf7d
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 88 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
10 changes: 5 additions & 5 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 Down Expand Up @@ -1184,7 +1184,7 @@ pub fn cbuild(
pub fn ctest(
ws: &Workspace,
config: &Config,
args: &ArgMatches<'_>,
args: &ArgMatches,
packages: &[CPackage],
mut compile_opts: CompileOptions,
) -> CliResult {
Expand Down
57 changes: 28 additions & 29 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,60 @@ use cargo::util::command_prelude::{multi_opt, opt};
use cargo::util::{CliError, CliResult};

use cargo_util::{ProcessBuilder, ProcessError};
use structopt::clap::*;
use structopt::StructOpt;

use clap::{Arg, ArgMatches, Command, CommandFactory, Parser};

// TODO: convert to a function using cargo opt()
#[allow(dead_code)]
#[derive(Clone, Debug, StructOpt)]
#[derive(Clone, Debug, Parser)]
struct Common {
/// Path to directory where target should be copied to
#[structopt(long = "destdir", parse(from_os_str))]
#[clap(long = "destdir", parse(from_os_str))]
destdir: Option<PathBuf>,
/// Directory path used to construct default values of
/// includedir, libdir, bindir, pkgconfigdir
#[structopt(long = "prefix", parse(from_os_str))]
#[clap(long = "prefix", parse(from_os_str))]
prefix: Option<PathBuf>,
/// Path to directory for installing generated library files
#[structopt(long = "libdir", parse(from_os_str))]
#[clap(long = "libdir", parse(from_os_str))]
libdir: Option<PathBuf>,
/// Path to directory for installing generated headers files
#[structopt(long = "includedir", parse(from_os_str))]
#[clap(long = "includedir", parse(from_os_str))]
includedir: Option<PathBuf>,
/// Path to directory for installing generated executable files
#[structopt(long = "bindir", parse(from_os_str))]
#[clap(long = "bindir", parse(from_os_str))]
bindir: Option<PathBuf>,
/// Path to directory for installing generated pkg-config .pc files
#[structopt(long = "pkgconfigdir", parse(from_os_str))]
#[clap(long = "pkgconfigdir", parse(from_os_str))]
pkgconfigdir: Option<PathBuf>,
/// Path to directory for installing read-only data (defaults to {prefix}/share)
#[structopt(long = "datarootdir", parse(from_os_str))]
#[clap(long = "datarootdir", parse(from_os_str))]
datarootdir: Option<PathBuf>,
/// Path to directory for installing read-only application-specific data
/// (defaults to {datarootdir})
#[structopt(long = "datadir", parse(from_os_str))]
#[clap(long = "datadir", parse(from_os_str))]
datadir: Option<PathBuf>,
#[structopt(long = "dlltool", parse(from_os_str))]
#[clap(long = "dlltool", parse(from_os_str))]
/// Use the provided dlltool when building for the windows-gnu targets.
dlltool: Option<PathBuf>,
#[structopt(long = "crt-static")]
#[clap(long = "crt-static")]
/// Build the library embedding the C runtime
crt_static: bool,
}

fn base_cli() -> App<'static, 'static> {
Common::clap()
.setting(AppSettings::ColoredHelp)
.arg(opt("version", "Print version info and exit").short("V"))
fn base_cli() -> Command<'static> {
Common::command()
.arg(opt("version", "Print version info and exit").short('V'))
.arg(
opt(
"verbose",
"Use verbose output (-vv very verbose/build.rs output)",
)
.short("v")
.multiple(true)
.short('v')
.multiple_occurrences(true)
.global(true),
)
.arg(opt("quiet", "No output printed to stdout").short("q"))
.arg(opt("quiet", "No output printed to stdout").short('q'))
.arg(
opt("color", "Coloring: auto, always, never")
.value_name("WHEN")
Expand All @@ -71,7 +70,7 @@ fn base_cli() -> App<'static, 'static> {
.arg(
multi_opt("config", "KEY=VALUE", "Override a configuration value")
.global(true)
.hidden(true),
.hide(true),
)
.arg_jobs()
.arg_profile("Build artifacts with the specified profile")
Expand All @@ -83,7 +82,7 @@ fn base_cli() -> App<'static, 'static> {
.arg_build_plan()
}

pub fn subcommand_build(name: &str, about: &'static str) -> App<'static, 'static> {
pub fn subcommand_build(name: &str, about: &'static str) -> Command<'static> {
base_cli()
.name(name)
.about(about)
Expand All @@ -94,7 +93,7 @@ pub fn subcommand_build(name: &str, about: &'static str) -> App<'static, 'static
"Build only a type of library",
)
.global(true)
.case_insensitive(true)
.ignore_case(true)
.possible_values(&["cdylib", "staticlib"]),
)
.arg_release("Build artifacts in release mode, with optimizations")
Expand All @@ -112,7 +111,7 @@ the --release flag will use the `release` profile instead.
)
}

pub fn subcommand_install(name: &str, about: &'static str) -> App<'static, 'static> {
pub fn subcommand_install(name: &str, about: &'static str) -> Command<'static> {
base_cli()
.name(name)
.about(about)
Expand All @@ -123,7 +122,7 @@ pub fn subcommand_install(name: &str, about: &'static str) -> App<'static, 'stat
"Build only a type of library",
)
.global(true)
.case_insensitive(true)
.ignore_case(true)
.possible_values(&["cdylib", "staticlib"]),
)
.arg(opt("debug", "Build in debug mode instead of release mode"))
Expand All @@ -144,15 +143,15 @@ the --debug flag will use the `dev` profile instead.
)
}

pub fn subcommand_test(name: &str) -> App<'static, 'static> {
pub fn subcommand_test(name: &str) -> Command<'static> {
base_cli()
.settings(&[AppSettings::TrailingVarArg])
.trailing_var_arg(true)
.name(name)
.about("Test the crate C-API")
.arg(
Arg::with_name("args")
Arg::new("args")
.help("Arguments for the test binary")
.multiple(true)
.multiple_values(true)
.last(true),
)
.arg_release("Build artifacts in release mode, with optimizations")
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn setup_env() {
}
}

pub fn config_configure(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
pub fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult {
let arg_target_dir = &args.value_of_path("target-dir", config);
let config_args: Vec<_> = args
.values_of("config")
Expand Down
4 changes: 2 additions & 2 deletions src/install.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::ArgMatches;
use std::path::{Component, Path, PathBuf};
use structopt::clap::ArgMatches;

use cargo::core::Workspace;
use cargo_util::paths::{copy, create_dir_all};
Expand Down Expand Up @@ -272,7 +272,7 @@ pub struct InstallPaths {
}

impl InstallPaths {
pub fn new(_name: &str, args: &ArgMatches<'_>, capi_config: &CApiConfig) -> Self {
pub fn new(_name: &str, args: &ArgMatches, capi_config: &CApiConfig) -> Self {
let destdir = args.value_of("destdir").map(PathBuf::from);
let prefix = args
.value_of("prefix")
Expand Down
2 changes: 1 addition & 1 deletion src/pkg_config_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl PkgConfig {
pub(crate) fn from_workspace(
name: &str,
install_paths: &InstallPaths,
args: &structopt::clap::ArgMatches<'_>,
args: &clap::ArgMatches,
capi_config: &CApiConfig,
) -> Self {
let mut pc = PkgConfig::new(name, capi_config);
Expand Down

0 comments on commit cfccf7d

Please sign in to comment.