mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 18:15:48 +00:00
Build workers for testing on demand (#2018)
This commit is contained in:
@@ -55,13 +55,35 @@ pub fn validate_candidate(
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the worker paths, checks that they exist and does a version check.
|
/// Retrieves the worker paths and builds workers as needed.
|
||||||
///
|
///
|
||||||
/// NOTE: This should only be called in dev code (tests, benchmarks) as it relies on the relative
|
/// NOTE: This should only be called in dev code (tests, benchmarks) as it relies on the relative
|
||||||
/// paths of the built workers.
|
/// paths of the built workers.
|
||||||
pub fn get_and_check_worker_paths() -> (PathBuf, PathBuf) {
|
pub fn get_and_check_worker_paths() -> (PathBuf, PathBuf) {
|
||||||
// Only needs to be called once for the current process.
|
// Only needs to be called once for the current process.
|
||||||
static WORKER_PATHS: OnceLock<Mutex<(PathBuf, PathBuf)>> = OnceLock::new();
|
static WORKER_PATHS: OnceLock<Mutex<(PathBuf, PathBuf)>> = OnceLock::new();
|
||||||
|
|
||||||
|
fn build_workers() {
|
||||||
|
let build_args = vec![
|
||||||
|
"build",
|
||||||
|
"--package=polkadot",
|
||||||
|
"--bin=polkadot-prepare-worker",
|
||||||
|
"--bin=polkadot-execute-worker",
|
||||||
|
];
|
||||||
|
let exit_status = std::process::Command::new("cargo")
|
||||||
|
// wasm runtime not needed
|
||||||
|
.env("SKIP_WASM_BUILD", "1")
|
||||||
|
.args(build_args)
|
||||||
|
.stdout(std::process::Stdio::piped())
|
||||||
|
.status()
|
||||||
|
.expect("Failed to run the build program");
|
||||||
|
|
||||||
|
if !exit_status.success() {
|
||||||
|
eprintln!("Failed to build workers: {}", exit_status.code().unwrap());
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mutex = WORKER_PATHS.get_or_init(|| {
|
let mutex = WORKER_PATHS.get_or_init(|| {
|
||||||
let mut workers_path = std::env::current_exe().unwrap();
|
let mut workers_path = std::env::current_exe().unwrap();
|
||||||
workers_path.pop();
|
workers_path.pop();
|
||||||
@@ -71,25 +93,25 @@ pub fn get_and_check_worker_paths() -> (PathBuf, PathBuf) {
|
|||||||
let mut execute_worker_path = workers_path.clone();
|
let mut execute_worker_path = workers_path.clone();
|
||||||
execute_worker_path.push(EXECUTE_BINARY_NAME);
|
execute_worker_path.push(EXECUTE_BINARY_NAME);
|
||||||
|
|
||||||
// Check that the workers are valid.
|
// explain why a build happens
|
||||||
if !prepare_worker_path.is_executable() || !execute_worker_path.is_executable() {
|
if !prepare_worker_path.is_executable() {
|
||||||
panic!("ERROR: Workers do not exist or are not executable. Workers directory: {:?}", workers_path);
|
eprintln!("Prepare worker does not exist or is not executable. Workers directory: {:?}", workers_path);
|
||||||
|
}
|
||||||
|
if !execute_worker_path.is_executable() {
|
||||||
|
eprintln!("Execute worker does not exist or is not executable. Workers directory: {:?}", workers_path);
|
||||||
|
}
|
||||||
|
if let Ok(ver) = get_worker_version(&prepare_worker_path) {
|
||||||
|
if ver != NODE_VERSION {
|
||||||
|
eprintln!("Prepare worker version {ver} does not match node version {NODE_VERSION}; worker path: {prepare_worker_path:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(ver) = get_worker_version(&execute_worker_path) {
|
||||||
|
if ver != NODE_VERSION {
|
||||||
|
eprintln!("Execute worker version {ver} does not match node version {NODE_VERSION}; worker path: {execute_worker_path:?}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let worker_version =
|
build_workers();
|
||||||
get_worker_version(&prepare_worker_path).expect("checked for worker existence");
|
|
||||||
if worker_version != NODE_VERSION {
|
|
||||||
panic!("ERROR: Prepare worker version {worker_version} does not match node version {NODE_VERSION}; worker path: {prepare_worker_path:?}");
|
|
||||||
}
|
|
||||||
let worker_version =
|
|
||||||
get_worker_version(&execute_worker_path).expect("checked for worker existence");
|
|
||||||
if worker_version != NODE_VERSION {
|
|
||||||
panic!("ERROR: Execute worker version {worker_version} does not match node version {NODE_VERSION}; worker path: {execute_worker_path:?}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't want to check against the commit hash because we'd have to always rebuild
|
|
||||||
// the calling crate on every commit.
|
|
||||||
eprintln!("WARNING: Workers match the node version, but may have changed in recent commits. Please rebuild them if anything funny happens. Workers path: {workers_path:?}");
|
|
||||||
|
|
||||||
Mutex::new((prepare_worker_path, execute_worker_path))
|
Mutex::new((prepare_worker_path, execute_worker_path))
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user