summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-11-01 09:45:54 -0400
committerBrad King <brad.king@kitware.com>2018-12-12 09:46:13 -0500
commit6615408193aa542833ef34c902a35831bd85d25a (patch)
treed49dfcfee3ff655dba5bec0adb7774bf005bb421 /Source
parent3f6ee75a66042370fe48833bcd5c712448ec59c0 (diff)
downloadcmake-6615408193aa542833ef34c902a35831bd85d25a.tar.gz
fileapi: add cmakeFiles v1
Issue: #18398
Diffstat (limited to 'Source')
-rw-r--r--Source/CMakeLists.txt2
-rw-r--r--Source/cmFileAPI.cxx63
-rw-r--r--Source/cmFileAPI.h5
-rw-r--r--Source/cmFileAPICMakeFiles.cxx113
-rw-r--r--Source/cmFileAPICMakeFiles.h15
5 files changed, 195 insertions, 3 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 82fad1cf57..035b7a0ef1 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -213,6 +213,8 @@ set(SRCS
cmFileAPICache.h
cmFileAPICodemodel.cxx
cmFileAPICodemodel.h
+ cmFileAPICMakeFiles.cxx
+ cmFileAPICMakeFiles.h
cmFileLock.cxx
cmFileLock.h
cmFileLockPool.cxx
diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx
index ec26268163..89bd25864a 100644
--- a/Source/cmFileAPI.cxx
+++ b/Source/cmFileAPI.cxx
@@ -4,6 +4,7 @@
#include "cmAlgorithms.h"
#include "cmCryptoHash.h"
+#include "cmFileAPICMakeFiles.h"
#include "cmFileAPICache.h"
#include "cmFileAPICodemodel.h"
#include "cmGlobalGenerator.h"
@@ -248,6 +249,17 @@ bool cmFileAPI::ReadQuery(std::string const& query,
objects.push_back(o);
return true;
}
+ if (kindName == ObjectKindName(ObjectKind::CMakeFiles)) {
+ Object o;
+ o.Kind = ObjectKind::CMakeFiles;
+ if (verStr == "v1") {
+ o.Version = 1;
+ } else {
+ return false;
+ }
+ objects.push_back(o);
+ return true;
+ }
if (kindName == ObjectKindName(ObjectKind::InternalTest)) {
Object o;
o.Kind = ObjectKind::InternalTest;
@@ -385,9 +397,10 @@ const char* cmFileAPI::ObjectKindName(ObjectKind kind)
{
// Keep in sync with ObjectKind enum.
static const char* objectKindNames[] = {
- "codemodel", //
- "cache", //
- "__test" //
+ "codemodel", //
+ "cache", //
+ "cmakeFiles", //
+ "__test" //
};
return objectKindNames[size_t(kind)];
}
@@ -411,6 +424,9 @@ Json::Value cmFileAPI::BuildObject(Object const& object)
case ObjectKind::Cache:
value = this->BuildCache(object);
break;
+ case ObjectKind::CMakeFiles:
+ value = this->BuildCMakeFiles(object);
+ break;
case ObjectKind::InternalTest:
value = this->BuildInternalTest(object);
break;
@@ -465,6 +481,8 @@ cmFileAPI::ClientRequest cmFileAPI::BuildClientRequest(
r.Kind = ObjectKind::CodeModel;
} else if (kindName == this->ObjectKindName(ObjectKind::Cache)) {
r.Kind = ObjectKind::Cache;
+ } else if (kindName == this->ObjectKindName(ObjectKind::CMakeFiles)) {
+ r.Kind = ObjectKind::CMakeFiles;
} else if (kindName == this->ObjectKindName(ObjectKind::InternalTest)) {
r.Kind = ObjectKind::InternalTest;
} else {
@@ -489,6 +507,9 @@ cmFileAPI::ClientRequest cmFileAPI::BuildClientRequest(
case ObjectKind::Cache:
this->BuildClientRequestCache(r, versions);
break;
+ case ObjectKind::CMakeFiles:
+ this->BuildClientRequestCMakeFiles(r, versions);
+ break;
case ObjectKind::InternalTest:
this->BuildClientRequestInternalTest(r, versions);
break;
@@ -706,6 +727,42 @@ Json::Value cmFileAPI::BuildCache(Object const& object)
return cache;
}
+// The "cmakeFiles" object kind.
+
+static unsigned int const CMakeFilesV1Minor = 0;
+
+void cmFileAPI::BuildClientRequestCMakeFiles(
+ ClientRequest& r, std::vector<RequestVersion> const& versions)
+{
+ // Select a known version from those requested.
+ for (RequestVersion const& v : versions) {
+ if ((v.Major == 1 && v.Minor <= CMakeFilesV1Minor)) {
+ r.Version = v.Major;
+ break;
+ }
+ }
+ if (!r.Version) {
+ r.Error = NoSupportedVersion(versions);
+ }
+}
+
+Json::Value cmFileAPI::BuildCMakeFiles(Object const& object)
+{
+ using namespace std::placeholders;
+ Json::Value cmakeFiles = cmFileAPICMakeFilesDump(*this, object.Version);
+ cmakeFiles["kind"] = this->ObjectKindName(object.Kind);
+
+ Json::Value& version = cmakeFiles["version"] = Json::objectValue;
+ if (object.Version == 1) {
+ version["major"] = 1;
+ version["minor"] = CMakeFilesV1Minor;
+ } else {
+ return cmakeFiles; // should be unreachable
+ }
+
+ return cmakeFiles;
+}
+
// The "__test" object kind is for internal testing of CMake.
static unsigned int const InternalTestV1Minor = 3;
diff --git a/Source/cmFileAPI.h b/Source/cmFileAPI.h
index 20aa011e1e..341b072f4b 100644
--- a/Source/cmFileAPI.h
+++ b/Source/cmFileAPI.h
@@ -53,6 +53,7 @@ private:
{
CodeModel,
Cache,
+ CMakeFiles,
InternalTest
};
@@ -191,6 +192,10 @@ private:
std::vector<RequestVersion> const& versions);
Json::Value BuildCache(Object const& object);
+ void BuildClientRequestCMakeFiles(
+ ClientRequest& r, std::vector<RequestVersion> const& versions);
+ Json::Value BuildCMakeFiles(Object const& object);
+
void BuildClientRequestInternalTest(
ClientRequest& r, std::vector<RequestVersion> const& versions);
Json::Value BuildInternalTest(Object const& object);
diff --git a/Source/cmFileAPICMakeFiles.cxx b/Source/cmFileAPICMakeFiles.cxx
new file mode 100644
index 0000000000..799a047c05
--- /dev/null
+++ b/Source/cmFileAPICMakeFiles.cxx
@@ -0,0 +1,113 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#include "cmFileAPICMakeFiles.h"
+
+#include "cmFileAPI.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmake.h"
+
+#include "cm_jsoncpp_value.h"
+
+#include <string>
+
+namespace {
+
+class CMakeFiles
+{
+ cmFileAPI& FileAPI;
+ unsigned long Version;
+ std::string CMakeModules;
+ std::string const& TopSource;
+ std::string const& TopBuild;
+ bool OutOfSource;
+
+ Json::Value DumpPaths();
+ Json::Value DumpInputs();
+ Json::Value DumpInput(std::string const& file);
+
+public:
+ CMakeFiles(cmFileAPI& fileAPI, unsigned long version);
+ Json::Value Dump();
+};
+
+CMakeFiles::CMakeFiles(cmFileAPI& fileAPI, unsigned long version)
+ : FileAPI(fileAPI)
+ , Version(version)
+ , CMakeModules(cmSystemTools::GetCMakeRoot() + "/Modules")
+ , TopSource(this->FileAPI.GetCMakeInstance()->GetHomeDirectory())
+ , TopBuild(this->FileAPI.GetCMakeInstance()->GetHomeOutputDirectory())
+ , OutOfSource(TopBuild != TopSource)
+{
+ static_cast<void>(this->Version);
+}
+
+Json::Value CMakeFiles::Dump()
+{
+ Json::Value cmakeFiles = Json::objectValue;
+ cmakeFiles["paths"] = this->DumpPaths();
+ cmakeFiles["inputs"] = DumpInputs();
+ return cmakeFiles;
+}
+
+Json::Value CMakeFiles::DumpPaths()
+{
+ Json::Value paths = Json::objectValue;
+ paths["source"] = this->TopSource;
+ paths["build"] = this->TopBuild;
+ return paths;
+}
+
+Json::Value CMakeFiles::DumpInputs()
+{
+ Json::Value inputs = Json::arrayValue;
+
+ cmGlobalGenerator* gg =
+ this->FileAPI.GetCMakeInstance()->GetGlobalGenerator();
+ for (cmLocalGenerator const* lg : gg->GetLocalGenerators()) {
+ cmMakefile const* mf = lg->GetMakefile();
+ for (std::string const& file : mf->GetListFiles()) {
+ inputs.append(this->DumpInput(file));
+ }
+ }
+
+ return inputs;
+}
+
+Json::Value CMakeFiles::DumpInput(std::string const& file)
+{
+ Json::Value input = Json::objectValue;
+
+ bool const isCMake = cmSystemTools::IsSubDirectory(file, this->CMakeModules);
+ if (isCMake) {
+ input["isCMake"] = true;
+ }
+
+ if (!cmSystemTools::IsSubDirectory(file, this->TopSource) &&
+ !cmSystemTools::IsSubDirectory(file, this->TopBuild)) {
+ input["isExternal"] = true;
+ }
+
+ if (this->OutOfSource &&
+ cmSystemTools::IsSubDirectory(file, this->TopBuild)) {
+ input["isGenerated"] = true;
+ }
+
+ std::string path = file;
+ if (!isCMake && cmSystemTools::IsSubDirectory(path, this->TopSource)) {
+ // Use a relative path within the source directory.
+ path = cmSystemTools::RelativePath(this->TopSource, path);
+ }
+ input["path"] = path;
+
+ return input;
+}
+}
+
+Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI, unsigned long version)
+{
+ CMakeFiles cmakeFiles(fileAPI, version);
+ return cmakeFiles.Dump();
+}
diff --git a/Source/cmFileAPICMakeFiles.h b/Source/cmFileAPICMakeFiles.h
new file mode 100644
index 0000000000..a851c32f46
--- /dev/null
+++ b/Source/cmFileAPICMakeFiles.h
@@ -0,0 +1,15 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#ifndef cmFileAPICMakeFiles_h
+#define cmFileAPICMakeFiles_h
+
+#include "cmConfigure.h" // IWYU pragma: keep
+
+#include "cm_jsoncpp_value.h"
+
+class cmFileAPI;
+
+extern Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI,
+ unsigned long version);
+
+#endif