use std::path::{Path, PathBuf};
use harn_vm::module_artifact::ModuleCompilationContext;
use crate::compiler_context::{imported_symbols_for_source, SourceCompilerAuthority};
pub(super) struct ArtifactKeys {
pub(super) entry: harn_vm::bytecode_cache::CacheKey,
pub(super) module: harn_vm::bytecode_cache::CacheKey,
}
impl ArtifactKeys {
pub(super) fn match_artifacts_at(&self, entry_dest: &Path, module_dest: &Path) -> bool {
harn_vm::bytecode_cache::entry_artifact_at_matches(entry_dest, &self.entry)
&& harn_vm::bytecode_cache::module_artifact_at_matches(module_dest, &self.module)
}
}
pub(super) fn artifact_keys(
source_path: &Path,
source: &str,
source_root: Option<&Path>,
authority: &SourceCompilerAuthority,
) -> (ArtifactKeys, ModuleCompilationContext) {
let entry = if source_root.is_some() {
harn_vm::bytecode_cache::CacheKey::from_relocatable_source(source_path, source)
} else {
harn_vm::bytecode_cache::CacheKey::from_source(source_path, source)
};
let compilation_context = imported_symbols_for_source(source_path, source);
let module_source = harn_vm::module_source::ModuleSource::from_text(source);
let module = harn_vm::bytecode_cache::CacheKey::from_module_source(
&module_source,
&compilation_context,
authority.module_provenance(),
);
(ArtifactKeys { entry, module }, compilation_context)
}
pub(super) enum Outcome {
Compiled(PathBuf),
Reused(PathBuf),
}
impl Outcome {
pub(super) fn destination(&self) -> &PathBuf {
match self {
Outcome::Compiled(path) | Outcome::Reused(path) => path,
}
}
}