From 1d885f60cae196752d3ab5d2dc9cc488370b59c9 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Fri, 2 Aug 2024 14:50:05 -0400 Subject: [PATCH] Allow specifying a path to `xtask-downloader` --- dev-tools/xtask/src/external.rs | 4 ++++ dev-tools/xtask/src/main.rs | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/dev-tools/xtask/src/external.rs b/dev-tools/xtask/src/external.rs index 05e668297d..34be7c0d9a 100644 --- a/dev-tools/xtask/src/external.rs +++ b/dev-tools/xtask/src/external.rs @@ -52,6 +52,10 @@ impl External { self } + pub fn trailing_args(&self) -> &[OsString] { + &self.args + } + pub fn exec_example(self, example_target: impl AsRef) -> Result<()> { self.exec_common("--example", example_target.as_ref()) } diff --git a/dev-tools/xtask/src/main.rs b/dev-tools/xtask/src/main.rs index 1d9dfd0b6c..40d027cb48 100644 --- a/dev-tools/xtask/src/main.rs +++ b/dev-tools/xtask/src/main.rs @@ -9,6 +9,9 @@ use anyhow::{Context, Result}; use cargo_metadata::Metadata; use clap::{Parser, Subcommand}; +use std::env; +use std::os::unix::process::CommandExt; +use std::process::Command; mod check_features; mod check_workspace_deps; @@ -94,7 +97,20 @@ fn main() -> Result<()> { Cmds::Clippy(args) => clippy::run_cmd(args), Cmds::CheckFeatures(args) => check_features::run_cmd(args), Cmds::CheckWorkspaceDeps => check_workspace_deps::run_cmd(), - Cmds::Download(external) => external.exec_bin("xtask-downloader"), + Cmds::Download(external) => { + // Allow specialized environments (e.g., testbed/a4x2) that can't + // `cargo run ...` to specify a path to `xtask-downloader` via an + // environment variable. + if let Ok(bin_path) = env::var("XTASK_DOWNLOADER_BIN") { + let error = Command::new(&bin_path) + .args(external.trailing_args()) + .exec(); + Err(error) + .with_context(|| format!("failed to exec `{bin_path}`")) + } else { + external.exec_bin("xtask-downloader") + } + } Cmds::Openapi(external) => external.exec_bin("openapi-manager"), #[cfg(target_os = "illumos")] Cmds::Releng(external) => {