Rerun build if any file in a directory has changed (#2343)

This commit is contained in:
jackcmay 2019-01-09 09:56:23 -08:00 committed by GitHub
parent e0c68bf9ad
commit 56b6ed6730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 30 deletions

21
Cargo.lock generated
View File

@ -1683,6 +1683,14 @@ name = "safemem"
version = "0.3.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "same-file"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.14" version = "0.1.14"
@ -1913,6 +1921,7 @@ dependencies = [
"solana-logger 0.12.0", "solana-logger 0.12.0",
"solana-sdk 0.12.0", "solana-sdk 0.12.0",
"solana_rbpf 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "solana_rbpf 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -2802,6 +2811,16 @@ name = "void"
version = "1.0.2" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "walkdir"
version = "2.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "want" name = "want"
version = "0.0.6" version = "0.0.6"
@ -3091,6 +3110,7 @@ dependencies = [
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"checksum schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56" "checksum schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56"
"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
@ -3172,6 +3192,7 @@ dependencies = [
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1"
"checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3"
"checksum which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e84a603e7e0b1ce1aa1ee2b109c7be00155ce52df5081590d1ffb93f4f515cb2" "checksum which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e84a603e7e0b1ce1aa1ee2b109c7be00155ce52df5081590d1ffb93f4f515cb2"
"checksum widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb" "checksum widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb"

View File

@ -23,6 +23,9 @@ serde = "1.0.84"
solana-logger = { path = "../../../logger", version = "0.12.0" } solana-logger = { path = "../../../logger", version = "0.12.0" }
solana-sdk = { path = "../../../sdk", version = "0.12.0" } solana-sdk = { path = "../../../sdk", version = "0.12.0" }
[build-dependencies]
walkdir = "2"
[lib] [lib]
name = "solana_bpf_loader" name = "solana_bpf_loader"
crate-type = ["lib", "cdylib"] crate-type = ["lib", "cdylib"]

View File

@ -1,6 +1,30 @@
extern crate walkdir;
use std::env; use std::env;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use walkdir::WalkDir;
fn rerun_if_changed(files: &[&str], directories: &[&str]) {
let mut all_files: Vec<_> = files.iter().map(|f| f.to_string()).collect();
for directory in directories {
let files_in_directory: Vec<_> = WalkDir::new(directory)
.into_iter()
.map(|entry| entry.unwrap())
.filter(|entry| entry.file_type().is_file())
.map(|f| f.path().to_str().unwrap().to_owned())
.collect();
all_files.extend_from_slice(&files_in_directory[..]);
}
for file in all_files {
if !Path::new(&file).is_file() {
panic!("{} is not a file", file);
}
println!("cargo:rerun-if-changed={}", file);
}
}
fn main() { fn main() {
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
@ -11,24 +35,18 @@ fn main() {
+ &env::var("PROFILE").unwrap() + &env::var("PROFILE").unwrap()
+ &"/bpf".to_string(); + &"/bpf".to_string();
let rerun_if_changed_files = vec![ rerun_if_changed(
"../../../sdk/bpf/bpf.mk", &[
"../../../sdk/bpf/inc/solana_sdk.h", "../../../sdk/bpf/bpf.ld",
"../../bpf/c/makefile", "../../../sdk/bpf/bpf.mk",
"../../bpf/c/src/bench_alu.c", "../../bpf/c/makefile",
"../../bpf/c/src/move_funds.c", ],
"../../bpf/c/src/noop++.cc", &[
"../../bpf/c/src/noop.c", "../../../sdk/bpf/inc",
"../../bpf/c/src/struct_pass.c", "../../../sdk/bpf/scripts",
"../../bpf/c/src/struct_ret.c", "../../bpf/c/src",
]; ],
);
for file in rerun_if_changed_files {
if !Path::new(file).is_file() {
panic!("{} is not a file", file);
}
println!("cargo:rerun-if-changed={}", file);
}
println!("cargo:warning=(not a warning) Compiling C-based BPF programs"); println!("cargo:warning=(not a warning) Compiling C-based BPF programs");
let status = Command::new("make") let status = Command::new("make")
@ -56,18 +74,14 @@ fn main() {
); );
} }
let rerun_if_changed_files = vec![ rerun_if_changed(
"../../bpf/rust/noop/bpf.ld", &[
"../../bpf/rust/noop/makefile", "../../bpf/rust/noop/bpf.ld",
"../../bpf/rust/noop/out/solana_bpf_rust_noop.so", "../../bpf/rust/noop/makefile",
]; "../../bpf/rust/noop/out/solana_bpf_rust_noop.so",
],
for file in rerun_if_changed_files { &[],
if !Path::new(file).is_file() { );
panic!("{} is not a file", file);
}
println!("cargo:rerun-if-changed={}", file);
}
println!( println!(
"cargo:warning=(not a warning) Installing Rust-based BPF program: solana_bpf_rust_noop" "cargo:warning=(not a warning) Installing Rust-based BPF program: solana_bpf_rust_noop"