()
| 92 | } |
| 93 | |
| 94 | fn main() { |
| 95 | // Watch the project root directory so that creating/removing `stubs/` |
| 96 | // (which is gitignored) is detected via the directory mtime change. |
| 97 | // Without this, Cargo's default "any package file" check ignores |
| 98 | // gitignored paths, and explicit watches on non-existent paths don't |
| 99 | // reliably trigger when they first appear. |
| 100 | println!("cargo:rerun-if-changed=."); |
| 101 | println!("cargo:rerun-if-changed=build.rs"); |
| 102 | println!("cargo:rerun-if-changed=stubs.lock"); |
| 103 | // Re-run when HEAD moves (commit, checkout, tag) so the embedded |
| 104 | // version string stays current. |
| 105 | println!("cargo:rerun-if-changed=.git/HEAD"); |
| 106 | println!("cargo:rerun-if-changed=.git/refs/tags"); |
| 107 | |
| 108 | // ── Git version string ────────────────────────────────────────── |
| 109 | // On a release tag: "0.6.0" |
| 110 | // Between tags: "0.6.0-186-g37a901ed" (commits ahead + hash) |
| 111 | // No tags at all: "g37a901ed" (just the hash) |
| 112 | // Dirty worktree: any of the above + "-dirty" |
| 113 | // No git at all: falls back to CARGO_PKG_VERSION (crates.io builds) |
| 114 | let git_version = std::process::Command::new("git") |
| 115 | .args(["describe", "--tags", "--always", "--dirty"]) |
| 116 | .output() |
| 117 | .ok() |
| 118 | .filter(|o| o.status.success()) |
| 119 | .and_then(|o| String::from_utf8(o.stdout).ok()) |
| 120 | .map(|s| s.trim().to_string()) |
| 121 | .unwrap_or_else(|| env::var("CARGO_PKG_VERSION").unwrap_or_default()); |
| 122 | println!("cargo:rustc-env=PHPANTOM_GIT_VERSION={git_version}"); |
| 123 | |
| 124 | let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); |
| 125 | let lock = read_stubs_lock(&manifest_dir); |
| 126 | |
| 127 | let (stubs_root, mut needs_fetch) = resolve_stubs_root(); |
| 128 | |
| 129 | // Check whether the stubs need to be (re-)fetched. A `.commit` |
| 130 | // marker file inside the stubs directory records which commit was |
| 131 | // last downloaded. When `stubs.lock` pins a different commit the |
| 132 | // stubs are stale and must be replaced. |
| 133 | if !needs_fetch { |
| 134 | let stubs_path = stubs_root.join(STUBS_DIR_REL); |
| 135 | let commit_marker = stubs_path.join(".commit"); |
| 136 | if let Ok(marker) = fs::read_to_string(&commit_marker) { |
| 137 | if marker.trim() != lock.commit { |
| 138 | needs_fetch = true; |
| 139 | } |
| 140 | } else { |
| 141 | // Stubs exist but no marker — written before this check was |
| 142 | // added. Treat as stale so we re-fetch and create the marker. |
| 143 | needs_fetch = true; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if needs_fetch { |
| 148 | let stubs_path = stubs_root.join(STUBS_DIR_REL); |
| 149 | if stubs_path.exists() { |
| 150 | eprintln!( |
| 151 | "cargo:warning=Stubs are stale (expected commit {}), re-fetching...", |
nothing calls this directly
no test coverage detected