From a7f2893bfb5149944be598bd93b642ead27c1886 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 23 Dec 2024 12:14:46 +0100 Subject: WIP --- src/deps.cc | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/deps.cc') diff --git a/src/deps.cc b/src/deps.cc index 9400b35..599be8c 100644 --- a/src/deps.cc +++ b/src/deps.cc @@ -5,6 +5,8 @@ #include "util.h" +#include + #include namespace { @@ -94,6 +96,74 @@ std::vector readDepsMake(const std::string& dep_file) return output; } + +// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1689r5.html +// https://devblogs.microsoft.com/cppblog/introducing-source-dependency-reporting-with-msvc-in-visual-studio-2019-version-16-7/ +/* Format examples: +{ + "Version": "1.1", + "Data": { + "Source": "z:\\home\\deva\\docs\\c\\ctor\\src\\libctor.cc", + "ProvidedModule": "", + "Includes": [ + "c:\\program files (x86)\\microsoft visual studio\\2019\\buildtools\\vc\\tools\\msvc\\14.29.30133\\include\\vector", + "c:\\program files (x86)\\microsoft visual studio\\2019\\buildtools\\vc\\tools\\msvc\\14.29.30133\\include\\yvals_core.h", + "c:\\program files (x86)\\microsoft visual studio\\2019\\buildtools\\vc\\tools\\msvc\\14.29.30133\\include\\vcruntime.h", +. +. +. + "z:\\home\\deva\\docs\\c\\ctor\\src\\unittest.h" + ], + "ImportedModules": [], + "ImportedHeaderUnits": [] + } +} +*/ +/* +{ + "Version": "1.2", + "Data": { + "Source": "c:\\jenkins\\workspace\\ctor-linux64\\src\\build.cc", + "ProvidedModule": "", + "Includes": [ + "c:\\jenkins\\workspace\\ctor-linux64\\src\\build.h", + "c:\\program files (x86)\\microsoft visual studio\\2022\\buildtools\\vc\\tools\\msvc\\14.42.34433\\include\\string", + "c:\\program files (x86)\\microsoft visual studio\\2022\\buildtools\\vc\\tools\\msvc\\14.42.34433\\include\\yvals_core.h", +. +. +. + "c:\\program files (x86)\\microsoft visual studio\\2022\\buildtools\\vc\\tools\\msvc\\14.42.34433\\include\\iostream" + ], + "ImportedModules": [], + "ImportedHeaderUnits": [] + } +} +*/ + +std::vector readDepsJson(const std::string& dep_file) +{ + std::ifstream stream(dep_file); + auto json = nlohmann::json::parse(stream); + for(const auto& [key, value] : json.items()) + { + if(key == "Data" && value.is_object()) + { + for(const auto& [inner_key, inner_value] : value.items()) + { + if(inner_key == "Includes" && inner_value.is_array()) + { + std::vector deps; + for(const auto& dep : inner_value) + { + deps.emplace_back(dep); + } + return deps; + } + } + } + } + return {}; +} } std::vector readDeps(const std::string& dep_file, @@ -110,6 +180,10 @@ std::vector readDeps(const std::string& dep_file, case ctor::toolchain::none: return {}; + // json based: + case ctor::toolchain::msvc: + return readDepsJson(dep_file); + // makefile .d file based: case ctor::toolchain::gcc: case ctor::toolchain::clang: -- cgit v1.2.3