Skip to content

Commit 8eb27b6

Browse files
committed
s/CARGO_SCRIPT/RUST_SCRIPT
1 parent 549a290 commit 8eb27b6

File tree

6 files changed

+23
-33
lines changed

6 files changed

+23
-33
lines changed

docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ Note that, like with expressions, you can specify a custom template for stream f
157157
158158
The following environment variables are provided to scripts by `rust-script`:
159159
160-
- `CARGO_SCRIPT_BASE_PATH`: the base path used by `rust-script` to resolve relative dependency paths. Note that this is *not* necessarily the same as either the working directory, or the directory in which the script is being compiled.
160+
- `RUST_SCRIPT_BASE_PATH`: the base path used by `rust-script` to resolve relative dependency paths. Note that this is *not* necessarily the same as either the working directory, or the directory in which the script is being compiled.
161161
162-
- `CARGO_SCRIPT_PKG_NAME`: the generated package name of the script.
162+
- `RUST_SCRIPT_PKG_NAME`: the generated package name of the script.
163163
164-
- `CARGO_SCRIPT_SAFE_NAME`: the file name of the script (sans file extension) being run. For scripts, this is derived from the script's filename. May also be `"expr"` or `"loop"` for those invocations.
164+
- `RUST_SCRIPT_SAFE_NAME`: the file name of the script (sans file extension) being run. For scripts, this is derived from the script's filename. May also be `"expr"` or `"loop"` for those invocations.
165165
166-
- `CARGO_SCRIPT_SCRIPT_PATH`: absolute path to the script being run, assuming one exists. Set to the empty string for expressions.
166+
- `RUST_SCRIPT_PATH`: absolute path to the script being run, assuming one exists. Set to the empty string for expressions.
167167
168168
## Templates
169169

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,12 @@ fn try_main() -> Result<i32> {
533533
}
534534
let add_env = hint(move |cmd| {
535535
cmd.env(
536-
"CARGO_SCRIPT_SCRIPT_PATH",
536+
"RUST_SCRIPT_PATH",
537537
input.path().unwrap_or_else(|| Path::new("")),
538538
);
539-
cmd.env("CARGO_SCRIPT_SAFE_NAME", input.safe_name());
540-
cmd.env("CARGO_SCRIPT_PKG_NAME", input.package_name());
541-
cmd.env("CARGO_SCRIPT_BASE_PATH", input.base_path());
539+
cmd.env("RUST_SCRIPT_SAFE_NAME", input.safe_name());
540+
cmd.env("RUST_SCRIPT_PKG_NAME", input.package_name());
541+
cmd.env("RUST_SCRIPT_BASE_PATH", input.base_path());
542542
cmd
543543
});
544544

src/platform.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ pub fn binary_cache_path() -> Result<PathBuf, MainError> {
4444
}
4545

4646
pub fn templates_dir() -> Result<PathBuf, MainError> {
47+
if cfg!(debug_assertions) {
48+
if let Ok(path) = std::env::var("RUST_SCRIPT_DEBUG_TEMPLATE_PATH") {
49+
return Ok(path.into());
50+
}
51+
}
52+
4753
dirs::data_local_dir()
4854
.map(|dir| dir.join(consts::PROGRAM_NAME).join("templates"))
4955
.ok_or_else(|| (Blame::Human, "Cannot get cache directory").into())

src/templates.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use regex::Regex;
88
use std::borrow::Cow;
99
use std::collections::HashMap;
1010
use std::fs;
11-
use std::path::PathBuf;
1211

1312
lazy_static! {
1413
static ref RE_SUB: Regex = Regex::new(r#"#\{([A-Za-z_][A-Za-z0-9_]*)}"#).unwrap();
@@ -48,28 +47,13 @@ pub fn expand(src: &str, subs: &HashMap<&str, &str>) -> Result<String> {
4847
Ok(result)
4948
}
5049

51-
/**
52-
Returns the path to the template directory.
53-
*/
54-
pub fn get_template_path() -> Result<PathBuf> {
55-
if cfg!(debug_assertions) {
56-
use std::env;
57-
if let Ok(path) = env::var("CARGO_SCRIPT_DEBUG_TEMPLATE_PATH") {
58-
return Ok(path.into());
59-
}
60-
}
61-
62-
let cache_path = platform::templates_dir()?;
63-
Ok(cache_path)
64-
}
65-
6650
/**
6751
Attempts to locate and load the contents of the specified template.
6852
*/
6953
pub fn get_template(name: &str) -> Result<Cow<'static, str>> {
7054
use std::io::Read;
7155

72-
let base = get_template_path()?;
56+
let base = platform::templates_dir()?;
7357

7458
let file = fs::File::open(base.join(format!("{}.rs", name)))
7559
.map_err(MainError::from)
@@ -107,7 +91,7 @@ fn builtin_template(name: &str) -> Option<&'static str> {
10791
pub fn list() -> Result<()> {
10892
use std::ffi::OsStr;
10993

110-
let t_path = get_template_path()?;
94+
let t_path = platform::templates_dir()?;
11195

11296
if !t_path.exists() {
11397
fs::create_dir_all(&t_path)?;

tests/data/script-cs-env.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::env;
22

33
fn main() {
44
println!("--output--");
5-
let path = env::var("CARGO_SCRIPT_SCRIPT_PATH").expect("CSSP wasn't set");
5+
let path = env::var("RUST_SCRIPT_PATH").expect("CSSP wasn't set");
66
assert!(path.ends_with("script-cs-env.rs"));
7-
assert_eq!(env::var("CARGO_SCRIPT_SAFE_NAME"), Ok("script-cs-env".into()));
8-
assert_eq!(env::var("CARGO_SCRIPT_PKG_NAME"), Ok("script-cs-env".into()));
9-
let base_path = env::var("CARGO_SCRIPT_BASE_PATH").expect("CSBP wasn't set");
7+
assert_eq!(env::var("RUST_SCRIPT_SAFE_NAME"), Ok("script-cs-env".into()));
8+
assert_eq!(env::var("RUST_SCRIPT_PKG_NAME"), Ok("script-cs-env".into()));
9+
let base_path = env::var("RUST_SCRIPT_BASE_PATH").expect("CSBP wasn't set");
1010
assert!(base_path.ends_with("data"));
1111
println!("Ok");
1212
}

tests/tests/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn test_expr_qmark() {
6666
fn test_expr_template() {
6767
let template_dir = "tests/data/templates";
6868
let out = cargo_script!(
69-
#[env(CARGO_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
69+
#[env(RUST_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
7070
"-t",
7171
"shout",
7272
"-e",
@@ -83,7 +83,7 @@ fn test_expr_template() {
8383
fn test_expr_template_with_deps() {
8484
let template_dir = "tests/data/templates";
8585
let out = cargo_script!(
86-
#[env(CARGO_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
86+
#[env(RUST_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
8787
"-t",
8888
"boolinate",
8989
"-e",
@@ -100,7 +100,7 @@ fn test_expr_template_with_deps() {
100100
fn test_expr_template_override_expr() {
101101
let template_dir = "tests/data/templates/override";
102102
let out = cargo_script!(
103-
#[env(CARGO_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
103+
#[env(RUST_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
104104
"-e",
105105
with_output_marker!(r#"true"#)
106106
)

0 commit comments

Comments
 (0)