Skip to content

Commit bfc6ac0

Browse files
committed
build(xtask): ➖ remove sh crate from xtask
1 parent 144eeb7 commit bfc6ac0

File tree

5 files changed

+47
-102
lines changed

5 files changed

+47
-102
lines changed

.cargo/config.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[alias]
2-
xtask = "run --package xtask --"
3-
xtask-dbg = "run --package xtask --features dbg --"
2+
xtask = "run --package xtask --locked --"
3+
xtask-dbg = "run --package xtask --features dbg --locked --"
44

5-
# Use custom linker for faster linking
5+
# # Use custom linker for faster linking
66
# [build]
77
# rustflags = ["-Clink-arg=-fuse-ld=mold"]

Cargo.lock

Lines changed: 24 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dprint.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"plugins": [
2020
"https://plugins.dprint.dev/json-0.19.4.wasm",
2121
"https://plugins.dprint.dev/markdown-0.17.8.wasm",
22-
"https://plugins.dprint.dev/toml-0.6.3.wasm",
23-
"https://plugins.dprint.dev/exec-0.5.0.json@8d9972eee71fa1590e04873540421f3eda7674d0f1aae3d7c788615e7b7413d0",
22+
"https://plugins.dprint.dev/toml-0.6.4.wasm",
23+
"https://plugins.dprint.dev/exec-0.5.1.json@492414e39dea4dccc07b4af796d2f4efdb89e84bae2bd4e1e924c0cc050855bf",
2424
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm"
2525
]
2626
}

xtask/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ description = "A task runner for cargo workspaces"
1313
[dependencies]
1414
anyhow = "1.0.95"
1515
clap = { version = "4.5.24", features = ["derive"] }
16-
sh = "0.2.1"
1716

1817
[features]
1918
dbg = []

xtask/src/main.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
use std::{env::set_current_dir, path::Path};
3+
use std::{env::set_current_dir, io, path::Path, process::Command};
44

55
use clap::{Parser, ValueEnum};
6-
use sh::cmd;
76

87
#[derive(Debug, ValueEnum, Clone, Copy, PartialEq, Eq)]
98
/// Package distribution-specific packages.
@@ -17,12 +16,12 @@ enum Package {
1716
#[derive(Debug, Parser)]
1817
#[clap(about, long_about)]
1918
/// Build related tasks.
20-
enum Command {
19+
enum Args {
2120
/// Package distribution-specific packages.
2221
Dist {
2322
/// Which package to build.
2423
#[arg(value_enum)]
25-
package: Package,
24+
pkg: Package,
2625
},
2726
/// Build Docker image.
2827
Docker,
@@ -31,30 +30,28 @@ enum Command {
3130
Debug,
3231
}
3332

33+
fn exec(program: &str, args: &[&str]) -> io::Result<()> {
34+
Command::new(program).args(args).spawn()?.wait()?;
35+
Ok(())
36+
}
37+
3438
fn main() -> anyhow::Result<()> {
35-
let command = Command::parse();
39+
let args = Args::parse();
3640

3741
// chdir to the workspace root so that `cargo xtask` can be invoked from anywhere.
3842
set_current_dir(Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap())?;
3943

40-
match command {
41-
Command::Dist { package } => match package {
42-
Package::Deb => cmd!(cargo deb "-v" "--locked"),
43-
Package::Rpm => cmd! {
44-
cargo build "--release" "--locked";
45-
cargo "generate-rpm"
46-
},
47-
},
48-
Command::Docker => cmd!(docker build "-t" rsjudge "."),
49-
44+
match args {
45+
Args::Dist { pkg: Package::Deb } => exec("cargo", &["deb", "-v", "--locked"])?,
46+
Args::Dist { pkg: Package::Rpm } => {
47+
// `cargo-generate-rpm` does not invoke `cargo build` itself.
48+
exec("cargo", &["build", "--release", "--locked"])?;
49+
exec("cargo", &["generate-rpm"])?;
50+
}
51+
Args::Docker => exec("docker", &["build", "-t", "rsjudge", "."])?,
5052
#[cfg(feature = "dbg")]
51-
Command::Debug => return Ok(()),
53+
Args::Debug => {}
5254
}
53-
.try_for_each(|cmd| {
54-
#[cfg(feature = "dbg")]
55-
eprintln!("Executing: {:?}", cmd);
56-
cmd.exec()
57-
})?;
5855

5956
Ok(())
6057
}

0 commit comments

Comments
 (0)