From 19cf37515284578090071d311e950805a4420ab5 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Fri, 17 Mar 2023 20:44:46 -0700 Subject: [PATCH] Don't download nodejs if NODE_BINARY is set, add YARN_BINARY (#2446) * Don't download nodejs if NODE_BINARY is set Some build environments, such as nixpkgs, restrict network access and thus would prefer to not download anything at all. Setting PROTOC_BINARY and friends makes the build system not download stuff, and the same should be true for nodejs * Allow setting YARN_BINARY for the build system * Add myself to CONTRIBUTORS As required by CI --- CONTRIBUTORS | 1 + build/ninja_gen/src/node.rs | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index a2d8fc932..19bbc0603 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -117,6 +117,7 @@ Jack Pearson yellowjello Ingemar Berg Ben Kerman +Euan Kemp ******************** diff --git a/build/ninja_gen/src/node.rs b/build/ninja_gen/src/node.rs index df05e149d..89cd16bc1 100644 --- a/build/ninja_gen/src/node.rs +++ b/build/ninja_gen/src/node.rs @@ -105,16 +105,6 @@ pub fn setup_node( binary_exports: &[&'static str], mut data_exports: HashMap<&str, Vec>>, ) -> Result<()> { - download_and_extract( - build, - "node", - archive, - hashmap! { - "bin" => vec![if cfg!(windows) { "node.exe" } else { "bin/node" }], - "npm" => vec![if cfg!(windows) { "npm.cmd " } else { "bin/npm" }] - }, - )?; - let node_binary = match std::env::var("NODE_BINARY") { Ok(path) => { assert!( @@ -124,13 +114,33 @@ pub fn setup_node( path.into() } Err(_) => { + download_and_extract( + build, + "node", + archive, + hashmap! { + "bin" => vec![if cfg!(windows) { "node.exe" } else { "bin/node" }], + "npm" => vec![if cfg!(windows) { "npm.cmd " } else { "bin/npm" }] + }, + )?; inputs![":extract:node:bin"] } }; let node_binary = build.expand_inputs(node_binary); build.variable("node_binary", &node_binary[0]); - build.add("yarn", YarnSetup {})?; + match std::env::var("YARN_BINARY") { + Ok(path) => { + assert!( + Utf8Path::new(&path).is_absolute(), + "YARN_BINARY must be absolute" + ); + build.add_resolved_files_to_group("yarn:bin", &vec![path]); + } + Err(_) => { + build.add("yarn", YarnSetup {})?; + } + }; for binary in binary_exports { data_exports.insert(