1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env thag
//# Purpose: Test shared target directory and executable cache logic
//# Categories: testing, demo
/// A simple demo script to test the new shared target directory and executable cache.
///
/// This script uses `serde_json` as a dependency to verify that:
/// 1. Dependencies are compiled once and shared across all scripts
/// 2. The executable is cached in the executable cache directory
/// 3. Subsequent runs are fast due to warm cache
///
/// Run with: `thag demo/test_shared_cache.rs`
/// Then run again to see the speed improvement from caching.
/// Clean cache with: `thag --clean` or `thag --clean bins`
use serde_json::{json, Value};
fn main() {
println!("Testing shared target and executable cache logic");
println!("=========================================================\n");
// Create some JSON data to demonstrate the dependency is working
let data = json!({
"script": "test_shared_cache.rs",
"purpose": "Test shared target directory",
"features": [
"Shared dependency cache",
"Executable caching",
"Faster builds"
],
"directories": {
"shared_target": "$TMPDIR/thag_rs_shared_target",
"executable_cache": "$TMPDIR/thag_rs_bins"
}
});
println!("Configuration:");
println!("{}\n", serde_json::to_string_pretty(&data).unwrap());
// Some simple computation
let features: Vec<String> = data["features"]
.as_array()
.unwrap()
.iter()
.filter_map(Value::as_str)
.map(String::from)
.collect();
println!("Features enabled:");
for (i, feature) in features.iter().enumerate() {
println!(" {}. {}", i + 1, feature);
}
println!("\n✓ Script executed successfully!");
println!("\nTip: Run this script again to see improved performance from caching.");
println!(" Use 'thag --clean' to clear all caches.");
}