mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-02-20 12:22:23 -05:00
chore: build.rs cleanup (#1691)
This commit is contained in:
parent
f9beec4dce
commit
a8732245a7
1 changed files with 22 additions and 28 deletions
50
build.rs
50
build.rs
|
@ -318,7 +318,7 @@ fn build_v8(is_asan: bool) {
|
||||||
gn_args.push(r#"target_cpu="x86""#.to_string());
|
gn_args.push(r#"target_cpu="x86""#.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let gn_out = maybe_gen(gn_args);
|
let gn_out = maybe_gen(&gn_args);
|
||||||
assert!(gn_out.exists());
|
assert!(gn_out.exists());
|
||||||
assert!(gn_out.join("args.gn").exists());
|
assert!(gn_out.join("args.gn").exists());
|
||||||
if env_bool("PRINT_GN_ARGS") {
|
if env_bool("PRINT_GN_ARGS") {
|
||||||
|
@ -481,14 +481,14 @@ fn replace_non_alphanumeric(url: &str) -> String {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_file(url: String, filename: PathBuf) {
|
fn download_file(url: &str, filename: &Path) {
|
||||||
if !url.starts_with("http:") && !url.starts_with("https:") {
|
if !url.starts_with("http:") && !url.starts_with("https:") {
|
||||||
copy_archive(&url, &filename);
|
copy_archive(url, filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checksum (i.e: url) to avoid redownloads
|
// Checksum (i.e: url) to avoid redownloads
|
||||||
match std::fs::read_to_string(static_checksum_path(&filename)) {
|
match std::fs::read_to_string(static_checksum_path(filename)) {
|
||||||
Ok(c) if c == static_lib_url() => return,
|
Ok(c) if c == static_lib_url() => return,
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
@ -496,20 +496,15 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
// If there is a `.cargo/.rusty_v8/<escaped URL>` file, use that instead
|
// If there is a `.cargo/.rusty_v8/<escaped URL>` file, use that instead
|
||||||
// of downloading.
|
// of downloading.
|
||||||
if let Ok(mut path) = home::cargo_home() {
|
if let Ok(mut path) = home::cargo_home() {
|
||||||
path = path.join(".rusty_v8").join(replace_non_alphanumeric(&url));
|
path = path.join(".rusty_v8").join(replace_non_alphanumeric(url));
|
||||||
println!("Looking for download in '{path:?}'");
|
println!("Looking for download in '{path:?}'");
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
copy_archive(&path.to_string_lossy(), &filename);
|
copy_archive(&path.to_string_lossy(), filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tmp file to download to so we don't clobber the existing one
|
let tmpfile = filename.with_extension("tmp");
|
||||||
let tmpfile = {
|
|
||||||
let mut t = filename.clone();
|
|
||||||
t.set_extension("tmp");
|
|
||||||
t
|
|
||||||
};
|
|
||||||
if tmpfile.exists() {
|
if tmpfile.exists() {
|
||||||
println!("Deleting old tmpfile {}", tmpfile.display());
|
println!("Deleting old tmpfile {}", tmpfile.display());
|
||||||
std::fs::remove_file(&tmpfile).unwrap();
|
std::fs::remove_file(&tmpfile).unwrap();
|
||||||
|
@ -521,7 +516,7 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
let status = Command::new(python())
|
let status = Command::new(python())
|
||||||
.arg("./tools/download_file.py")
|
.arg("./tools/download_file.py")
|
||||||
.arg("--url")
|
.arg("--url")
|
||||||
.arg(&url)
|
.arg(url)
|
||||||
.arg("--filename")
|
.arg("--filename")
|
||||||
.arg(&tmpfile)
|
.arg(&tmpfile)
|
||||||
.status();
|
.status();
|
||||||
|
@ -538,7 +533,7 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
.arg("-s")
|
.arg("-s")
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
.arg(&tmpfile)
|
.arg(&tmpfile)
|
||||||
.arg(&url)
|
.arg(url)
|
||||||
.status()
|
.status()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -549,12 +544,12 @@ fn download_file(url: String, filename: PathBuf) {
|
||||||
assert!(tmpfile.exists());
|
assert!(tmpfile.exists());
|
||||||
|
|
||||||
// Write checksum (i.e url) & move file
|
// Write checksum (i.e url) & move file
|
||||||
std::fs::write(static_checksum_path(&filename), url).unwrap();
|
std::fs::write(static_checksum_path(filename), url).unwrap();
|
||||||
copy_archive(&tmpfile.to_string_lossy(), &filename);
|
copy_archive(&tmpfile.to_string_lossy(), filename);
|
||||||
std::fs::remove_file(&tmpfile).unwrap();
|
std::fs::remove_file(&tmpfile).unwrap();
|
||||||
|
|
||||||
assert!(filename.exists());
|
assert!(filename.exists());
|
||||||
assert!(static_checksum_path(&filename).exists());
|
assert!(static_checksum_path(filename).exists());
|
||||||
assert!(!tmpfile.exists());
|
assert!(!tmpfile.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,7 +561,7 @@ fn download_static_lib_binaries() {
|
||||||
std::fs::create_dir_all(&dir).unwrap();
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
println!("cargo:rustc-link-search={}", dir.display());
|
println!("cargo:rustc-link-search={}", dir.display());
|
||||||
|
|
||||||
download_file(url, static_lib_path());
|
download_file(&url, &static_lib_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decompress_to_writer<R, W>(input: &mut R, output: &mut W) -> io::Result<()>
|
fn decompress_to_writer<R, W>(input: &mut R, output: &mut W) -> io::Result<()>
|
||||||
|
@ -712,7 +707,7 @@ fn print_prebuilt_src_binding_path() {
|
||||||
if let Ok(base) = env::var("RUSTY_V8_MIRROR") {
|
if let Ok(base) = env::var("RUSTY_V8_MIRROR") {
|
||||||
let version = env::var("CARGO_PKG_VERSION").unwrap();
|
let version = env::var("CARGO_PKG_VERSION").unwrap();
|
||||||
let url = format!("{}/v{}/{}", base, version, name);
|
let url = format!("{}/v{}/{}", base, version, name);
|
||||||
download_file(url, src_binding_path.clone());
|
download_file(&url, &src_binding_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
@ -724,8 +719,9 @@ fn print_prebuilt_src_binding_path() {
|
||||||
// Chromium depot_tools contains helpers
|
// Chromium depot_tools contains helpers
|
||||||
// which delegate to the "relevant" `buildtools`
|
// which delegate to the "relevant" `buildtools`
|
||||||
// directory when invoked, so they don't count.
|
// directory when invoked, so they don't count.
|
||||||
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
fn not_in_depot_tools(p: PathBuf) -> bool {
|
fn not_in_depot_tools(p: PathBuf) -> bool {
|
||||||
!p.as_path().to_str().unwrap().contains("depot_tools")
|
!p.to_str().unwrap().contains("depot_tools")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn need_gn_ninja_download() -> bool {
|
fn need_gn_ninja_download() -> bool {
|
||||||
|
@ -926,18 +922,16 @@ fn ninja(gn_out_dir: &Path, maybe_env: Option<NinjaEnv>) -> Command {
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type GnArgs = Vec<String>;
|
fn maybe_gen(gn_args: &[String]) -> PathBuf {
|
||||||
|
|
||||||
pub fn maybe_gen(gn_args: GnArgs) -> PathBuf {
|
|
||||||
let dirs = get_dirs();
|
let dirs = get_dirs();
|
||||||
let gn_out_dir = dirs.out.join("gn_out");
|
let gn_out_dir = dirs.out.join("gn_out");
|
||||||
|
|
||||||
if !gn_out_dir.exists() || !gn_out_dir.join("build.ninja").exists() {
|
if !gn_out_dir.exists() || !gn_out_dir.join("build.ninja").exists() {
|
||||||
let args = if let Ok(extra_args) = env::var("EXTRA_GN_ARGS") {
|
let mut args = gn_args.join(" ");
|
||||||
format!("{} {}", gn_args.join(" "), extra_args)
|
if let Ok(extra_args) = env::var("EXTRA_GN_ARGS") {
|
||||||
} else {
|
args.push(' ');
|
||||||
gn_args.join(" ")
|
args.push_str(&extra_args);
|
||||||
};
|
}
|
||||||
|
|
||||||
let path = env::current_dir().unwrap();
|
let path = env::current_dir().unwrap();
|
||||||
println!("The current directory is {}", path.display());
|
println!("The current directory is {}", path.display());
|
||||||
|
|
Loading…
Add table
Reference in a new issue