feat(ide): emit the full CMake File API reply set
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 7s
VoidBuildSystem CI / fuzz-clang (push) Failing after 7s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 48s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 7s
VoidBuildSystem CI / fuzz-clang (push) Failing after 7s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 48s
This commit is contained in:
1 parent
1caeab70fa
commit
3f5b21a570
1 file changed
+85
-2
+85
-2
@@ -1636,12 +1636,95 @@ emit_cmake_file_api(const Graph::BuildGraph &graph, const std::filesystem::path
|
||||
return written;
|
||||
}
|
||||
|
||||
// cmakeFiles-v1: configure inputs/outputs, so IDEs can track project files.
|
||||
std::vector<std::string> configure_inputs{json_quote(project_root.string())};
|
||||
for (const auto &candidate : {"build.cpp", "build.profiles.cpp", "workspace.cpp"}) {
|
||||
const auto path = project_root / candidate;
|
||||
std::error_code file_ec;
|
||||
if (std::filesystem::is_regular_file(path, file_ec)) {
|
||||
configure_inputs.push_back(json_quote(path.string()));
|
||||
}
|
||||
}
|
||||
const std::string cmake_files_json =
|
||||
"{\"kind\":\"cmakeFiles\",\"version\":" + version_block +
|
||||
",\"paths\":{\"source\":" + json_quote(project_root.string()) +
|
||||
",\"build\":" + json_quote(build_root.string()) + "},\"inputs\":" +
|
||||
json_array(configure_inputs,
|
||||
[](const std::string &entry) { return "{\"path\":" + entry + '}'; }) +
|
||||
",\"outputs\":[{\"path\":" + json_quote((build_root / "compile_commands.json").string()) +
|
||||
"}]}";
|
||||
const std::string cmake_files_file =
|
||||
"cmakeFiles-v1-" + Util::sha256_hex(cmake_files_json).substr(0, 16) + ".json";
|
||||
if (auto written = write_reply(cmake_files_file, cmake_files_json); !written) {
|
||||
return written;
|
||||
}
|
||||
|
||||
// toolchains-v1: compiler identity for C and CXX.
|
||||
std::vector<std::string> toolchain_files;
|
||||
for (const auto &[language, compiler, extensions] :
|
||||
std::vector<std::tuple<std::string, std::filesystem::path, std::vector<std::string>>>{
|
||||
{"CXX",
|
||||
graph.toolchain.cxx_compiler,
|
||||
{".cpp", ".cc", ".cxx", ".c++", ".mpp", ".cppm", ".ixx"}},
|
||||
{"C", graph.toolchain.c_compiler, {".c"}}}) {
|
||||
const std::string toolchain_json =
|
||||
"{\"kind\":\"toolchain\",\"version\":" + version_block +
|
||||
",\"language\":" + json_quote(language) +
|
||||
",\"compiler\":{\"id\":" + json_quote(compiler_name(graph.toolchain.family)) +
|
||||
",\"path\":" + json_quote(compiler.string()) +
|
||||
"},\"sourceFileExtensions\":" + json_array(extensions, json_quote) +
|
||||
",\"implicit\":{\"includeDirectories\":[],\"linkDirectories\":[],"
|
||||
"\"linkFrameworkDirectories\":[],\"linkLibraries\":[]}}";
|
||||
const std::string toolchain_file =
|
||||
"toolchains-v1-" + Util::sha256_hex(toolchain_json).substr(0, 16) + ".json";
|
||||
if (auto written = write_reply(toolchain_file, toolchain_json); !written) {
|
||||
return written;
|
||||
}
|
||||
toolchain_files.push_back(toolchain_file);
|
||||
}
|
||||
|
||||
// cache-v2: the effective configuration values an IDE shows in its settings.
|
||||
const std::vector<std::pair<std::string, std::string>> cache_entries{
|
||||
{"CMAKE_BUILD_TYPE", graph.profile.name},
|
||||
{"CMAKE_C_COMPILER", graph.toolchain.c_compiler.string()},
|
||||
{"CMAKE_CXX_COMPILER", graph.toolchain.cxx_compiler.string()},
|
||||
{"CMAKE_GENERATOR", "VBS"},
|
||||
{"VBS_PROFILE", graph.profile.name},
|
||||
{"VBS_PROJECT_ROOT", project_root.string()},
|
||||
};
|
||||
std::string cache_json = "{\"kind\":\"cache\",\"version\":" + version_block + ",\"entries\":[";
|
||||
for (std::size_t i = 0; i < cache_entries.size(); ++i) {
|
||||
if (i > 0) {
|
||||
cache_json += ',';
|
||||
}
|
||||
const auto &[name, value] = cache_entries[i];
|
||||
cache_json +=
|
||||
"{\"name\":" + json_quote(name) +
|
||||
",\"properties\":[{\"name\":\"HELPSTRING\","
|
||||
"\"value\":\"\"},{\"name\":\"TYPE\",\"value\":\"STRING\"},{\"name\":\"VALUE\","
|
||||
"\"value\":" +
|
||||
json_quote(value) + "}],\"type\":\"STRING\",\"value\":" + json_quote(value) + '}';
|
||||
}
|
||||
cache_json += "]}";
|
||||
const std::string cache_file =
|
||||
"cache-v2-" + Util::sha256_hex(cache_json).substr(0, 16) + ".json";
|
||||
if (auto written = write_reply(cache_file, cache_json); !written) {
|
||||
return written;
|
||||
}
|
||||
|
||||
const std::string index_json =
|
||||
"{\"cmake\":{\"generator\":{\"multiConfig\":false},\"version\":{\"major\":0,"
|
||||
"\"minor\":1,\"patch\":0,\"string\":\"" +
|
||||
std::string{Bootstrap::version} +
|
||||
"\"}},\"reply\":{\"codemodel-v2\":{\"jsonFile\":" + json_quote(codemodel_file) +
|
||||
",\"kind\":\"codemodel\",\"version\":" + version_block + "}}}";
|
||||
"\"}},\"reply\":{\"cache-v2\":{\"jsonFile\":" + json_quote(cache_file) +
|
||||
",\"kind\":\"cache\",\"version\":" + version_block +
|
||||
"},\"cmakeFiles-v1\":{\"jsonFile\":" + json_quote(cmake_files_file) +
|
||||
",\"kind\":\"cmakeFiles\",\"version\":" + version_block +
|
||||
"},\"codemodel-v2\":{\"jsonFile\":" + json_quote(codemodel_file) +
|
||||
",\"kind\":\"codemodel\",\"version\":" + version_block +
|
||||
"},\"toolchains-v1\":{\"jsonFile\":" +
|
||||
(toolchain_files.empty() ? std::string{"\"\""} : json_quote(toolchain_files.front())) +
|
||||
",\"kind\":\"toolchain\",\"version\":" + version_block + "}}}";
|
||||
const std::string index_file = "index-" + Util::sha256_hex(index_json).substr(0, 16) + ".json";
|
||||
return write_reply(index_file, index_json);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user