Skip to content

Commit ad11422

Browse files
gabriele-0201pepyakin
authored andcommitted
xtask: add no_infer_bin_path flag
remove the ci flag and set the default behavior to add binaries to the path and CONSTANTS_MANIFEST to environment variables
1 parent 6dbf268 commit ad11422

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ jobs:
3232
- name: cargo test
3333
run: cargo test --verbose --all
3434
- name: cargo xtask test
35-
run: cargo xtask test --ci
35+
run: cargo xtask test

xtask/src/cli.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ pub mod test {
5757

5858
#[derive(Debug, Args)]
5959
pub struct Params {
60-
/// If the test is executed in CI
60+
/// By default, binary paths are extracted using the `cargo metadata` command under the key `target_directory`.
61+
///
62+
/// To disable this behavior and manually add all binaries to the path, you need to specify this flag
6163
#[clap(long, default_value = "false")]
62-
pub ci: bool,
64+
pub no_infer_bin_path: bool,
6365

6466
#[clap(flatten)]
6567
pub build: BuildParams,

xtask/src/main.rs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() -> anyhow::Result<()> {
2727
fn test(params: test::Params) -> anyhow::Result<()> {
2828
let project_path = obtain_project_path()?;
2929

30-
init_env(&project_path, params.ci)?;
30+
init_env(&project_path, params.no_infer_bin_path)?;
3131

3232
build::build(&project_path, params.build)?;
3333

@@ -78,27 +78,47 @@ fn wait_interrupt() {
7878

7979
// Set up environment variables needed by the compilation and testing process.
8080
//
81-
// If ci flag is specified, all binaries are added to PATH env variable
82-
// and the sovereign constant manifest position is specified through the
83-
// CONSTANTS_MANIFEST new env variable
84-
fn init_env(project_path: &Path, ci: bool) -> anyhow::Result<()> {
85-
if ci {
86-
let path = std::env::var("PATH").unwrap_or_else(|_| "".to_string());
87-
88-
// `cargo_target` is the target used in ci by cargo as destination
89-
// for all intermediate and final artifacts
90-
let new_path = format!("/cargo_target/release/:{}", path);
91-
std::env::set_var("PATH", new_path);
92-
93-
let path = project_path.join("demo/sovereign/constants.json");
94-
if !path.exists() {
95-
anyhow::bail!(
96-
"The `constants.json` file for Sovereign does not exist,\n \
81+
// Add the sovereign constant manifest position through the
82+
// CONSTANTS_MANIFEST new env variable and if no_infer_bin_path is not specified
83+
// add to the path all required binaries.
84+
fn init_env(project_path: &PathBuf, no_infer_bin_path: bool) -> anyhow::Result<()> {
85+
let path = project_path.join("demo/sovereign/constants.json");
86+
if !path.exists() {
87+
anyhow::bail!(
88+
"The `constants.json` file for Sovereign does not exist,\n \
9789
or it is not in the expected position, `demo/sovereign/constants.json`"
98-
)
99-
}
100-
std::env::set_var("CONSTANTS_MANIFEST", path);
90+
)
10191
}
92+
std::env::set_var("CONSTANTS_MANIFEST", path);
93+
94+
if no_infer_bin_path {
95+
return Ok(());
96+
}
97+
98+
let path = std::env::var("PATH").unwrap_or_else(|_| "".to_string());
99+
100+
#[rustfmt::skip]
101+
let chain_target_path = duct::cmd!(
102+
"sh", "-c",
103+
"cargo metadata --format-version 1 | jq -r '.target_directory'"
104+
)
105+
.stdout_capture()
106+
.run()?;
107+
let chain_target_path = str::from_utf8(&chain_target_path.stdout)?.trim();
108+
109+
#[rustfmt::skip]
110+
let sovereign_target_path = duct::cmd!(
111+
"sh", "-c",
112+
"cd demo/sovereign && cargo metadata --format-version 1 | jq -r '.target_directory'"
113+
)
114+
.stdout_capture()
115+
.run()?;
116+
let sovereign_target_path = str::from_utf8(&sovereign_target_path.stdout)?.trim();
117+
118+
std::env::set_var(
119+
"PATH",
120+
format!("{chain_target_path}/release/:{sovereign_target_path}/release/:{path}"),
121+
);
102122

103123
Ok(())
104124
}

0 commit comments

Comments
 (0)