Commit b3a8033d by Gert Wollny Committed by Commit Bot

JsonSerializer: use stubs when building without rapidjson

Bug: angleproject:5805 Change-Id: Ibf51b8b75c3feb6efdef969effb3f50e2474c6b3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2795772 Commit-Queue: Gert Wollny <gert.wollny@collabora.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 4ed9c4f1
...@@ -922,17 +922,24 @@ group("angle_compression") { ...@@ -922,17 +922,24 @@ group("angle_compression") {
} }
angle_source_set("libjson_serializer") { angle_source_set("libjson_serializer") {
sources = [ "src/libANGLE/serializer/JsonSerializer.h" ]
if (angle_has_build) {
defines = [ "ANGLE_HAVE_RAPIDJSON" ]
sources += [ "src/libANGLE/serializer/JsonSerializer.cpp" ]
}
public_deps = [ public_deps = [
":libANGLE_base", ":libANGLE_base",
"$angle_root/third_party/rapidjson", "$angle_root/third_party/rapidjson",
] ]
sources = [
"src/libANGLE/serializer/JsonSerializer.cpp",
"src/libANGLE/serializer/JsonSerializer.h",
]
} }
angle_source_set("libANGLE_with_capture") { angle_source_set("libANGLE_with_capture") {
if (angle_has_build) {
defines = [ "ANGLE_HAVE_RAPIDJSON" ]
}
public_deps = [ public_deps = [
":libANGLE_base", ":libANGLE_base",
":libjson_serializer", ":libjson_serializer",
......
...@@ -11,13 +11,12 @@ ...@@ -11,13 +11,12 @@
#include "common/debug.h" #include "common/debug.h"
#include <anglebase/sha1.h>
#include <rapidjson/document.h> #include <rapidjson/document.h>
#include <rapidjson/filewritestream.h> #include <rapidjson/filewritestream.h>
#include <rapidjson/ostreamwrapper.h> #include <rapidjson/ostreamwrapper.h>
#include <rapidjson/prettywriter.h> #include <rapidjson/prettywriter.h>
#include <anglebase/sha1.h>
namespace angle namespace angle
{ {
......
...@@ -11,12 +11,13 @@ ...@@ -11,12 +11,13 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include <rapidjson/document.h> #if defined(ANGLE_HAVE_RAPIDJSON)
# include <rapidjson/document.h>
#include <memory> # include <memory>
#include <sstream> # include <sstream>
#include <stack> # include <stack>
#include <type_traits> # include <type_traits>
namespace angle namespace angle
{ {
...@@ -50,6 +51,22 @@ class JsonSerializer : public angle::NonCopyable ...@@ -50,6 +51,22 @@ class JsonSerializer : public angle::NonCopyable
void startDocument(const std::string &name); void startDocument(const std::string &name);
void endDocument(); void endDocument();
void addCString(const std::string &name, const char *value);
void addString(const std::string &name, const std::string &value);
void addBlob(const std::string &name, const uint8_t *value, size_t length);
void startGroup(const std::string &name);
void endGroup();
const char *data() const;
std::vector<uint8_t> getData() const;
size_t length() const;
template <typename T> template <typename T>
void addScalar(const std::string &name, T value) void addScalar(const std::string &name, T value)
{ {
...@@ -71,32 +88,57 @@ class JsonSerializer : public angle::NonCopyable ...@@ -71,32 +88,57 @@ class JsonSerializer : public angle::NonCopyable
mGroupValueStack.top()->AddMember(tag, array, mAllocator); mGroupValueStack.top()->AddMember(tag, array, mAllocator);
} }
void addCString(const std::string &name, const char *value); private:
using ValuePointer = std::unique_ptr<rapidjson::Value>;
void addString(const std::string &name, const std::string &value); rapidjson::Document mDoc;
rapidjson::Document::AllocatorType &mAllocator;
std::stack<std::string> mGroupNameStack;
std::stack<ValuePointer> mGroupValueStack;
std::string mResult;
};
void addBlob(const std::string &name, const uint8_t *value, size_t length); } // namespace angle
#else
namespace angle
{
void startGroup(const std::string &name); class JsonSerializer : public angle::NonCopyable
{
void endGroup(); JsonSerializer() {}
~JsonSerializer() {}
const char *data() const; void startDocument(const std::string &name) { (void)name; }
void endDocument() {}
std::vector<uint8_t> getData() const; void addCString(const std::string &name, const char *value) {}
size_t length() const; void addString(const std::string &name, const std::string &value) {}
private: void addBlob(const std::string &name, const uint8_t *value, size_t length) {}
using ValuePointer = std::unique_ptr<rapidjson::Value>;
rapidjson::Document mDoc; void startGroup(const std::string &name) { (void)name; }
rapidjson::Document::AllocatorType &mAllocator;
std::stack<std::string> mGroupNameStack; void endGroup() {}
std::stack<ValuePointer> mGroupValueStack;
std::string mResult; const char *data() const { return ""; }
std::vector<uint8_t> getData() const { return std::vector<uint8_t>(); }
size_t length() const { return 0; }
template <typename T>
void addScalar(const std::string &name, T value)
{}
template <typename T>
void addVector(const std::string &name, const std::vector<T> &value)
{}
}; };
} // namespace angle } // namespace angle
#endif
#endif // JSONSERIALIZER_H #endif // JSONSERIALIZER_H
...@@ -6,9 +6,10 @@ ...@@ -6,9 +6,10 @@
// JsonSerializer_unittests-cpp: Unit tests for the JSON based serializer // JsonSerializer_unittests-cpp: Unit tests for the JSON based serializer
// //
#include "JsonSerializer.h" #if defined(ANGLE_HAVE_RAPIDJSON)
# include "JsonSerializer.h"
#include <gtest/gtest.h> # include <gtest/gtest.h>
class JsonSerializerTest : public ::testing::Test class JsonSerializerTest : public ::testing::Test
{ {
...@@ -183,3 +184,5 @@ void JsonSerializerTest::check(const std::string &expect) ...@@ -183,3 +184,5 @@ void JsonSerializerTest::check(const std::string &expect)
std::vector<uint8_t> expect_as_ubyte(expect.begin(), expect.end()); std::vector<uint8_t> expect_as_ubyte(expect.begin(), expect.end());
EXPECT_EQ(js.getData(), expect_as_ubyte); EXPECT_EQ(js.getData(), expect_as_ubyte);
} }
#endif
...@@ -135,9 +135,15 @@ angle_test("angle_unittests") { ...@@ -135,9 +135,15 @@ angle_test("angle_unittests") {
} }
} }
defines = []
if (angle_enable_hlsl) { if (angle_enable_hlsl) {
sources += angle_unittests_hlsl_sources sources += angle_unittests_hlsl_sources
defines = [ "ANGLE_ENABLE_HLSL" ] defines += [ "ANGLE_ENABLE_HLSL" ]
}
if (angle_has_build) {
defines += [ "ANGLE_HAS_RAPIDJSON" ]
} }
deps = [ deps = [
...@@ -151,6 +157,7 @@ angle_test("angle_unittests") { ...@@ -151,6 +157,7 @@ angle_test("angle_unittests") {
"$angle_root:translator", "$angle_root:translator",
"$angle_root/util:angle_util_static", "$angle_root/util:angle_util_static",
] ]
if (!is_android && !is_fuchsia) { if (!is_android && !is_fuchsia) {
# SystemUtils.RunApp, the only unittest using a helper binary, is not supported on these # SystemUtils.RunApp, the only unittest using a helper binary, is not supported on these
# platforms yet. # platforms yet.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment