diff --git a/pylib/build.rs b/pylib/build.rs index 2678b92dc..1ea80e25a 100644 --- a/pylib/build.rs +++ b/pylib/build.rs @@ -1,11 +1,11 @@ fn main() { - rerun_if_changed("../Lib/python_builtins/*"); + process_python_libs("../Lib/python_builtins/*"); #[cfg(not(feature = "stdlib"))] - rerun_if_changed("../Lib/core_modules/*"); + process_python_libs("../Lib/core_modules/*"); #[cfg(feature = "stdlib")] - rerun_if_changed("../../Lib/**/*"); + process_python_libs("../../Lib/**/*"); if cfg!(windows) { if let Ok(real_path) = std::fs::read_to_string("Lib") { @@ -14,7 +14,8 @@ fn main() { } } -fn rerun_if_changed(pattern: &str) { +// remove *.pyc files and add *.py to watch list +fn process_python_libs(pattern: &str) { let glob = glob::glob(pattern).unwrap_or_else(|e| panic!("failed to glob {pattern:?}: {e}")); for entry in glob.flatten() { if entry.is_dir() { @@ -22,6 +23,9 @@ fn rerun_if_changed(pattern: &str) { } let display = entry.display(); if display.to_string().ends_with(".pyc") { + if std::fs::remove_file(&entry).is_err() { + println!("cargo:warning=failed to remove {display}") + } continue; } println!("cargo:rerun-if-changed={display}");