Skip to content

Commit

Permalink
build: Download assets to cargo output dir (#1476)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* build: replace pushd by cd

---------

Co-authored-by: Ruihang Xia <[email protected]>
  • Loading branch information
evenyag and waynexia authored Apr 27, 2023
1 parent 9f0efc7 commit 8e3c3cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
3 changes: 3 additions & 0 deletions scripts/fetch-dashboard-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 12 additions & 17 deletions src/servers/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 8e3c3cb

Please sign in to comment.