Skip to main content

cache_dir

Function cache_dir 

Source
pub fn cache_dir(
    class_name: &str,
    java_class: &str,
    javac_raw: &str,
    java_raw: &str,
) -> Result<PathBuf, JavaError>
Expand description

Compute the deterministic cache-dir path used to store compiled .class files.

The path is <base_cache_dir>/<class_name>_<hex_hash>/ where hex_hash is a 64-bit hash of:

  • java_class — the complete Java source text
  • expand_java_args(javac_raw) — shell-expanded javac args (env vars and ~ substituted); relative paths in these args are anchored by the next component below
  • std::env::current_dir() — the process working directory at call time; including it ensures that two invocations with the same javac_raw containing relative paths (e.g. -cp .) but from different working directories hash to different cache entries
  • java_raw — hashed as a raw string (no expansion needed for cache differentiation; the java step always re-runs fresh)
  • detect_java_version() — the installed javac major version; ensures that upgrading the JDK produces a fresh cache entry whose .class files are compiled by the new compiler

The base directory is resolved by base_cache_dir.

§Errors

Returns JavaError::Io if javac -version cannot be run or its output cannot be parsed (see detect_java_version).