forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Factor out common code into core/build_util.rs (denoland#8756)
- Loading branch information
Showing
4 changed files
with
60 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! Helper module used in cli/build.rs and runtime/build.rs | ||
use crate::JsRuntime; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
pub fn create_snapshot( | ||
mut js_runtime: JsRuntime, | ||
snapshot_path: &Path, | ||
files: Vec<PathBuf>, | ||
) { | ||
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the | ||
// workspace root. | ||
let display_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap(); | ||
for file in files { | ||
println!("cargo:rerun-if-changed={}", file.display()); | ||
let display_path = file.strip_prefix(display_root).unwrap(); | ||
let display_path_str = display_path.display().to_string(); | ||
js_runtime | ||
.execute( | ||
&("deno:".to_string() + &display_path_str.replace('\\', "/")), | ||
&std::fs::read_to_string(&file).unwrap(), | ||
) | ||
.unwrap(); | ||
} | ||
|
||
let snapshot = js_runtime.snapshot(); | ||
let snapshot_slice: &[u8] = &*snapshot; | ||
println!("Snapshot size: {}", snapshot_slice.len()); | ||
std::fs::write(&snapshot_path, snapshot_slice).unwrap(); | ||
println!("Snapshot written to: {} ", snapshot_path.display()); | ||
} | ||
|
||
pub fn get_js_files(d: &Path) -> Vec<PathBuf> { | ||
let mut js_files = std::fs::read_dir(d) | ||
.unwrap() | ||
.map(|dir_entry| { | ||
let file = dir_entry.unwrap(); | ||
d.join(file.path()) | ||
}) | ||
.filter(|path| path.extension().unwrap_or_default() == "js") | ||
.collect::<Vec<PathBuf>>(); | ||
js_files.sort(); | ||
js_files | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters