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]]
name = "runrs"
version = "0.1.10"
version = "0.1.11"
dependencies = [
"rust_util",
"sha256",

View File

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

View File

@@ -10,13 +10,14 @@ cargo install --git https://git.hatter.ink/hatter/runrs runrs
Environment variables
| Env Key | Env Value |
|---------------|----------------------------------------------------------------|
| `HOME` | User home, default by OS system |
| Env Key | Env Value |
|---------------|---------------------------------------------------------------|
| `HOME` | User home, default by OS system |
| `RUNRS_SKIP_CACHE` | Skip compiled cached file , turn on `true`, `yes`, `on` or `1` |
| `RUNRS_SILENT_BUILD` | Build new binary in silent mode |
| `RUNRS_RUST_SCRIPT` | `rust_script` command line bin file |
| `RUNRS_MAX_SCRIPT_LEN` | Max script length |
| `RUNRS_REBUILD` | Force rebuild |
| `RUNRS_SILENT_BUILD` | Build new binary in silent mode |
| `RUNRS_RUST_SCRIPT` | `rust_script` command line bin file |
| `RUNRS_MAX_SCRIPT_LEN` | Max script length |
<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 {
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();
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)
} else {
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");
cmd.arg("--cargo-output");
}
if rebuild {
cmd.arg("--force");
}
cmd.args(&["--bin-name", &script_sha256, script_file]);
cmd
}