From b3a8033d77e7f5a06cc5472f652701272173b86c Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 31 Mar 2021 09:34:00 +0200 Subject: [PATCH] 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 Reviewed-by: Cody Northrop Reviewed-by: Shahbaz Youssefi Reviewed-by: Jamie Madill --- BUILD.gn | 15 +++- src/libANGLE/serializer/JsonSerializer.cpp | 3 +- src/libANGLE/serializer/JsonSerializer.h | 84 ++++++++++++++----- .../serializer/JsonSerializer_unittest.cpp | 7 +- src/tests/BUILD.gn | 9 +- 5 files changed, 88 insertions(+), 30 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 095c5a72e..7e29600d1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -922,17 +922,24 @@ group("angle_compression") { } 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 = [ ":libANGLE_base", "$angle_root/third_party/rapidjson", ] - sources = [ - "src/libANGLE/serializer/JsonSerializer.cpp", - "src/libANGLE/serializer/JsonSerializer.h", - ] } angle_source_set("libANGLE_with_capture") { + if (angle_has_build) { + defines = [ "ANGLE_HAVE_RAPIDJSON" ] + } + public_deps = [ ":libANGLE_base", ":libjson_serializer", diff --git a/src/libANGLE/serializer/JsonSerializer.cpp b/src/libANGLE/serializer/JsonSerializer.cpp index 2924b0177..a16fc3849 100644 --- a/src/libANGLE/serializer/JsonSerializer.cpp +++ b/src/libANGLE/serializer/JsonSerializer.cpp @@ -11,13 +11,12 @@ #include "common/debug.h" +#include #include #include #include #include -#include - namespace angle { diff --git a/src/libANGLE/serializer/JsonSerializer.h b/src/libANGLE/serializer/JsonSerializer.h index 17116b157..acd074919 100644 --- a/src/libANGLE/serializer/JsonSerializer.h +++ b/src/libANGLE/serializer/JsonSerializer.h @@ -11,12 +11,13 @@ #include "common/angleutils.h" -#include +#if defined(ANGLE_HAVE_RAPIDJSON) +# include -#include -#include -#include -#include +# include +# include +# include +# include namespace angle { @@ -50,6 +51,22 @@ class JsonSerializer : public angle::NonCopyable void startDocument(const std::string &name); 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 getData() const; + + size_t length() const; + template void addScalar(const std::string &name, T value) { @@ -71,22 +88,6 @@ class JsonSerializer : public angle::NonCopyable mGroupValueStack.top()->AddMember(tag, array, mAllocator); } - 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 getData() const; - - size_t length() const; - private: using ValuePointer = std::unique_ptr; @@ -98,5 +99,46 @@ class JsonSerializer : public angle::NonCopyable }; } // namespace angle +#else +namespace angle +{ + +class JsonSerializer : public angle::NonCopyable +{ + + JsonSerializer() {} + ~JsonSerializer() {} + + void startDocument(const std::string &name) { (void)name; } + 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)name; } + + void endGroup() {} + + const char *data() const { return ""; } + + std::vector getData() const { return std::vector(); } + + size_t length() const { return 0; } + + template + void addScalar(const std::string &name, T value) + {} + + template + void addVector(const std::string &name, const std::vector &value) + {} +}; + +} // namespace angle + +#endif #endif // JSONSERIALIZER_H diff --git a/src/libANGLE/serializer/JsonSerializer_unittest.cpp b/src/libANGLE/serializer/JsonSerializer_unittest.cpp index 214d0ad49..cc491c46f 100644 --- a/src/libANGLE/serializer/JsonSerializer_unittest.cpp +++ b/src/libANGLE/serializer/JsonSerializer_unittest.cpp @@ -6,9 +6,10 @@ // JsonSerializer_unittests-cpp: Unit tests for the JSON based serializer // -#include "JsonSerializer.h" +#if defined(ANGLE_HAVE_RAPIDJSON) +# include "JsonSerializer.h" -#include +# include class JsonSerializerTest : public ::testing::Test { @@ -183,3 +184,5 @@ void JsonSerializerTest::check(const std::string &expect) std::vector expect_as_ubyte(expect.begin(), expect.end()); EXPECT_EQ(js.getData(), expect_as_ubyte); } + +#endif diff --git a/src/tests/BUILD.gn b/src/tests/BUILD.gn index d5957ea18..65866840c 100644 --- a/src/tests/BUILD.gn +++ b/src/tests/BUILD.gn @@ -135,9 +135,15 @@ angle_test("angle_unittests") { } } + defines = [] + if (angle_enable_hlsl) { sources += angle_unittests_hlsl_sources - defines = [ "ANGLE_ENABLE_HLSL" ] + defines += [ "ANGLE_ENABLE_HLSL" ] + } + + if (angle_has_build) { + defines += [ "ANGLE_HAS_RAPIDJSON" ] } deps = [ @@ -151,6 +157,7 @@ angle_test("angle_unittests") { "$angle_root:translator", "$angle_root/util:angle_util_static", ] + if (!is_android && !is_fuchsia) { # SystemUtils.RunApp, the only unittest using a helper binary, is not supported on these # platforms yet.