Skip to content

Commit 0f4694b

Browse files
committed
ProjectBuildConfig: fix configuring a configured project (#108)
When we re-configure an existing dir, on windows it would fail. The reason is `mkdir ...` fails, as the directory already exist. On Unix we can use `mkdir -p` to overcome it. On Windows, the solution was to pipe the command trough another shell. Maybe in the future I will revisit it in power shell, in hope that this will work nicer. How did I debug this? I added "echo" before each command to find out which one failed. ``` {"echo 1111111111111111111111111", "cmd /c \"mkdir \"${build_directory}\\.cmake\\api\\v1\ \query\" >nul 2>nul || rem\"", "echo 2222222222222222222222222222", "cmd /c \"type nul > \"${build_directory}\\.cmake\\api\\v1\ \query\\codemodel-v2\" || " "rem\"", "echo 3333333333", "cmake -S \"${source_directory}\" -B \"${build_directory}\" " "-DCMAKE_BUILD_TYPE=Debug"}); ``` closes #108
1 parent de43da7 commit 0f4694b

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

src/plugins/ProjectManager/ProjectBuildConfig.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ auto getExecutablesFromCMakeFileAPI(const QString &buildDir) -> StringHash {
110110
return executables;
111111
}
112112

113-
auto static cargoListBinUnits(const QString &directoryPath, bool /*recursive*/ = true)
114-
-> StringHash {
113+
auto static cargoListBinUnits(const QString &directoryPath) -> StringHash {
115114
auto fileMap = StringHash{};
116115
auto process = QProcess{};
117116
process.setProgram("cargo");
@@ -269,11 +268,22 @@ auto ProjectBuildConfig::tryGuessFromCMake(const QString &directory)
269268
{"mkdir -p ${build_directory}/.cmake/api/v1/query/",
270269
"touch ${build_directory}/.cmake/api/v1/query/codemodel-v2",
271270
"cmake -S ${source_directory} -B ${build_directory} -DCMAKE_BUILD_TYPE=Debug"});
271+
272+
// Why not running the commands directly on this shell instead of spawning a new one?
273+
// Great question! This is because commands may fail, and I don't want them to kill the
274+
// build system, and I cannot use "| rem" easily.
275+
// Note also the clang format thingie, the lines are too long and then are separated
276+
// which makes reading the command very hard.
277+
278+
// clang-format off
272279
t.commands.insert(
273-
PLATFORM_WINDOWS,
274-
{"mkdir ${build_directory}\\.cmake\\api\\v1\\query\\ >nul 2>nul",
275-
"type nul > ${build_directory}\\.cmake\\api\\v1\\query\\codemodel-v2",
276-
"cmake -S ${source_directory} -B ${build_directory} -DCMAKE_BUILD_TYPE=Debug"});
280+
PLATFORM_WINDOWS, {
281+
"cmd /c \"mkdir \"${build_directory}\\.cmake\\api\\v1\\query\" >nul 2>nul || rem\"",
282+
"cmd /c \"type nul > \"${build_directory}\\.cmake\\api\\v1\\query\\codemodel-v2\" || rem\"",
283+
"cmake -S \"${source_directory}\" -B \"${build_directory}\" -DCMAKE_BUILD_TYPE=Debug"
284+
});
285+
// clang-format on
286+
277287
t.runDirectory = "${source_directory}";
278288
t.isBuild = true;
279289
value->tasksInfo.push_back(t);
@@ -283,16 +293,20 @@ auto ProjectBuildConfig::tryGuessFromCMake(const QString &directory)
283293
{
284294
auto t = TaskInfo();
285295
t.name = "CMake (configure/Release)";
286-
t.commands.insert(PLATFORM_LINUX,
287-
{"mkdir -p ${build_directory}/.cmake/api/v1/query/",
288-
"touch ${build_directory}/.cmake/api/v1/query/codemodel-v2",
289-
"cmake -S ${source_directory} -B ${build_directory} "
290-
"-DCMAKE_BUILD_TYPE=Release"});
291-
t.commands.insert(PLATFORM_WINDOWS,
292-
{"mkdir -p ${build_directory}\\.cmake\\api\\v1\\query\\",
293-
"type nul > ${build_directory}\\.cmake\\api\\v1\\query\\codemodel-v2",
294-
"cmake -S ${source_directory} -B ${build_directory} "
295-
"-DCMAKE_BUILD_TYPE=Release"});
296+
t.commands.insert(
297+
PLATFORM_LINUX,
298+
{"mkdir -p ${build_directory}/.cmake/api/v1/query/",
299+
"touch ${build_directory}/.cmake/api/v1/query/codemodel-v2",
300+
"cmake -S ${source_directory} -B ${build_directory} -DCMAKE_BUILD_TYPE=Release"});
301+
302+
// clang-format off
303+
t.commands.insert(
304+
PLATFORM_WINDOWS, {
305+
"cmd /c \"mkdir \"${build_directory}\\.cmake\\api\\v1\\query\" >nul 2>nul || rem\"",
306+
"cmd /c \"type nul > \"${build_directory}\\.cmake\\api\\v1\\query\\codemodel-v2\" || rem\"",
307+
"cmake -S \"${source_directory}\" -B \"${build_directory}\" -DCMAKE_BUILD_TYPE=Release"
308+
});
309+
// clang-format on
296310
t.runDirectory = "${source_directory}";
297311
t.isBuild = true;
298312
value->tasksInfo.push_back(t);

0 commit comments

Comments
 (0)