1use std::path::{Path, PathBuf};
4
5#[must_use]
6pub fn lemma_deps_dir(workdir: &Path) -> PathBuf {
7 workdir.join(".deps")
8}
9
10#[must_use]
12pub fn relative_dependency_cache_path(registry_attribute_display: &str) -> PathBuf {
13 let last_slash_position = registry_attribute_display.rfind('/');
14 let (directory_segment, leaf_segment) = match last_slash_position {
15 Some(slice_index) => (
16 ®istry_attribute_display[..slice_index],
17 ®istry_attribute_display[slice_index + 1..],
18 ),
19 None => ("", registry_attribute_display),
20 };
21 let filename_with_suffix = format!("{}.lemma", leaf_segment);
22 if directory_segment.is_empty() {
23 PathBuf::from(filename_with_suffix)
24 } else {
25 PathBuf::from(directory_segment).join(filename_with_suffix)
26 }
27}
28
29#[must_use]
31pub fn dependency_identifier_from_dependency_path(
32 workdir: &Path,
33 dependency_path: &Path,
34) -> String {
35 let deps_dir = lemma_deps_dir(workdir);
36 let relative = dependency_path
37 .strip_prefix(&deps_dir)
38 .unwrap_or(dependency_path.as_ref());
39 let without_ext = relative.with_extension("");
40 without_ext.to_string_lossy().to_string()
41}
42
43#[must_use]
45pub fn dependency_cache_file(workdir: &Path, registry_qualifier: &str) -> PathBuf {
46 lemma_deps_dir(workdir).join(relative_dependency_cache_path(registry_qualifier))
47}