Skip to content

Commit 55280e1

Browse files
authored
Merge pull request #13 from qorix-group/piotrkorkus_remove_baselibs_dep
Remove baselibs dep from C++
2 parents d9cb702 + 9c2af53 commit 55280e1

5 files changed

Lines changed: 20 additions & 28 deletions

File tree

.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ build --java_language_version=17
22
build --tool_java_language_version=17
33
build --java_runtime_version=remotejdk_17
44
build --tool_java_runtime_version=remotejdk_17
5-
build --@score_baselibs//score/json:base_library=nlohmann
65

76
test --test_output=errors
87

MODULE.bazel

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module(
2424
bazel_dep(name = "score_starpls_lsp", version = "0.1.0", dev_dependency = True)
2525

2626
# Python rules.
27-
bazel_dep(name = "rules_python", version = "1.0.0", dev_dependency = True)
27+
bazel_dep(name = "rules_python", version = "1.7.0", dev_dependency = True)
2828

2929
PYTHON_VERSION = "3.12"
3030

@@ -36,13 +36,13 @@ python.toolchain(
3636
use_repo(python)
3737

3838
# C++ GoogleTest dependencies.
39-
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)
39+
bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)
4040

4141
# Rust rules.
42-
bazel_dep(name = "rules_rust", version = "0.56.0")
42+
bazel_dep(name = "rules_rust", version = "0.67.0")
4343

4444
# C/C++ rules.
45-
bazel_dep(name = "rules_cc", version = "0.1.1", dev_dependency = True)
45+
bazel_dep(name = "rules_cc", version = "0.2.14")
4646

4747
# Rust module dependencies.
4848
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
@@ -51,8 +51,8 @@ rust.toolchain(
5151
versions = ["1.85.0"],
5252
)
5353

54-
# C++ base libs.
55-
bazel_dep(name = "score_baselibs", version = "0.1.2", dev_dependency = True)
54+
# Json for C++.
55+
bazel_dep(name = "nlohmann_json", version = "3.12.0")
5656

5757
# Score Rust crates.
58-
bazel_dep(name = "score_crates", version = "0.0.4")
58+
bazel_dep(name = "score_crates", version = "0.0.6")

test_scenarios_cpp/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cc_library(
3535
],
3636
includes = ["include/"],
3737
visibility = ["//visibility:public"],
38-
deps = ["@score_baselibs//score/json:json_parser"],
38+
deps = ["@nlohmann_json//:json"],
3939
)
4040

4141
cc_test(

test_scenarios_cpp/include/tracing.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <string>
2121

2222
#include "monotonic_clock.hpp"
23-
#include "score/json/json_writer.h"
23+
#include <nlohmann/json.hpp>
2424

2525
#define _TRACING(target, level, fields...) \
2626
do { \
@@ -58,8 +58,7 @@ class Subscriber {
5858
template <typename... T>
5959
void event(const std::optional<std::string>& target, const Level& level,
6060
std::pair<std::string, T>... fields) const {
61-
using namespace score::json;
62-
Object fields_object{object_create(fields...)};
61+
nlohmann::json fields_object = object_create(fields...);
6362
handle_event(target, level, std::move(fields_object));
6463
}
6564

@@ -69,15 +68,15 @@ class Subscriber {
6968
MonotonicClock timer_;
7069

7170
void handle_event(const std::optional<std::string>& target, const Level& level,
72-
score::json::Object&& fields) const;
71+
nlohmann::json&& fields) const;
7372

74-
score::json::Object object_create() const { return score::json::Object{}; }
73+
nlohmann::json object_create() const { return nlohmann::json::object(); }
7574

7675
template <typename HeadT, typename... TailT>
77-
score::json::Object object_create(std::pair<std::string, HeadT> field,
78-
std::pair<std::string, TailT>... fields) const {
79-
auto object{object_create(fields...)};
80-
object.insert(field);
76+
nlohmann::json object_create(std::pair<std::string, HeadT> field,
77+
std::pair<std::string, TailT>... fields) const {
78+
auto object = object_create(fields...);
79+
object[field.first] = field.second;
8180
return object;
8281
}
8382
};

test_scenarios_cpp/src/tracing.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ Subscriber::Subscriber(Level max_level, bool thread_ids)
6565
: max_level_{max_level}, thread_ids_{thread_ids} {}
6666

6767
void Subscriber::handle_event(const std::optional<std::string>& target, const Level& level,
68-
score::json::Object&& fields) const {
69-
using namespace score::json;
70-
68+
nlohmann::json&& fields) const {
7169
// Drop handling if below max level.
7270
if (level < max_level_) {
7371
return;
7472
}
7573

76-
Object event;
74+
nlohmann::json event;
7775

7876
// Add timestamp.
7977
event.emplace("timestamp", timer_.format_time());
@@ -98,17 +96,13 @@ void Subscriber::handle_event(const std::optional<std::string>& target, const Le
9896
}
9997

10098
// Make JSON string.
101-
JsonWriter writer;
102-
auto buffer_result{writer.ToBuffer(event)};
103-
if (!buffer_result) {
104-
throw std::runtime_error{"Failed to stringify JSON"};
105-
}
99+
std::string json_str = event.dump();
106100

107101
// Minify JSON and add "\n".
108102
// "\n" + 'std::flush' is used instead of 'std::endl'.
109103
// This is to avoid message mangling in multithreaded scenarios.
110104
std::stringstream ss;
111-
ss << minify_json(*buffer_result) << "\n";
105+
ss << minify_json(json_str) << "\n";
112106

113107
// Print output.
114108
std::cout << ss.str() << std::flush;

0 commit comments

Comments
 (0)