From 8e3c3cbc40e4489fe8fc52d84cd1d46769cde62b Mon Sep 17 00:00:00 2001 From: Yingwen Date: Thu, 27 Apr 2023 17:09:10 +0800 Subject: [PATCH] build: Download assets to cargo output dir (#1476) * build: Download assets to cargo output dir Also remove the output from the build script and only print the output on failure * chore: Update src/servers/build.rs Co-authored-by: Ruihang Xia * build: replace pushd by cd --------- Co-authored-by: Ruihang Xia --- scripts/fetch-dashboard-assets.sh | 3 +++ src/servers/build.rs | 29 ++++++++++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/fetch-dashboard-assets.sh b/scripts/fetch-dashboard-assets.sh index 8888a907d85b..ac940bab930e 100755 --- a/scripts/fetch-dashboard-assets.sh +++ b/scripts/fetch-dashboard-assets.sh @@ -7,9 +7,12 @@ set -e declare -r SCRIPT_DIR=$(cd $(dirname ${0}) >/dev/null 2>&1 && pwd) declare -r ROOT_DIR=$(dirname ${SCRIPT_DIR}) declare -r STATIC_DIR="$ROOT_DIR/src/servers/dashboard" +OUT_DIR="${1:-$SCRIPT_DIR}" RELEASE_VERSION="$(cat $STATIC_DIR/VERSION)" +echo "Downloading assets to dir: $OUT_DIR" +cd $OUT_DIR # Download the SHA256 checksum attached to the release. To verify the integrity # of the download, this checksum will be used to check the download tar file # containing the built dashboard assets. diff --git a/src/servers/build.rs b/src/servers/build.rs index b32ce969b8c8..e1e0ea9bb664 100644 --- a/src/servers/build.rs +++ b/src/servers/build.rs @@ -21,33 +21,28 @@ fn main() { fn fetch_dashboard_assets() { use std::process::{Command, Stdio}; - macro_rules! p { - ($($tokens: tt)*) => { - println!("cargo:warning={}", format!($($tokens)*)) - } - } - + let message = "Failed to fetch dashboard assets"; + let help = r#" +You can manually execute './scripts/fetch-dashboard-assets.sh' to see why, +or it's a network error, just try again or enable/disable some proxy."#; + let out_dir = std::env::var("OUT_DIR").unwrap(); let output = Command::new("./fetch-dashboard-assets.sh") + .arg(&out_dir) .current_dir("../../scripts") .stdout(Stdio::piped()) .spawn() .and_then(|p| p.wait_with_output()); match output { Ok(output) => { - String::from_utf8_lossy(&output.stdout) - .lines() - .for_each(|x| p!("{}", x)); + let script_output = String::from_utf8_lossy(&output.stdout); - assert!(output.status.success()); + assert!( + output.status.success(), + "{message}.\n{script_output}\n{help}" + ); } Err(e) => { - let e = format!( - r#" -Failed to fetch dashboard assets: {}. -You can manually execute './scripts/fetch-dashboard-assets.sh' to see why, -or it's a network error, just try again or enable/disable some proxy."#, - e - ); + let e = format!("{message}: {e}.\n{help}"); panic!("{}", e); } }