Skip to content

Commit 5c95d2b

Browse files
committed
feat(run,check): add --local-cache for script mode and unify cache behavior
- add localCache option to run and check commands - support --local-cache to use local .vix-scripts directory - default to global ~/.vix/cache/scripts for clean DX - update ScriptCMake to switch between local/global cache - propagate option through RunFlow, RunScript, and CheckScript - fix build break due to updated get_scripts_root signature - document --local-cache in CLI help
1 parent ba76acc commit 5c95d2b

7 files changed

Lines changed: 17 additions & 4 deletions

File tree

include/vix/cli/commands/check/CheckDetail.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ namespace vix::commands::CheckCommand::detail
7878
/// Absolute path of the .cpp file to validate.
7979
fs::path cppFile;
8080

81+
/// Use local .vix-scripts instead of global ~/.vix/cache/scripts.
82+
bool localCache = false;
83+
8184
/// Enable AddressSanitizer + UBSan.
8285
bool enableSanitizers = false;
8386

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ namespace vix::commands::RunCommand::detail
130130

131131
bool warnedVixFlagAfterDoubleDash = false;
132132
std::string warnedArg;
133+
134+
bool localCache = false;
133135
};
134136

135137
/**
@@ -353,7 +355,7 @@ namespace vix::commands::RunCommand::detail
353355
/**
354356
* @brief Return the root directory used for generated script projects.
355357
*/
356-
fs::path get_scripts_root();
358+
fs::path get_scripts_root(bool localCache);
357359

358360
/**
359361
* @brief Detect whether a .cpp script uses the Vix runtime.

src/commands/RunCommand.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ namespace vix::commands::RunCommand
12961296
out << " --ubsan Enable UBSan only\n";
12971297
out << " --with-sqlite Enable SQLite support for script mode\n";
12981298
out << " --with-mysql Enable MySQL support for script mode\n\n";
1299+
out << " --local-cache Use local .vix-scripts instead of global cache\n";
12991300

13001301
out << "Documentation:\n";
13011302
out << " --docs Enable auto docs (sets VIX_DOCS=1)\n";

src/commands/check/CheckScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace vix::commands::CheckCommand::detail
182182
const bool enableUbsanOnly = opt.enableUbsanOnly;
183183
const std::string exeName = script.stem().string();
184184

185-
fs::path scriptsRoot = run::get_scripts_root();
185+
fs::path scriptsRoot = run::get_scripts_root(opt.localCache);
186186
std::error_code ec;
187187
fs::create_directories(scriptsRoot, ec);
188188
if (ec)

src/commands/run/RunFlow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ namespace vix::commands::RunCommand::detail
439439
{
440440
opt.verbose = true;
441441
}
442+
else if (a == "--local-cache")
443+
{
444+
opt.localCache = true;
445+
}
442446
else if (a == "--log-level" || a == "--loglevel")
443447
{
444448
opt.logLevel = take_value(args, i, a, opt);

src/commands/run/RunScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ namespace vix::commands::RunCommand::detail
456456
ScriptProjectState state;
457457
state.script = fs::absolute(opt.cppFile).lexically_normal();
458458
state.exeName = state.script.stem().string();
459-
state.scriptsRoot = get_scripts_root();
459+
state.scriptsRoot = get_scripts_root(opt.localCache);
460460

461461
const std::string scriptCacheKey = hex_u64(
462462
fnv1a_64("script-cache:" + state.script.string()));

src/commands/run/detail/ScriptCMake.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,11 @@ namespace vix::commands::RunCommand::detail
12901290
return false;
12911291
}
12921292

1293-
fs::path get_scripts_root()
1293+
fs::path get_scripts_root(bool localCache)
12941294
{
1295+
if (localCache)
1296+
return fs::current_path() / ".vix-scripts";
1297+
12951298
if (const auto home = home_dir(); home)
12961299
return fs::path(*home) / ".vix" / "cache" / "scripts";
12971300

0 commit comments

Comments
 (0)