v1.1.11
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1221,7 +1221,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "1.1.10"
|
version = "1.1.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argh",
|
"argh",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "1.1.10"
|
version = "1.1.11"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A Tool for Run Rust/TypeScript Scripts"
|
description = "A Tool for Run Rust/TypeScript Scripts"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::fs;
|
||||||
use crate::resolver::resolve_file;
|
use crate::resolver::resolve_file;
|
||||||
use crate::{util, verify, RunScriptArgs};
|
use crate::{util, verify, RunScriptArgs};
|
||||||
use rust_util::util_env::is_env_on;
|
use rust_util::util_env::is_env_on;
|
||||||
@@ -11,6 +12,7 @@ pub fn do_run_script(args: &RunScriptArgs) {
|
|||||||
let script_file = resolve_file(script_file, args.force_update)
|
let script_file = resolve_file(script_file, args.force_update)
|
||||||
.unwrap_or_else(|e| failure_and_exit!("Failed to resolve script: {}", e));
|
.unwrap_or_else(|e| failure_and_exit!("Failed to resolve script: {}", e));
|
||||||
let script_file = &script_file;
|
let script_file = &script_file;
|
||||||
|
let script_file_name = get_script_name(script_file);
|
||||||
|
|
||||||
verify::verify_script(script_file, is_env_on("RUNRS_SKIP_VERIFY") || is_env_on("RSV"));
|
verify::verify_script(script_file, is_env_on("RUNRS_SKIP_VERIFY") || is_env_on("RSV"));
|
||||||
|
|
||||||
@@ -19,8 +21,9 @@ pub fn do_run_script(args: &RunScriptArgs) {
|
|||||||
|
|
||||||
let user_home = get_user_home().unwrap_or_else(|| failure_and_exit!("$HOME not found!"));
|
let user_home = get_user_home().unwrap_or_else(|| failure_and_exit!("$HOME not found!"));
|
||||||
let rust_script = util::get_run_script_bin_name(&user_home);
|
let rust_script = util::get_run_script_bin_name(&user_home);
|
||||||
let cache_script_bin_name = get_cache_script_bin_name(&user_home, &script_sha256);
|
let script_bin_name = get_cache_script_bin_name(&user_home, &script_sha256);
|
||||||
let mut run_script_cmd = util::build_script_command(
|
let cache_script_bin_name = get_cache_script_bin_name_with_rs(&user_home, &script_sha256, &script_file_name);
|
||||||
|
let (mut run_script_cmd, cached) = util::build_script_command(
|
||||||
rust_script,
|
rust_script,
|
||||||
script_file,
|
script_file,
|
||||||
&script_sha256,
|
&script_sha256,
|
||||||
@@ -29,7 +32,19 @@ pub fn do_run_script(args: &RunScriptArgs) {
|
|||||||
for arg in args.arguments.iter().skip(1) {
|
for arg in args.arguments.iter().skip(1) {
|
||||||
run_script_cmd.arg(arg);
|
run_script_cmd.arg(arg);
|
||||||
}
|
}
|
||||||
util::run_script_command(script_file, &cache_script_bin_name, &mut run_script_cmd)
|
util::run_script_command(script_file, &script_bin_name, &mut run_script_cmd, || {
|
||||||
|
if !cached {
|
||||||
|
debugging!("Checking file : {}", &script_bin_name);
|
||||||
|
if fs::metadata(&script_bin_name).is_ok() {
|
||||||
|
debugging!("Linking file: {} & {}", &script_bin_name, &cache_script_bin_name);
|
||||||
|
match std::os::unix::fs::symlink(&script_bin_name, &cache_script_bin_name) {
|
||||||
|
Ok(_) => debugging!("Link file success"),
|
||||||
|
Err(e) => failure!("Linked file: {} and {} failed: {}", &script_bin_name, &cache_script_bin_name, &e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cache_script_bin_name(user_home: &str, script_sha256: &str) -> String {
|
fn get_cache_script_bin_name(user_home: &str, script_sha256: &str) -> String {
|
||||||
@@ -46,3 +61,40 @@ fn get_cache_script_bin_name(user_home: &str, script_sha256: &str) -> String {
|
|||||||
);
|
);
|
||||||
cache_script_bin_name
|
cache_script_bin_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_cache_script_bin_name_with_rs(user_home: &str, script_sha256: &str, script_file_name: &str) -> String {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
let cache_script_bin_path = format!(
|
||||||
|
"{}/Library/Caches/rust-script/binaries/release/{}-bin",
|
||||||
|
user_home, script_sha256
|
||||||
|
);
|
||||||
|
// #[cfg(target_os = "linux")]
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
let cache_script_bin_path = format!(
|
||||||
|
"{}/.cache/rust-script/binaries/release/{}-bin",
|
||||||
|
user_home, script_sha256
|
||||||
|
);
|
||||||
|
if fs::metadata(&cache_script_bin_path).is_err() {
|
||||||
|
debugging!("Creating cache script bin: {}", cache_script_bin_path);
|
||||||
|
fs::create_dir_all(&cache_script_bin_path).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
let cache_script_bin_name = format!(
|
||||||
|
"{}/{}", cache_script_bin_path, script_file_name
|
||||||
|
);
|
||||||
|
// #[cfg(target_os = "linux")]
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
let cache_script_bin_name = format!(
|
||||||
|
"{}/{}", cache_script_bin_path, script_file_name
|
||||||
|
);
|
||||||
|
cache_script_bin_name
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_script_name(script_file: &str) -> String {
|
||||||
|
let last_part = script_file.split("/").last();
|
||||||
|
if let Some(last_part) = last_part {
|
||||||
|
return last_part.to_string();
|
||||||
|
}
|
||||||
|
script_file.to_string()
|
||||||
|
}
|
||||||
|
|||||||
13
src/util.rs
13
src/util.rs
@@ -92,7 +92,7 @@ pub fn build_script_command(
|
|||||||
script_file: &str,
|
script_file: &str,
|
||||||
script_sha256: &str,
|
script_sha256: &str,
|
||||||
cache_script_bin_name: &str,
|
cache_script_bin_name: &str,
|
||||||
) -> Command {
|
) -> (Command, bool) {
|
||||||
let skip_cache = is_env_on("RUNRS_SKIP_CACHE");
|
let skip_cache = is_env_on("RUNRS_SKIP_CACHE");
|
||||||
let rebuild = is_env_on("RUNRS_REBUILD");
|
let rebuild = is_env_on("RUNRS_REBUILD");
|
||||||
let cache_script_bin_name_exists = fs::metadata(cache_script_bin_name).is_ok();
|
let cache_script_bin_name_exists = fs::metadata(cache_script_bin_name).is_ok();
|
||||||
@@ -102,7 +102,7 @@ pub fn build_script_command(
|
|||||||
iff!(cache_script_bin_name_exists, "", "not ")
|
iff!(cache_script_bin_name_exists, "", "not ")
|
||||||
);
|
);
|
||||||
if !rebuild && !skip_cache && cache_script_bin_name_exists {
|
if !rebuild && !skip_cache && cache_script_bin_name_exists {
|
||||||
Command::new(cache_script_bin_name)
|
(Command::new(cache_script_bin_name), true)
|
||||||
} else {
|
} else {
|
||||||
let mut cmd = Command::new(rust_script);
|
let mut cmd = Command::new(rust_script);
|
||||||
if !is_env_on("RUNRS_SILENT_BUILD") {
|
if !is_env_on("RUNRS_SILENT_BUILD") {
|
||||||
@@ -113,7 +113,7 @@ pub fn build_script_command(
|
|||||||
cmd.arg("--force");
|
cmd.arg("--force");
|
||||||
}
|
}
|
||||||
cmd.args(["--bin-name", script_sha256, script_file]);
|
cmd.args(["--bin-name", script_sha256, script_file]);
|
||||||
cmd
|
(cmd, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,16 +121,21 @@ pub fn run_script_command(
|
|||||||
script_file: &str,
|
script_file: &str,
|
||||||
cache_script_bin_name: &str,
|
cache_script_bin_name: &str,
|
||||||
run_script_cmd: &mut Command,
|
run_script_cmd: &mut Command,
|
||||||
|
after_command: impl Fn() -> (),
|
||||||
) -> ! {
|
) -> ! {
|
||||||
debugging!("Run command: {:?}", run_script_cmd);
|
debugging!("Run command: {:?}", run_script_cmd);
|
||||||
let run_command_start = SystemTime::now();
|
let run_command_start = SystemTime::now();
|
||||||
match util_cmd::run_command_and_wait(run_script_cmd) {
|
match util_cmd::run_command_and_wait(run_script_cmd) {
|
||||||
Err(e) => failure_and_exit!("Run rust-script failed: {}", e),
|
Err(e) => {
|
||||||
|
after_command();
|
||||||
|
failure_and_exit!("Run rust-script failed: {}", e)
|
||||||
|
},
|
||||||
Ok(exit_status) => {
|
Ok(exit_status) => {
|
||||||
write_script_file_to_src(script_file, cache_script_bin_name);
|
write_script_file_to_src(script_file, cache_script_bin_name);
|
||||||
if let Ok(run_command_cost) = SystemTime::now().duration_since(run_command_start) {
|
if let Ok(run_command_cost) = SystemTime::now().duration_since(run_command_start) {
|
||||||
debugging!("Run command cost: {}ms", run_command_cost.as_millis());
|
debugging!("Run command cost: {}ms", run_command_cost.as_millis());
|
||||||
}
|
}
|
||||||
|
after_command();
|
||||||
process::exit(exit_status.code().unwrap_or(0))
|
process::exit(exit_status.code().unwrap_or(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user