Skip to content

Commit c628a4e

Browse files
committed
Update communication module and fix json schema validation
1 parent 76b75ca commit c628a4e

File tree

12 files changed

+185
-52
lines changed

12 files changed

+185
-52
lines changed

MODULE.bazel

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,42 @@ bazel_dep(name = "score_tooling", version = "1.0.4", dev_dependency = True)
162162
bazel_dep(name = "aspect_rules_lint", version = "2.3.0", dev_dependency = True)
163163
bazel_dep(name = "buildifier_prebuilt", version = "8.5.1", dev_dependency = True)
164164

165+
# ============================================================================
166+
# JSON Schema Validation
167+
# ============================================================================
168+
bazel_dep(name = "nlohmann_json", version = "3.11.3", dev_dependency = True)
169+
bazel_dep(name = "download_utils", version = "1.2.2", dev_dependency = True)
170+
171+
download_archive = use_repo_rule("@download_utils//download/archive:defs.bzl", "download_archive")
172+
173+
download_archive(
174+
name = "json_schema_validator",
175+
build = "//third_party/json_schema_validator:json_schema_validator.BUILD",
176+
strip_prefix = "json-schema-validator-2.1.0",
177+
urls = ["https://github.com/pboettch/json-schema-validator/archive/refs/tags/2.1.0.tar.gz"],
178+
)
179+
180+
download_archive(
181+
name = "jsonschema",
182+
build = "//third_party/jsonschema:jsonschema.BUILD",
183+
strip_prefix = "jsonschema-4.23.0",
184+
urls = ["https://github.com/python-jsonschema/jsonschema/archive/refs/tags/v4.23.0.tar.gz"],
185+
)
186+
165187
# ============================================================================
166188
# Documentation
167189
# ============================================================================
168-
bazel_dep(name = "score_docs_as_code", version = "2.3.0", dev_dependency = True)
190+
bazel_dep(name = "score_docs_as_code", version = "3.0.0", dev_dependency = True)
169191

170192
# ============================================================================
171193
# Communication Framework
172194
# ============================================================================
173-
bazel_dep(name = "score_communication", version = "0.1.2")
174-
175-
# On aarch64 (ARM), C's char is unsigned (u8)
176-
# Fixed upstream on main by commit b9efce9702d108fd63be806738db50c14d354302
177-
# Opened problem report at: https://github.com/eclipse-score/communication/issues/172
178-
single_version_override(
195+
bazel_dep(name = "score_communication", version = "0.1.4")
196+
# TODO: Remove override as soon as new release containing the GenericSkeleton is available.
197+
git_override(
179198
module_name = "score_communication",
180-
patch_strip = 1,
181-
patches = ["//:third_party/score_communication-cchar.patch"],
199+
commit = "fea1b1058ea78ccd32fd04bf2e0d4728b34e18fa",
200+
remote = "https://github.com/eclipse-score/communication.git",
182201
)
183202

184203
# ============================================================================
@@ -187,29 +206,25 @@ single_version_override(
187206
# Patch note: baselibs-multiarch.patch adds multi-arch support for .deb downloads.
188207
# score_baselibs hardcodes amd64 URLs; patch replaces them with architecture-aware
189208
# selection (x86_64 or aarch64) based on TARGET_ARCH environment variable.
190-
bazel_dep(name = "score_baselibs", version = "0.2.2")
191-
single_version_override(
209+
bazel_dep(name = "score_baselibs", version = "0.2.4")
210+
git_override(
192211
module_name = "score_baselibs",
193-
patch_strip = 1,
194-
patches = ["//:third_party/baselibs-multiarch.patch"],
212+
commit = "052c2f271be4239f97182b164f4903b8c88d6c72",
213+
remote = "https://github.com/eclipse-score/baselibs.git",
214+
)
215+
216+
bazel_dep(name = "score_logging", version = "0.1.0")
217+
git_override(
218+
module_name = "score_logging",
219+
commit = "38e8762881d512c89ae5c2e5e5238fd791d327df",
220+
remote = "https://github.com/eclipse-score/logging.git",
195221
)
196222

197223
# ============================================================================
198224
# Code Generation
199225
# ============================================================================
200226
bazel_dep(name = "flatbuffers", version = "25.12.19")
201227

202-
# ============================================================================
203-
# Requirements Traceability
204-
# ============================================================================
205-
# TRLC (Traceability Language Compiler) for requirements management.
206-
# Overrides the transitive dependency to pin a verified release.
207-
git_override(
208-
module_name = "trlc",
209-
commit = "650b51a47264a4f232b3341f473527710fc32669", # trlc-2.0.2 release
210-
remote = "https://github.com/bmw-software-engineering/trlc.git",
211-
)
212-
213228
# ============================================================================
214229
# Examples: Car Window Simulator
215230
# ============================================================================
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Creates "validate_json_schema_test" test rule which validates the input "json" file against its "schema"
3+
"""
4+
5+
def _impl(ctx):
6+
script = """
7+
readonly expected_failure={expected_failure}
8+
'{validator}' '{schema}' < '{json}'
9+
readonly ret=$?
10+
if test "$expected_failure" = true && test "$ret" -ne 0; then
11+
exit 0
12+
elif test "$expected_failure" = false && test "$ret" -eq 0; then
13+
exit 0
14+
fi
15+
echo "Test Failed: Json validator performed json validation of '{json}' against '{schema}' schema with exit code $ret, meanwhile rule attribute 'expected_failure' is equal to '{expected_failure}'.
16+
This means in case expected_failure=false then expected exit code should be zero (valid json). Otherwise, if expected_failure=true then exit code is non-zero (invalid json).
17+
Note: by default expected_failure is false."
18+
exit 1
19+
""".format(
20+
validator = ctx.attr._validator.files_to_run.executable.short_path,
21+
schema = ctx.file.schema.short_path,
22+
json = ctx.file.json.short_path,
23+
expected_failure = "true" if ctx.attr.expected_failure else "false",
24+
)
25+
26+
ctx.actions.write(
27+
output = ctx.outputs.executable,
28+
content = script,
29+
)
30+
31+
# To ensure the files needed by the script are available, put them in the runfiles
32+
runfiles = ctx.runfiles(files = [ctx.file._validator, ctx.file.json, ctx.file.schema])
33+
return [DefaultInfo(runfiles = runfiles)]
34+
35+
validate_json_schema_test = rule(
36+
implementation = _impl,
37+
attrs = {
38+
"expected_failure": attr.bool(default = False),
39+
"json": attr.label(
40+
allow_single_file = True,
41+
mandatory = True,
42+
),
43+
"schema": attr.label(
44+
allow_single_file = True,
45+
mandatory = True,
46+
),
47+
"_validator": attr.label(
48+
default = Label("@json_schema_validator"),
49+
allow_single_file = True,
50+
executable = True,
51+
cfg = "exec",
52+
),
53+
},
54+
test = True,
55+
)

bazel/tools/someip_config.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
"""Macros to generate and validate a SOME/IP gateway configuration"""
1515

16-
load("@score_communication//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
16+
load("//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
1717

1818
def _get_expected_binary_name(json):
1919
"""Extracts the expected binary filename from a JSON label.

src/gatewayd/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
2020
load("@flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
2121
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
2222
load("@rules_cc//cc:cc_library.bzl", "cc_library")
23-
load("@score_communication//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
23+
load("//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
2424
load("@score_someip_gateway//bazel/tools:someip_config.bzl", "generate_someip_config_bin", "validate_someip_config_test")
2525

2626
exports_files(

src/gatewayd/remote_service_instance.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ RemoteServiceInstance::RemoteServiceInstance(
5656
// TODO: Check based on event/method id within the SOME/IP header which event was
5757
// received, to forward via the correct IPC event. For now, we assume it's always
5858
// the echo_response_tiny event.
59-
auto& event = const_cast<score::mw::com::impl::GenericSkeletonEvent&>(
59+
auto& event = const_cast<score::mw::com::GenericSkeletonEvent&>(
6060
ipc_skeleton_.GetEvents().find("echo_response_tiny")->second);
6161
auto maybe_sample = event.Allocate();
6262
if (!maybe_sample.has_value()) {
@@ -103,7 +103,7 @@ Result<mw::com::FindServiceHandle> RemoteServiceInstance::CreateAsyncRemoteServi
103103
service_instance_config->instance_specifier()->str())
104104
.value();
105105

106-
std::vector<score::mw::com::impl::EventInfo> events{};
106+
std::vector<score::mw::com::EventInfo> events{};
107107
events.reserve(service_instance_config->events()->size());
108108

109109
for (const auto& event : *service_instance_config->events()) {
@@ -113,12 +113,12 @@ Result<mw::com::FindServiceHandle> RemoteServiceInstance::CreateAsyncRemoteServi
113113
}
114114

115115
// TODO: Get the event type info from somewhere. Configuration?
116-
score::mw::com::impl::DataTypeMetaInfo type_info{sizeof(echo_service::EchoResponseTiny),
117-
alignof(echo_service::EchoResponseTiny)};
116+
score::mw::com::DataTypeMetaInfo type_info{sizeof(echo_service::EchoResponseTiny),
117+
alignof(echo_service::EchoResponseTiny)};
118118
events.push_back({event->event_name()->string_view(), type_info});
119119
}
120120

121-
score::mw::com::impl::GenericSkeletonServiceElementInfo create_params;
121+
score::mw::com::GenericSkeletonServiceElementInfo create_params;
122122
create_params.events = events;
123123

124124
auto create_ipc_result =

src/someipd/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This daemon contains the SOME/IP communication stack and is QM
1616
"""
1717

1818
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
19-
load("@score_communication//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
19+
load("//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
2020

2121
exports_files(["etc/mw_com_config.json"])
2222

tests/benchmarks/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
1515
load("@rules_cc//cc:cc_library.bzl", "cc_library")
16-
load("@score_communication//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
16+
load("//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
1717

1818
cc_library(
1919
name = "echo_service",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
package(
14+
default_visibility = ["//visibility:public"],
15+
)
16+
17+
cc_library(
18+
name = "json_schema_validator_lib",
19+
srcs = glob(["src/*"]),
20+
hdrs = ["src/nlohmann/json-schema.hpp"],
21+
features = [
22+
"third_party_warnings",
23+
"-treat_warnings_as_errors",
24+
],
25+
includes = ["src"],
26+
deps = ["@nlohmann_json//:json"],
27+
)
28+
29+
cc_binary(
30+
name = "json_schema_validator",
31+
srcs = ["app/json-schema-validate.cpp"],
32+
deps = [":json_schema_validator_lib"],
33+
)

third_party/jsonschema/BUILD

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
alias(
14+
name = "jsonschema",
15+
actual = "@jsonschema//:lib",
16+
visibility = ["//visibility:public"],
17+
)

0 commit comments

Comments
 (0)