Read `stubs.lock` and return the pinned commit + hash. Panics if the file is missing or malformed — `stubs.lock` is checked into version control and must always be present.
(manifest_dir: &str)
| 316 | /// Panics if the file is missing or malformed — `stubs.lock` is checked |
| 317 | /// into version control and must always be present. |
| 318 | fn read_stubs_lock(manifest_dir: &str) -> StubsLock { |
| 319 | let lock_path = Path::new(manifest_dir).join("stubs.lock"); |
| 320 | let content = fs::read_to_string(&lock_path) |
| 321 | .unwrap_or_else(|e| panic!("Failed to read stubs.lock: {}\nThis file is required and should be checked into version control.", e)); |
| 322 | |
| 323 | let mut repo: Option<String> = None; |
| 324 | let mut commit: Option<String> = None; |
| 325 | let mut sha256: Option<String> = None; |
| 326 | |
| 327 | for line in content.lines() { |
| 328 | let line = line.trim(); |
| 329 | if line.is_empty() || line.starts_with('#') { |
| 330 | continue; |
| 331 | } |
| 332 | if let Some((key, value)) = line.split_once('=') { |
| 333 | let key = key.trim(); |
| 334 | let value = value.trim().trim_matches('"'); |
| 335 | match key { |
| 336 | "repo" => repo = Some(value.to_string()), |
| 337 | "commit" => commit = Some(value.to_string()), |
| 338 | "sha256" => sha256 = Some(value.to_string()), |
| 339 | _ => {} |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | StubsLock { |
| 345 | repo: repo.unwrap_or_else(|| "JetBrains/phpstorm-stubs".to_string()), |
| 346 | commit: commit.expect("stubs.lock is missing 'commit' field"), |
| 347 | sha256: sha256.expect("stubs.lock is missing 'sha256' field"), |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /// Compute the SHA-256 hex digest of a byte slice. |
| 352 | fn sha256_hex(data: &[u8]) -> String { |