updates build_system.cpp to be more independant

This commit is contained in:
2026-07-23 16:44:42 -04:00
parent f31c9d4a6b
commit 36c9ef132d
2 changed files with 462 additions and 549 deletions
+391 -383
View File
@@ -1,5 +1,5 @@
// tools/build_check.cpp - Fast native C++ build helper tool for Juliet project
// Replaces all PowerShell scripts (build_helper.ps1, check_target.ps1, clean_unity.ps1, summary_helper.ps1)
// tools/build.cpp - Fast native C++ build orchestrator for Juliet project
// Replaces all PowerShell scripts and orchestrates the full build process
#ifndef NOMINMAX
#define NOMINMAX
#endif
@@ -604,417 +604,433 @@ static void CollectUnityFiles(const char* dirPath, FilePathList& list)
// Commands
// ============================================================================
static int CommandStartBuild()
{
EnsureDirectoryExists("Intermediate");
struct BuildStep {
char StepName[256];
char OutputFile[MaxPath];
char Depends[MaxPath];
char Command[MaxFiles];
};
DeleteFileA("Intermediate\\step_start.tmp");
struct BuildConfig {
char Name[64];
char FastBuildTargets[512];
BuildStep Steps[32];
int StepCount;
};
static int CommandRunPlan(int argc, char* argv[])
{
if (argc < 3)
{
printf("[ERROR] Usage: build_system run_plan <plan_file.txt>\n");
return 1;
}
const char* planFile = argv[2];
FileContent planContent = ReadEntireFile(planFile);
if (!planContent.Data)
{
printf("[ERROR] Could not read build plan: %s\n", planFile);
return 1;
}
EnsureDirectoryExists("Intermediate");
DeleteFileA("Intermediate\\step_timings.tmp");
DeleteFileA("Intermediate\\built_outputs.tmp");
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
ULARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
LARGE_INTEGER perfStart, perfEnd, perfFreq;
QueryPerformanceCounter(&perfStart);
QueryPerformanceFrequency(&perfFreq);
char buf[32];
sprintf_s(buf, "%llu", li.QuadPart);
WriteEntireFile("Intermediate\\build_start.tmp", buf, static_cast<DWORD>(strlen(buf)));
return 0;
}
static int CommandStartStep(int argc, char* argv[])
{
assert(argv != nullptr);
EnsureDirectoryExists("Intermediate");
const char* stepName = (argc > 2 && argv[2] != nullptr) ? argv[2] : "Unnamed Step";
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
ULARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
char buf[MaxPath + 64];
int len = sprintf_s(buf, "%s\n%llu\n", stepName, li.QuadPart);
if (len > 0)
// Parse plan file
BuildConfig configs[4] = {};
int configCount = 0;
const char* pos = planContent.Data;
while (*pos != '\0')
{
WriteEntireFile("Intermediate\\step_start.tmp", buf, static_cast<DWORD>(len));
}
return 0;
}
static int CommandEndStep(int argc, char* argv[])
{
assert(argv != nullptr);
if (!FileExists("Intermediate\\step_start.tmp"))
{
return 0;
}
FileContent content = ReadEntireFile("Intermediate\\step_start.tmp");
if (content.Data == nullptr)
{
return 0;
}
char stepName[MaxPath] = "Unnamed Step";
uint64_t startTicks = 0;
const char* line1End = strchr(content.Data, '\n');
if (line1End != nullptr)
{
int nameLen = static_cast<int>(line1End - content.Data);
if (nameLen > 0 && nameLen < MaxPath)
const char* lineStart = pos;
while (*pos != '\0' && *pos != '\n' && *pos != '\r') pos++;
int lineLen = static_cast<int>(pos - lineStart);
if (lineLen > 0)
{
memcpy(stepName, content.Data, static_cast<size_t>(nameLen));
stepName[nameLen] = '\0';
}
sscanf_s(line1End + 1, "%llu", &startTicks);
}
FreeFileContent(content);
DeleteFileA("Intermediate\\step_start.tmp");
if (argc > 2 && argv[2] != nullptr && argv[2][0] != '\0')
{
strncpy_s(stepName, argv[2], MaxPath - 1);
}
FILETIME ftNow;
GetSystemTimeAsFileTime(&ftNow);
ULARGE_INTEGER nowLi;
nowLi.LowPart = ftNow.dwLowDateTime;
nowLi.HighPart = ftNow.dwHighDateTime;
double elapsedSeconds = static_cast<double>(nowLi.QuadPart - startTicks) / 10000000.0;
char appendBuf[MaxPath + 64];
int appendLen = sprintf_s(appendBuf, "%s|%.3fs\n", stepName, elapsedSeconds);
if (appendLen > 0)
{
FileContent existing = ReadEntireFile("Intermediate\\step_timings.tmp");
DWORD newSize = static_cast<DWORD>(appendLen) + existing.Size;
char* combined = static_cast<char*>(HeapAlloc(GetProcessHeap(), 0, newSize + 1));
if (combined != nullptr)
{
DWORD offset = 0;
if (existing.Data != nullptr && existing.Size > 0)
if (lineLen > 7 && memcmp(lineStart, "CONFIG ", 7) == 0)
{
memcpy(combined, existing.Data, existing.Size);
offset = existing.Size;
if (configCount < 4)
{
int nLen = lineLen - 7;
if (nLen >= static_cast<int>(sizeof(configs[configCount].Name))) nLen = static_cast<int>(sizeof(configs[configCount].Name)) - 1;
memcpy(configs[configCount].Name, lineStart + 7, nLen);
configs[configCount].Name[nLen] = '\0';
configCount++;
}
}
memcpy(combined + offset, appendBuf, static_cast<size_t>(appendLen));
combined[newSize] = '\0';
WriteEntireFile("Intermediate\\step_timings.tmp", combined, newSize);
HeapFree(GetProcessHeap(), 0, combined);
}
FreeFileContent(existing);
}
return 0;
}
static int CommandFinishBuild()
{
// Compute elapsed time
const char* elapsedStr = "0.000s";
char elapsedBuf[64] = {};
if (FileExists("Intermediate\\build_start.tmp"))
{
FileContent startContent = ReadEntireFile("Intermediate\\build_start.tmp");
if (startContent.Data != nullptr)
{
uint64_t startTicks = 0;
sscanf_s(startContent.Data, "%llu", &startTicks);
FreeFileContent(startContent);
FILETIME ftNow;
GetSystemTimeAsFileTime(&ftNow);
ULARGE_INTEGER nowLi;
nowLi.LowPart = ftNow.dwLowDateTime;
nowLi.HighPart = ftNow.dwHighDateTime;
double elapsedSeconds = static_cast<double>(nowLi.QuadPart - startTicks) / 10000000.0;
if (elapsedSeconds < 60.0)
else if (configCount > 0)
{
sprintf_s(elapsedBuf, "%.3fs", elapsedSeconds);
BuildConfig& curCfg = configs[configCount - 1];
if (lineLen > 10 && memcmp(lineStart, "FASTBUILD ", 10) == 0)
{
int nLen = lineLen - 10;
if (nLen >= static_cast<int>(sizeof(curCfg.FastBuildTargets))) nLen = static_cast<int>(sizeof(curCfg.FastBuildTargets)) - 1;
memcpy(curCfg.FastBuildTargets, lineStart + 10, nLen);
curCfg.FastBuildTargets[nLen] = '\0';
}
else if (lineLen > 5 && memcmp(lineStart, "STEP ", 5) == 0)
{
if (curCfg.StepCount < 32)
{
int nLen = lineLen - 5;
if (nLen >= static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount].StepName))) nLen = static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount].StepName)) - 1;
memcpy(curCfg.Steps[curCfg.StepCount].StepName, lineStart + 5, nLen);
curCfg.Steps[curCfg.StepCount].StepName[nLen] = '\0';
curCfg.StepCount++;
}
}
else if (lineLen > 7 && memcmp(lineStart, "OUTPUT ", 7) == 0 && curCfg.StepCount > 0)
{
int nLen = lineLen - 7;
if (nLen >= static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount - 1].OutputFile))) nLen = static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount - 1].OutputFile)) - 1;
memcpy(curCfg.Steps[curCfg.StepCount - 1].OutputFile, lineStart + 7, nLen);
curCfg.Steps[curCfg.StepCount - 1].OutputFile[nLen] = '\0';
}
else if (lineLen > 8 && memcmp(lineStart, "DEPENDS ", 8) == 0 && curCfg.StepCount > 0)
{
int nLen = lineLen - 8;
if (nLen >= static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount - 1].Depends))) nLen = static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount - 1].Depends)) - 1;
memcpy(curCfg.Steps[curCfg.StepCount - 1].Depends, lineStart + 8, nLen);
curCfg.Steps[curCfg.StepCount - 1].Depends[nLen] = '\0';
}
else if (lineLen > 8 && memcmp(lineStart, "COMMAND ", 8) == 0 && curCfg.StepCount > 0)
{
int nLen = lineLen - 8;
if (nLen >= static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount - 1].Command))) nLen = static_cast<int>(sizeof(curCfg.Steps[curCfg.StepCount - 1].Command)) - 1;
memcpy(curCfg.Steps[curCfg.StepCount - 1].Command, lineStart + 8, nLen);
curCfg.Steps[curCfg.StepCount - 1].Command[nLen] = '\0';
}
}
}
while (*pos == '\n' || *pos == '\r') pos++;
}
FreeFileContent(planContent);
bool anyBuilt = false;
char timingsBuf[MaxFiles * 2] = {};
int timingsLen = 0;
auto AppendTiming = [&](const char* stepName, double secs)
{
timingsLen += sprintf_s(timingsBuf + timingsLen, sizeof(timingsBuf) - timingsLen, "%s|%.3fs\n", stepName, secs);
};
auto ExecuteCmd = [](const char* cmdLine) -> int
{
STARTUPINFOA si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi = {};
DWORD exitCode = 1;
char* cmdBuf = static_cast<char*>(HeapAlloc(GetProcessHeap(), 0, MaxFiles));
if (!cmdBuf) return 1;
strcpy_s(cmdBuf, MaxFiles, cmdLine);
if (CreateProcessA(nullptr, cmdBuf, nullptr, nullptr, TRUE, 0, nullptr, nullptr, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &exitCode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else
{
printf("[ERROR] Failed to execute command.\n");
HeapFree(GetProcessHeap(), 0, cmdBuf);
return 1;
}
HeapFree(GetProcessHeap(), 0, cmdBuf);
return static_cast<int>(exitCode);
};
for (int i = 0; i < configCount; i++)
{
BuildConfig& cfg = configs[i];
printf("\n==============================================================================\n");
printf("Generating Unity Files into Intermediate/ via FASTBuild [%s]...\n", cfg.Name);
printf("==============================================================================\n");
if (cfg.FastBuildTargets[0] != '\0')
{
char fbuildCmd[MaxPath];
sprintf_s(fbuildCmd, sizeof(fbuildCmd), "misc\\fbuild.exe %s", cfg.FastBuildTargets);
LARGE_INTEGER tStart, tEnd;
QueryPerformanceCounter(&tStart);
int res = ExecuteCmd(fbuildCmd);
QueryPerformanceCounter(&tEnd);
char stepName[MaxPath];
sprintf_s(stepName, sizeof(stepName), "FASTBuild Unity Gen [%s]", cfg.Name);
AppendTiming(stepName, static_cast<double>(tEnd.QuadPart - tStart.QuadPart) / static_cast<double>(perfFreq.QuadPart));
if (res != 0)
{
printf("[BUILD FAILED] FASTBuild failed for %s.\n", cfg.Name);
return res;
}
}
HashCache oldCache;
LoadHashCache("Intermediate\\.unity_hashes_cache", oldCache);
HashCache newCache;
bool unityChanged = false;
FilePathList unityFiles;
CollectUnityFiles("Intermediate", unityFiles);
if (unityFiles.Count == 0)
{
unityChanged = true;
}
else
{
for (int k = 0; k < unityFiles.Count; k++)
{
CleanResult cr = CleanAndHashUnityFile(unityFiles.Paths[k].Data);
newCache.Add(unityFiles.Paths[k].Data, cr.HashStr);
const char* oldHash = oldCache.Find(unityFiles.Paths[k].Data);
if (oldHash == nullptr || strcmp(oldHash, cr.HashStr) != 0)
{
unityChanged = true;
}
}
}
SaveHashCache("Intermediate\\.unity_hashes_cache", newCache);
if (unityChanged)
{
printf("[FASTBuild] Unity structure or source file list changed.\n");
}
else
{
printf("[FASTBuild] No Unity file structure changes detected [up-to-date].\n");
}
printf("\n==============================================================================\n");
printf("Compiling Targets [%s]...\n", cfg.Name);
printf("==============================================================================\n");
struct DirCacheEntry { FixedString Path; int64_t Time; };
DirCacheEntry dirCache[64];
int dirCacheCount = 0;
auto GetDirTime = [&](const char* dir) -> int64_t
{
for (int k = 0; k < dirCacheCount; k++)
{
if (dirCache[k].Path.EqualsNoCase(dir)) return dirCache[k].Time;
}
int64_t t = GetNewestSourceTimeRecursive(dir);
if (dirCacheCount < 64)
{
dirCache[dirCacheCount].Path.Set(dir);
dirCache[dirCacheCount].Time = t;
dirCacheCount++;
}
return t;
};
bool anyNeedBuild = false;
for (int j = 0; j < cfg.StepCount; j++)
{
BuildStep& step = cfg.Steps[j];
int64_t maxTime = 0;
const char* cur = step.Depends;
while (*cur)
{
const char* nextPipe = strchr(cur, '|');
char dirPath[MaxPath] = {};
if (nextPipe)
{
int dLen = static_cast<int>(nextPipe - cur);
if (dLen >= static_cast<int>(sizeof(dirPath))) dLen = static_cast<int>(sizeof(dirPath)) - 1;
memcpy(dirPath, cur, dLen);
dirPath[dLen] = '\0';
cur = nextPipe + 1;
}
else
{
strcpy_s(dirPath, sizeof(dirPath), cur);
cur += strlen(cur);
}
if (dirPath[0] != '\0')
{
int64_t t = GetDirTime(dirPath);
if (t > maxTime) maxTime = t;
}
}
bool needCompile = unityChanged;
if (!needCompile)
{
if (!FileExists(step.OutputFile))
{
needCompile = true;
}
else
{
int64_t outTime = GetFileModTimeInt64(step.OutputFile);
if (outTime < maxTime) needCompile = true;
}
}
printf("\n--- %s ---\n", step.StepName);
if (!needCompile)
{
printf("[SKIP / UP-TO-DATE] %s [Binary up to date]\n", step.OutputFile);
}
else
{
int totalMs = static_cast<int>(elapsedSeconds * 1000.0);
int hours = totalMs / 3600000;
int minutes = (totalMs % 3600000) / 60000;
int seconds = (totalMs % 60000) / 1000;
int ms = totalMs % 1000;
sprintf_s(elapsedBuf, "%02d:%02d:%02d.%03d", hours, minutes, seconds, ms);
printf("[REBUILDING] Compiling %s...\n", step.OutputFile);
anyNeedBuild = true;
LARGE_INTEGER tStart, tEnd;
QueryPerformanceCounter(&tStart);
int res = ExecuteCmd(step.Command);
QueryPerformanceCounter(&tEnd);
AppendTiming(step.StepName, static_cast<double>(tEnd.QuadPart - tStart.QuadPart) / static_cast<double>(perfFreq.QuadPart));
if (res != 0)
{
printf("[BUILD FAILED] Command failed with exit code %d.\n", res);
return res;
}
char builtOut[MaxPath + 2];
sprintf_s(builtOut, "%s\n", step.OutputFile);
HANDLE hFile = CreateFileA("Intermediate\\built_outputs.tmp", FILE_APPEND_DATA, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD written = 0;
WriteFile(hFile, builtOut, static_cast<DWORD>(strlen(builtOut)), &written, nullptr);
CloseHandle(hFile);
}
anyBuilt = true;
}
elapsedStr = elapsedBuf;
}
DeleteFileA("Intermediate\\build_start.tmp");
}
if (FileExists("Intermediate\\step_timings.tmp"))
{
FileContent timingsContent = ReadEntireFile("Intermediate\\step_timings.tmp");
if (timingsContent.Data != nullptr && timingsContent.Size > 0)
if (!anyNeedBuild)
{
printf("Step Timings:\n");
const char* pos = timingsContent.Data;
while (*pos != '\0')
{
const char* lineStart = pos;
while (*pos != '\0' && *pos != '\n' && *pos != '\r')
{
pos++;
}
int lineLen = static_cast<int>(pos - lineStart);
while (*pos == '\n' || *pos == '\r')
{
pos++;
}
if (lineLen > 0)
{
const char* pipePos = nullptr;
for (const char* p = lineStart; p < lineStart + lineLen; p++)
{
if (*p == '|')
{
pipePos = p;
break;
}
}
if (pipePos != nullptr)
{
char stepName[MaxPath] = {};
int nameLen = static_cast<int>(pipePos - lineStart);
if (nameLen < MaxPath)
{
memcpy(stepName, lineStart, static_cast<size_t>(nameLen));
stepName[nameLen] = '\0';
}
char durationStr[64] = {};
int durLen = static_cast<int>((lineStart + lineLen) - (pipePos + 1));
if (durLen < 64)
{
memcpy(durationStr, pipePos + 1, static_cast<size_t>(durLen));
durationStr[durLen] = '\0';
}
printf(" - %-42s : %s\n", stepName, durationStr);
}
}
}
printf("------------------------------------------------------------------------------\n");
FreeFileContent(timingsContent);
printf("\n[SKIP / UP-TO-DATE] All requested targets in [%s] are up-to-date.\n", cfg.Name);
}
DeleteFileA("Intermediate\\step_timings.tmp");
}
printf("Total Duration : %s\n", elapsedStr);
if (timingsLen > 0)
{
WriteEntireFile("Intermediate\\step_timings.tmp", timingsBuf, timingsLen);
}
QueryPerformanceCounter(&perfEnd);
double elapsedSeconds = static_cast<double>(perfEnd.QuadPart - perfStart.QuadPart) / static_cast<double>(perfFreq.QuadPart);
char elapsedBuf[64];
if (elapsedSeconds < 60.0)
{
sprintf_s(elapsedBuf, "%.3fs", elapsedSeconds);
}
else
{
int totalMs = static_cast<int>(elapsedSeconds * 1000.0);
int hours = totalMs / 3600000;
int minutes = (totalMs % 3600000) / 60000;
int seconds = (totalMs % 60000) / 1000;
int ms = totalMs % 1000;
sprintf_s(elapsedBuf, "%02d:%02d:%02d.%03d", hours, minutes, seconds, ms);
}
printf("\n==============================================================================\n");
printf("[BUILD SUMMARY]\n");
printf("==============================================================================\n");
if (timingsLen > 0)
{
printf("Step Timings:\n");
const char* pos = timingsBuf;
while (*pos)
{
const char* lineStart = pos;
while (*pos && *pos != '\n') pos++;
int len = static_cast<int>(pos - lineStart);
if (len > 0)
{
const char* pipe = strchr(lineStart, '|');
if (pipe && pipe < pos)
{
char stepName[MaxPath] = {};
int nameLen = static_cast<int>(pipe - lineStart);
memcpy(stepName, lineStart, nameLen);
char durStr[64] = {};
int durLen = static_cast<int>(pos - (pipe + 1));
memcpy(durStr, pipe + 1, durLen);
printf(" - %-42s : %s\n", stepName, durStr);
}
}
if (*pos == '\n') pos++;
}
printf("------------------------------------------------------------------------------\n");
}
printf("Total Duration : %s\n", elapsedBuf);
printf("Output Binaries:\n");
if (FileExists("Intermediate\\built_outputs.tmp"))
if (anyBuilt)
{
FileContent outputsContent = ReadEntireFile("Intermediate\\built_outputs.tmp");
bool anyPrinted = false;
if (outputsContent.Data != nullptr)
if (outputsContent.Data)
{
const char* pos = outputsContent.Data;
while (*pos != '\0')
while (*pos)
{
const char* lineStart = pos;
while (*pos != '\0' && *pos != '\n' && *pos != '\r')
while (*pos && *pos != '\n' && *pos != '\r') pos++;
int len = static_cast<int>(pos - lineStart);
if (len > 0)
{
pos++;
}
int lineLen = static_cast<int>(pos - lineStart);
while (*pos == '\n' || *pos == '\r')
{
pos++;
}
if (lineLen > 0)
{
char filePath[MaxPath];
if (lineLen < MaxPath)
char filePath[MaxPath] = {};
memcpy(filePath, lineStart, len);
WIN32_FILE_ATTRIBUTE_DATA fileData;
if (GetFileAttributesExA(filePath, GetFileExInfoStandard, &fileData))
{
memcpy(filePath, lineStart, static_cast<size_t>(lineLen));
filePath[lineLen] = '\0';
if (FileExists(filePath))
{
WIN32_FILE_ATTRIBUTE_DATA fileData;
if (GetFileAttributesExA(filePath, GetFileExInfoStandard, &fileData))
{
ULARGE_INTEGER fileSize;
fileSize.LowPart = fileData.nFileSizeLow;
fileSize.HighPart = fileData.nFileSizeHigh;
double sizeMB = static_cast<double>(fileSize.QuadPart) / (1024.0 * 1024.0);
printf(" - %s (%.2f MB)\n", filePath, sizeMB);
anyPrinted = true;
}
}
ULARGE_INTEGER fileSize;
fileSize.LowPart = fileData.nFileSizeLow;
fileSize.HighPart = fileData.nFileSizeHigh;
double sizeMB = static_cast<double>(fileSize.QuadPart) / (1024.0 * 1024.0);
printf(" - %s (%.2f MB)\n", filePath, sizeMB);
}
}
while (*pos == '\n' || *pos == '\r') pos++;
}
FreeFileContent(outputsContent);
}
if (!anyPrinted)
{
printf(" - None built in this session (all requested targets up-to-date)\n");
}
DeleteFileA("Intermediate\\built_outputs.tmp");
}
else
{
printf(" - None built in this session (all requested targets up-to-date)\n");
}
printf("==============================================================================\n");
printf("[ALL BUILDS SUCCEEDED] All requested targets processed successfully.\n");
printf("==============================================================================\n");
fflush(stdout);
return 0;
}
static int CommandEvaluate(int argc, char* argv[])
{
LARGE_INTEGER perfStart, perfEnd, perfFreq;
QueryPerformanceCounter(&perfStart);
QueryPerformanceFrequency(&perfFreq);
const char* cfg = (argc > 2) ? argv[2] : "Debug";
bool targetJuliet = (argc > 3) && argv[3][0] == '1';
bool targetGame = (argc > 4) && argv[4][0] == '1';
bool targetRomeo = (argc > 5) && argv[5][0] == '1';
bool targetShader = (argc > 6) && argv[6][0] == '1';
EnsureDirectoryExists("Intermediate");
// 1. Process unity files: clean #pragma message, compute hashes, detect changes
HashCache oldCache;
LoadHashCache("Intermediate\\.unity_hashes_cache", oldCache);
HashCache newCache;
bool unityChanged = false;
FilePathList unityFiles;
CollectUnityFiles("Intermediate", unityFiles);
if (unityFiles.Count == 0)
{
unityChanged = true;
}
else
{
for (int i = 0; i < unityFiles.Count; i++)
{
CleanResult cr = CleanAndHashUnityFile(unityFiles.Paths[i].Data);
newCache.Add(unityFiles.Paths[i].Data, cr.HashStr);
const char* oldHash = oldCache.Find(unityFiles.Paths[i].Data);
if (oldHash == nullptr || strcmp(oldHash, cr.HashStr) != 0)
{
unityChanged = true;
}
}
}
SaveHashCache("Intermediate\\.unity_hashes_cache", newCache);
// 2. Scan source directory modification times once
int64_t julietTime = GetNewestSourceTimeRecursive("Juliet");
int64_t gameTime = GetNewestSourceTimeRecursive("Game");
int64_t imguiTime = GetNewestSourceTimeRecursive("External\\imgui");
int64_t appTime = GetNewestSourceTimeRecursive("JulietApp");
int64_t romeoTime = GetNewestSourceTimeRecursive("Romeo");
int64_t shaderTime = GetNewestSourceTimeRecursive("JulietShaderCompiler");
auto MaxTime = [](int64_t a, int64_t b) -> int64_t { return (a > b) ? a : b; };
int64_t julietCombined = MaxTime(julietTime, imguiTime);
int64_t gameCombined = MaxTime(MaxTime(julietTime, gameTime), imguiTime);
int64_t appCombined = MaxTime(MaxTime(MaxTime(julietTime, gameTime), appTime), imguiTime);
int64_t romeoCombined = MaxTime(MaxTime(julietTime, romeoTime), imguiTime);
int64_t shaderCombined = MaxTime(MaxTime(julietTime, shaderTime), imguiTime);
// Build paths for target binaries
char binDir[MaxPath];
char intDir[MaxPath];
sprintf_s(binDir, "bin\\x64-%s", cfg);
sprintf_s(intDir, "Intermediate\\x64-%s", cfg);
auto IsUpToDate = [](const char* targetPath, int64_t newestSourceTime) -> bool
{
assert(targetPath != nullptr);
if (!FileExists(targetPath))
{
return false;
}
return GetFileModTimeInt64(targetPath) >= newestSourceTime;
};
char path[MaxPath];
sprintf_s(path, "%s\\ImGui_Unity1.obj", intDir);
bool imguiNeed = unityChanged || !IsUpToDate(path, imguiTime);
sprintf_s(path, "%s\\Juliet.dll", binDir);
bool julietNeed = unityChanged || !IsUpToDate(path, julietCombined);
bool gameNeed = false;
if (targetJuliet || targetGame)
{
sprintf_s(path, "%s\\Game.dll", binDir);
gameNeed = julietNeed || unityChanged || !IsUpToDate(path, gameCombined);
}
bool julietAppNeed = false;
if (targetJuliet)
{
sprintf_s(path, "%s\\JulietApp.exe", binDir);
julietAppNeed = gameNeed || unityChanged || !IsUpToDate(path, appCombined);
}
bool romeoNeed = false;
if (targetRomeo)
{
sprintf_s(path, "%s\\Romeo.exe", binDir);
romeoNeed = julietNeed || unityChanged || !IsUpToDate(path, romeoCombined);
}
bool shaderNeed = false;
if (targetShader && DirectoryExists("Intermediate\\JulietShaderCompiler"))
{
sprintf_s(path, "%s\\JulietShaderCompiler.exe", binDir);
shaderNeed = julietNeed || unityChanged || !IsUpToDate(path, shaderCombined);
}
QueryPerformanceCounter(&perfEnd);
double durationMs =
static_cast<double>(perfEnd.QuadPart - perfStart.QuadPart) * 1000.0 / static_cast<double>(perfFreq.QuadPart);
printf("[PERF] Fast Native C++ EvaluateConfig: %.1f ms\n", durationMs);
// Write results
char statusBuf[512];
int statusLen = sprintf_s(statusBuf,
"FASTBUILD_UNITY_CHANGED=%d\n"
"JULIET_NEED_COMPILE=%d\n"
"IMGUI_NEED_COMPILE=%d\n"
"GAME_NEED_COMPILE=%d\n"
"JULIETAPP_NEED_COMPILE=%d\n"
"ROMEO_NEED_COMPILE=%d\n"
"SHADER_NEED_COMPILE=%d\n",
unityChanged ? 1 : 0, julietNeed ? 1 : 0, imguiNeed ? 1 : 0, gameNeed ? 1 : 0,
julietAppNeed ? 1 : 0, romeoNeed ? 1 : 0, shaderNeed ? 1 : 0);
WriteEntireFile("Intermediate\\config_status.tmp", statusBuf, static_cast<DWORD>(statusLen));
fflush(stdout);
return 0;
}
@@ -1026,24 +1042,16 @@ int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: build_check <command> [args...]\n");
printf("Usage: build_system <command> [args...]\n");
printf("Commands:\n");
printf(" start_build Record build start timestamp\n");
printf(" start_step <name> Record start timestamp of a build step\n");
printf(" end_step [<name>] Record duration of current step\n");
printf(" finish_build Print build summary (elapsed time, step timings, built binaries)\n");
printf(" evaluate <cfg> <juliet> <game> <romeo> <shader> Evaluate rebuild needs\n");
printf(" run_plan <plan_file> Run the build from a generated plan file\n");
printf(" check_alive Returns 0 immediately to test execution\n");
return 1;
}
const char* cmd = argv[1];
if (strcmp(cmd, "check_alive") == 0) return 0;
if (strcmp(cmd, "start_build") == 0) return CommandStartBuild();
if (strcmp(cmd, "start_step") == 0) return CommandStartStep(argc, argv);
if (strcmp(cmd, "end_step") == 0) return CommandEndStep(argc, argv);
if (strcmp(cmd, "finish_build") == 0) return CommandFinishBuild();
if (strcmp(cmd, "evaluate") == 0) return CommandEvaluate(argc, argv);
if (strcmp(cmd, "run_plan") == 0) return CommandRunPlan(argc, argv);
printf("[ERROR] Unknown command: %s\n", cmd);
return 1;