1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
//! See <https://github.com/matklad/cargo-xtask/>.
//!
//! This binary defines various auxiliary build commands, which are not
//! expressible with just `cargo`.
//!
//! This binary is integrated into the `cargo` command line by using an alias in
//! `.cargo/config`.
use std::path::PathBuf;
use anyhow::Result;
use clap::{Parser, Subcommand};
use xtask::{dist, release};
fn main() -> Result<()> {
let cli = Cli::parse();
std::env::set_current_dir(cli.directory)?;
match cli.command {
Commands::Dist { tag } => {
let targz = dist::generate_tar_gz(&cli.profile, tag.as_deref())?;
println!("{}", targz.display());
}
Commands::OutDir => {
let out_dir = dist::find_out_dir(&cli.profile)?;
println!("{}", out_dir.display());
}
};
Ok(())
}
#[derive(Debug, Clone, Parser)]
#[command(author, version, about)]
struct Cli {
#[command(subcommand)]
command: Commands,
/// Cargo profile to use.
#[arg(short, long, default_value = "release")]
profile: String,
/// Change to DIRECTORY before doing anything
#[arg(short='C', long, default_value_os_t = get_package_dir())]
directory: PathBuf,
}
#[derive(Debug, Clone, Subcommand)]
enum Commands {
/// Print the default value of OUT_DIR used by cargo when building the package.
OutDir,
/// Generate distributable package and print it's path
Dist {
/// Verify the package version matches the provided tag.
#[arg(short, long)]
tag: Option<String>,
},
}
fn get_package_dir() -> PathBuf {
std::path::Path::new(&env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.to_path_buf()
}
|