Skip to content

Commit 497ea40

Browse files
committed
refactor: share one spelling of the schedule semaphore directory
The generated rules spelled the token directory as a literal in the admission prefix, as the $sched_sem edge variable and in the stale-token reclaim. Derive all three from one file-scope constant so they cannot drift apart.
1 parent a591f34 commit 497ea40

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/build/ninja_backend.cppm‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ namespace {
319319
// U+FEFF in UTF-8. The response files of the MSVC tools begin with it (#693).
320320
constexpr std::string_view kUtf8ByteOrderMark = "\xEF\xBB\xBF";
321321

322+
// The token directory every admission wrapper shares: the detached-compiler
323+
// edges spell it as the `$sched_sem` edge variable, the ordinary compile rules
324+
// interpolate it straight into the command, and the stale-token reclaim below
325+
// removes it. One constant, so the spellings cannot drift apart.
326+
constexpr std::string_view kSchedSemaphoreDir = ".mcpp-sched";
327+
322328
// Whether the plan's compiler names an imported module's BMI as MSVC does
323329
// (`/reference <name>=<path>`), and so reads an argument file by MSVC's rules.
324330
bool msvc_module_spelling(const BuildPlan& plan) {
@@ -1848,8 +1854,8 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
18481854
// existing shell-free depfile filter is moved into the wrapper.
18491855
const bool memoryAdmission = plan.memoryBaselineBytes != 0;
18501856
auto admission_prefix = [&]() {
1851-
return std::format("$mcpp compile-admit --sem .mcpp-sched"
1852-
" --mem-threshold {}", plan.memoryThresholdPercent);
1857+
return std::format("$mcpp compile-admit --sem {} --mem-threshold {}",
1858+
kSchedSemaphoreDir, plan.memoryThresholdPercent);
18531859
};
18541860
auto admission_dep = [&]() {
18551861
return needsGnuModuleFilter
@@ -2985,7 +2991,7 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
29852991
e += " obj_out = " + obj + "\n";
29862992
e += " slot = " + slot + "\n";
29872993
e += " scan_dep = " + escape_ninja_path(ddi) + ".dep\n";
2988-
e += " sched_sem = .mcpp-sched\n";
2994+
e += std::format(" sched_sem = {}\n", kSchedSemaphoreDir);
29892995
e += std::format(" sched_cap = {}\n", plan.scheduleCompilerCap);
29902996
e += std::format(" sched_mem_threshold = {}\n", plan.memoryThresholdPercent);
29912997
if (auto inc = local_include_flags(cu, dial); !inc.empty())
@@ -4224,7 +4230,7 @@ void reclaim_stale_schedule_tokens(const std::filesystem::path& outputDir) {
42244230
std::lock_guard lock(m);
42254231
if (!reclaimed.insert(outputDir.lexically_normal().generic_string()).second) return;
42264232
std::error_code ec;
4227-
std::filesystem::remove_all(outputDir / ".mcpp-sched", ec);
4233+
std::filesystem::remove_all(outputDir / kSchedSemaphoreDir, ec);
42284234
}
42294235

42304236
} // namespace

0 commit comments

Comments
 (0)