Skip to content

Commit

Permalink
Fix #29 - remove CMakeCache.txt before generating if build dir has be…
Browse files Browse the repository at this point in the history
…en moved
  • Loading branch information
will-v-pi committed Aug 9, 2024
1 parent 995e0ad commit 64e566d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/utils/cmakeUtil.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { exec } from "child_process";
import { workspace, type Uri, window, ProgressLocation } from "vscode";
import { showRequirementsNotMetErrorMessage } from "./requirementsUtil.mjs";
import { dirname, join } from "path";
import { dirname, join, resolve } from "path";
import Settings from "../settings.mjs";
import { HOME_VAR, SettingsKey } from "../settings.mjs";
import { readFileSync } from "fs";
import { existsSync, readFileSync, rmSync } from "fs";
import Logger from "../logger.mjs";
import { readFile, writeFile } from "fs/promises";
import { rimraf, windows as rimrafWindows } from "rimraf";
Expand Down Expand Up @@ -110,6 +110,35 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
return false;
}

if (existsSync(join(folder.fsPath, "build", "CMakeCache.txt"))) {
// check if the build directory has been moved

const buildDir = join(folder.fsPath, "build");

const cacheBuildDir = cmakeGetPicoVar(
join(buildDir, "CMakeCache.txt"),
"CMAKE_CACHEFILE_DIR"
);

if (cacheBuildDir !== null) {
let p1 = resolve(buildDir);
let p2 = resolve(cacheBuildDir);
if (process.platform === "win32") {
p1 = p1.toLowerCase();
p2 = p2.toLowerCase();
}

if (p1 !== p2) {
console.warn(
`Build directory has been moved from ${p1} to ${p2}` +
` - Deleting CMakeCache.txt and regenerating.`
);

rmSync(join(buildDir, "CMakeCache.txt"));
}
}
}

try {
// check if CMakeLists.txt exists in the root folder
await workspace.fs.stat(
Expand Down

0 comments on commit 64e566d

Please sign in to comment.