Skip to content

Commit 99a7d78

Browse files
committed
Add envs, path and custom message params to build helper funtions
1 parent 5a21b13 commit 99a7d78

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,11 @@ pub fn handle_command(mut args: tracel_xtask::commands::build::BuildCmdArgs) ->
607607

608608
// additional crate builds
609609
// build 'my-crate' with all the features
610-
tracel_xtask::utils::helpers::custom_crates_build(vec!["my-crate"], vec!["--all-features"])?;
610+
tracel_xtask::utils::helpers::custom_crates_build(vec!["my-crate"], vec!["--all-features"], None, None, "all features")?;
611611
// build 'my-crate' with specific features
612-
tracel_xtask::utils::helpers::custom_crates_build(vec!["my-crate"], vec!["--features", "myfeature1,myfeature2"])?;
612+
tracel_xtask::utils::helpers::custom_crates_build(vec!["my-crate"], vec!["--features", "myfeature1,myfeature2"], None, None, "myfeature1,myfeature2")?;
613613
// build 'my-crate' with a different target than the default one
614-
tracel_xtask::utils::helpers::custom_crates_build(vec!["my-crate"], vec!["--target", "thumbv7m-none-eabi"])?;
614+
tracel_xtask::utils::helpers::custom_crates_build(vec!["my-crate"], vec!["--target", "thumbv7m-none-eabi"], None, None, "thumbv7m-none-eabi target")?;
615615
Ok(())
616616
}
617617
```

crates/tracel-xtask/src/utils/helpers.rs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
use std::{collections::HashMap, path::Path};
2+
13
use anyhow::Ok;
24

35
use crate::{endgroup, group, utils::process::run_process};
46

57
/// Allow to build additional crates outside the common build commands
6-
pub fn custom_crates_build(crates: Vec<&str>, params: Vec<&str>) -> anyhow::Result<()> {
8+
pub fn custom_crates_build(
9+
crates: Vec<&str>,
10+
args: Vec<&str>,
11+
envs: Option<HashMap<&str, &str>>,
12+
path: Option<&Path>,
13+
group_msg: &str,
14+
) -> anyhow::Result<()> {
715
let mut base_args = vec!["build", "--color", "always"];
8-
base_args.extend(params);
16+
base_args.extend(args);
917
crates.iter().try_for_each(|c| {
10-
group!("Custom Build: {}", *c);
18+
group!("Custom Build: {} ({})", *c, group_msg);
1119
let mut args = base_args.clone();
1220
args.extend(vec!["-p", *c]);
1321
run_process(
1422
"cargo",
1523
&args,
16-
None,
17-
None,
24+
envs.clone(),
25+
path,
1826
&format!("Custom build failed for {}", *c),
1927
)?;
2028
endgroup!();
@@ -23,18 +31,24 @@ pub fn custom_crates_build(crates: Vec<&str>, params: Vec<&str>) -> anyhow::Resu
2331
}
2432

2533
/// Allow to test additional crates with specific flags and config
26-
pub fn custom_crates_tests(crates: Vec<&str>, params: Vec<&str>) -> anyhow::Result<()> {
34+
pub fn custom_crates_tests(
35+
crates: Vec<&str>,
36+
args: Vec<&str>,
37+
envs: Option<HashMap<&str, &str>>,
38+
path: Option<&Path>,
39+
group_msg: &str,
40+
) -> anyhow::Result<()> {
2741
let mut base_args = vec!["test", "--color", "always"];
28-
base_args.extend(params);
42+
base_args.extend(args);
2943
crates.iter().try_for_each(|c| {
30-
group!("Custom Tests: {}", *c);
44+
group!("Custom Tests: {} ({})", *c, group_msg);
3145
let mut args = base_args.clone();
3246
args.extend(vec!["-p", *c]);
3347
run_process(
3448
"cargo",
3549
&args,
36-
None,
37-
None,
50+
envs.clone(),
51+
path,
3852
&format!("Custom test failed for {}", *c),
3953
)?;
4054
endgroup!();
@@ -43,18 +57,24 @@ pub fn custom_crates_tests(crates: Vec<&str>, params: Vec<&str>) -> anyhow::Resu
4357
}
4458

4559
/// Allow to build crate documentation additional crates outside the common doc commands
46-
pub fn custom_crates_doc_build(crates: Vec<&str>, params: Vec<&str>) -> anyhow::Result<()> {
60+
pub fn custom_crates_doc_build(
61+
crates: Vec<&str>,
62+
args: Vec<&str>,
63+
envs: Option<HashMap<&str, &str>>,
64+
path: Option<&Path>,
65+
group_msg: &str,
66+
) -> anyhow::Result<()> {
4767
let mut base_args = vec!["doc", "--no-deps", "--color", "always"];
48-
base_args.extend(params);
68+
base_args.extend(args);
4969
crates.iter().try_for_each(|c| {
50-
group!("Custom doc build: {}", *c);
70+
group!("Custom doc build: {} ({})", *c, group_msg);
5171
let mut args = base_args.clone();
5272
args.extend(vec!["-p", *c]);
5373
run_process(
5474
"cargo",
5575
&args,
56-
None,
57-
None,
76+
envs.clone(),
77+
path,
5878
&format!("Custom doc build failed for {}", *c),
5979
)?;
6080
endgroup!();

0 commit comments

Comments
 (0)