feat: v0.1.11 add rebuild

This commit is contained in:
2022-08-08 00:30:06 +08:00
parent 10067174fc
commit b1ef84209e
4 changed files with 14 additions and 9 deletions

2
Cargo.lock generated
View File

@@ -128,7 +128,7 @@ dependencies = [
[[package]] [[package]]
name = "runrs" name = "runrs"
version = "0.1.10" version = "0.1.11"
dependencies = [ dependencies = [
"rust_util", "rust_util",
"sha256", "sha256",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "runrs" name = "runrs"
version = "0.1.10" version = "0.1.11"
edition = "2018" edition = "2018"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
description = "Run Rust Scripts" description = "Run Rust Scripts"

View File

@@ -10,13 +10,14 @@ cargo install --git https://git.hatter.ink/hatter/runrs runrs
Environment variables Environment variables
| Env Key | Env Value | | Env Key | Env Value |
|---------------|----------------------------------------------------------------| |---------------|---------------------------------------------------------------|
| `HOME` | User home, default by OS system | | `HOME` | User home, default by OS system |
| `RUNRS_SKIP_CACHE` | Skip compiled cached file , turn on `true`, `yes`, `on` or `1` | | `RUNRS_SKIP_CACHE` | Skip compiled cached file , turn on `true`, `yes`, `on` or `1` |
| `RUNRS_SILENT_BUILD` | Build new binary in silent mode | | `RUNRS_REBUILD` | Force rebuild |
| `RUNRS_RUST_SCRIPT` | `rust_script` command line bin file | | `RUNRS_SILENT_BUILD` | Build new binary in silent mode |
| `RUNRS_MAX_SCRIPT_LEN` | Max script length | | `RUNRS_RUST_SCRIPT` | `rust_script` command line bin file |
| `RUNRS_MAX_SCRIPT_LEN` | Max script length |
<br> <br>

View File

@@ -36,9 +36,10 @@ fn main() {
fn build_script_command(rust_script: PathBuf, script_file: &str, script_sha256: &str, cache_script_bin_name: &str) -> Command { fn build_script_command(rust_script: PathBuf, script_file: &str, script_sha256: &str, cache_script_bin_name: &str) -> Command {
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 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();
debugging!("Bin name: {} {}exists", cache_script_bin_name, iff!(cache_script_bin_name_exists, "", "not ")); debugging!("Bin name: {} {}exists", cache_script_bin_name, iff!(cache_script_bin_name_exists, "", "not "));
if !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)
} else { } else {
let mut cmd = Command::new(rust_script); let mut cmd = Command::new(rust_script);
@@ -46,6 +47,9 @@ fn build_script_command(rust_script: PathBuf, script_file: &str, script_sha256:
information!("Cached binary not exists, RUNRS_SILENT_BUILD=1 turn off"); information!("Cached binary not exists, RUNRS_SILENT_BUILD=1 turn off");
cmd.arg("--cargo-output"); cmd.arg("--cargo-output");
} }
if rebuild {
cmd.arg("--force");
}
cmd.args(&["--bin-name", &script_sha256, script_file]); cmd.args(&["--bin-name", &script_sha256, script_file]);
cmd cmd
} }