@@ -421,13 +421,47 @@ namespace vix::commands::RunCommand::detail
421421 hint (" If you meant a runtime arg, use `--run` (or repeatable --args)." );
422422 }
423423
424+ unsigned long long fnv1a_64 (const std::string &input)
425+ {
426+ constexpr unsigned long long offset = 14695981039346656037ULL ;
427+ constexpr unsigned long long prime = 1099511628211ULL ;
428+
429+ unsigned long long hash = offset;
430+ for (char c : input)
431+ {
432+ const unsigned char uc = static_cast <unsigned char >(c);
433+ hash ^= static_cast <unsigned long long >(uc);
434+ hash *= prime;
435+ }
436+
437+ return hash;
438+ }
439+
440+ std::string hex_u64 (unsigned long long value)
441+ {
442+ static constexpr char digits[] = " 0123456789abcdef" ;
443+ std::string out (16 , ' 0' );
444+
445+ for (int i = 15 ; i >= 0 ; --i)
446+ {
447+ out[static_cast <std::size_t >(i)] = digits[value & 0xF ];
448+ value >>= 4ULL ;
449+ }
450+
451+ return out;
452+ }
453+
424454 ScriptProjectState prepare_script_project_state (Options &opt)
425455 {
426456 ScriptProjectState state;
427- state.script = opt.cppFile ;
457+ state.script = fs::absolute ( opt.cppFile ). lexically_normal () ;
428458 state.exeName = state.script .stem ().string ();
429- state.scriptsRoot = get_scripts_root ();
430- state.projectDir = state.scriptsRoot / state.exeName ;
459+ state.scriptsRoot = get_scripts_root (opt.localCache );
460+
461+ const std::string scriptCacheKey = hex_u64 (
462+ fnv1a_64 (" script-cache:" + state.script .string ()));
463+
464+ state.projectDir = state.scriptsRoot / scriptCacheKey;
431465 state.cmakeLists = state.projectDir / " CMakeLists.txt" ;
432466 state.buildDir = state.projectDir / " build-ninja" ;
433467 state.sigFile = state.projectDir / " .vix-config.sig" ;
@@ -874,6 +908,14 @@ namespace vix::commands::RunCommand::detail
874908 if (prepCode != 0 )
875909 return prepCode;
876910
911+ if (o.clean )
912+ {
913+ std::error_code ec;
914+ fs::remove_all (state.buildDir , ec);
915+ fs::remove (state.sigFile , ec);
916+ state.needConfigure = true ;
917+ }
918+
877919 const int code = configure_and_build_script (o, state);
878920 if (code != 0 )
879921 return code;
0 commit comments