()
| 41 | } |
| 42 | |
| 43 | fn run() -> Result<()> { |
| 44 | let app = create_app(); |
| 45 | let matches = app.get_matches(); |
| 46 | let verbosity_level = matches.occurrences_of("verbose"); |
| 47 | let recompile = matches.is_present("recompile"); |
| 48 | let no_run = matches.is_present("no_run"); |
| 49 | let script_path = matches.value_of("script_path").unwrap(); |
| 50 | let script_args = values_t!(matches, "script_args", String).unwrap_or(Vec::new()); |
| 51 | |
| 52 | let (path_hash, script_hash) = |
| 53 | hash::hash_script(&script_path).chain_err(|| "Unable to take signature of script")?; |
| 54 | |
| 55 | let cache = cache::BinCache::new()?; |
| 56 | let script_cache_dir = cache.get(path_hash)?; |
| 57 | let script_hash_path = script_cache_dir.join("script_hash"); |
| 58 | let cached_script_hash = file_to_string(&script_hash_path).unwrap_or(String::new()); |
| 59 | let script_bin_path = script_cache_dir.join(SCRIPT_BIN_PATH); |
| 60 | if !script_bin_path.exists() || recompile || script_hash != cached_script_hash { |
| 61 | scriptbuilder::build_script_crate(&script_path, &script_cache_dir, verbosity_level > 0).chain_err(|| "Unable to compile the script")?; |
| 62 | string_to_file(&script_hash_path, &script_hash)? |
| 63 | } |
| 64 | if !no_run { |
| 65 | runner::run_script(&script_bin_path, script_args)?; |
| 66 | } |
| 67 | Ok(()) |
| 68 | } |
| 69 | |
| 70 | fn file_to_string<P: AsRef<Path>>(path: P) -> Result<String> { |
| 71 | let path = path.as_ref(); |
no test coverage detected