瀏覽代碼

fileapi: Add helper to create and reference a json reply file

Brad King 7 年之前
父節點
當前提交
7ee0abbde1
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 12 0
      Source/cmFileAPI.cxx
  2. 5 0
      Source/cmFileAPI.h

+ 12 - 0
Source/cmFileAPI.cxx

@@ -175,6 +175,18 @@ std::string cmFileAPI::WriteJsonFile(
   return fileName;
 }
 
+Json::Value cmFileAPI::MaybeJsonFile(Json::Value in, std::string const& prefix)
+{
+  Json::Value out;
+  if (in.isObject() || in.isArray()) {
+    out = Json::objectValue;
+    out["jsonFile"] = this->WriteJsonFile(in, prefix);
+  } else {
+    out = std::move(in);
+  }
+  return out;
+}
+
 std::string cmFileAPI::ComputeSuffixHash(std::string const& file)
 {
   cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_256);

+ 5 - 0
Source/cmFileAPI.h

@@ -31,6 +31,11 @@ public:
   /** Get the "cmake" instance with which this was constructed.  */
   cmake* GetCMakeInstance() const { return this->CMakeInstance; }
 
+  /** Convert a JSON object or array into an object with a single
+      "jsonFile" member specifying a file named with the given prefix
+      and holding the original object.  Other JSON types are unchanged.  */
+  Json::Value MaybeJsonFile(Json::Value in, std::string const& prefix);
+
 private:
   cmake* CMakeInstance;