Import foxglove schemas repo
This has to do a couple of things:
* Actually import the repo as an http_archive.
* Modify the cc_static_flatbuffer rule to allow it to handle a
flatbuffer target with multiple fbs files.
* Move foxglove-related third_party files into one directory.
Change-Id: I0123fc8037b107019f9c29b781418c9a03639eca
Signed-off-by: James Kuszmaul <jabukuszmaul@gmail.com>
diff --git a/WORKSPACE b/WORKSPACE
index 5e26090..3e1801c 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1303,9 +1303,9 @@
http_archive(
name = "com_github_foxglove_ws-protocol",
- build_file = "//third_party/foxglove_ws_protocol:foxglove_ws_protocol.BUILD",
+ build_file = "//third_party/foxglove/ws_protocol:foxglove_ws_protocol.BUILD",
patch_args = ["-p1"],
- patches = ["//third_party/foxglove_ws_protocol:foxglove_ws_protocol.patch"],
+ patches = ["//third_party/foxglove/ws_protocol:foxglove_ws_protocol.patch"],
sha256 = "3256f09a67419f6556778c443d332f1a4bf53ba0e7a464179bf838abffa366ab",
strip_prefix = "ws-protocol-releases-typescript-ws-protocol-examples-v0.0.6",
url = "https://github.com/foxglove/ws-protocol/archive/refs/tags/releases/typescript/ws-protocol-examples/v0.0.6.tar.gz",
@@ -1325,3 +1325,11 @@
strip_prefix = "asio-1.24.0",
url = "https://downloads.sourceforge.net/project/asio/asio/1.24.0%2520%2528Stable%2529/asio-1.24.0.tar.bz2",
)
+
+http_archive(
+ name = "com_github_foxglove_schemas",
+ build_file = "//third_party/foxglove/schemas:schemas.BUILD",
+ sha256 = "c0d08365eb8fba0af7773b5f0095fb53fb53f020bde46edaa308af5bb939fc15",
+ strip_prefix = "schemas-7a3e077b88142ac46bb4e2616f83dc029b45352e/schemas/flatbuffer",
+ url = "https://github.com/foxglove/schemas/archive/7a3e077b88142ac46bb4e2616f83dc029b45352e.tar.gz",
+)
diff --git a/aos/flatbuffers.bzl b/aos/flatbuffers.bzl
index 3db4ca0..c26906a 100644
--- a/aos/flatbuffers.bzl
+++ b/aos/flatbuffers.bzl
@@ -1,16 +1,18 @@
-def cc_static_flatbuffer(name, target, function, visibility = None):
+def cc_static_flatbuffer(name, target, function, bfbs_name = None, visibility = None):
"""Creates a cc_library which encodes a file as a Span.
args:
target, The file to encode.
function, The inline function, with full namespaces, to create.
+ bfbs_name, For flatbuffer targets that have multiple fbs files, this
+ specifies the basename of the bfbs file to generate a schema for.
"""
native.genrule(
name = name + "_gen",
tools = ["@org_frc971//aos:flatbuffers_static"],
srcs = [target],
outs = [name + ".h"],
- cmd = "$(location @org_frc971//aos:flatbuffers_static) $(SRCS) $(OUTS) '" + function + "'",
+ cmd = "$(location @org_frc971//aos:flatbuffers_static) '$(SRCS)' $(OUTS) '" + function + "' " + (bfbs_name if bfbs_name else "-"),
)
native.cc_library(
diff --git a/aos/flatbuffers_static.py b/aos/flatbuffers_static.py
index 199c5b9..3bd28fe 100644
--- a/aos/flatbuffers_static.py
+++ b/aos/flatbuffers_static.py
@@ -8,12 +8,26 @@
def main(argv):
- if len(argv) != 4:
+ if len(argv) != 5:
+ print(
+ f"Incorrect number of arguments {len(argv)} to flatbuffers_static."
+ )
+ print(argv)
return 1
input_path = sys.argv[1]
output_path = sys.argv[2]
function = sys.argv[3].split("::")
+ bfbs_name = sys.argv[4]
+ if bfbs_name != '-':
+ inputs = input_path.split(' ')
+ valid_paths = [path for path in inputs if path.endswith(bfbs_name)]
+ if len(valid_paths) != 1:
+ print(
+ f"Expected exactly one match for {bfbs_name}; got {valid_paths}."
+ )
+ return 1
+ input_path = valid_paths[0]
include_guard = output_path.replace('/', '_').replace('-', '_').replace(
'.', '_').upper() + '_'
diff --git a/third_party/foxglove_ws_protocol/BUILD b/third_party/foxglove/BUILD
similarity index 100%
copy from third_party/foxglove_ws_protocol/BUILD
copy to third_party/foxglove/BUILD
diff --git a/third_party/foxglove_ws_protocol/BUILD b/third_party/foxglove/schemas/BUILD
similarity index 100%
copy from third_party/foxglove_ws_protocol/BUILD
copy to third_party/foxglove/schemas/BUILD
diff --git a/third_party/foxglove/schemas/schemas.BUILD b/third_party/foxglove/schemas/schemas.BUILD
new file mode 100644
index 0000000..a1a5d29
--- /dev/null
+++ b/third_party/foxglove/schemas/schemas.BUILD
@@ -0,0 +1,21 @@
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "DEFAULT_FLATC_ARGS")
+
+FLATC_ARGS = [arg for arg in DEFAULT_FLATC_ARGS if arg != "--require-explicit-ids"]
+
+flatbuffer_cc_library(
+ name = "schemas",
+ srcs = glob(["*.fbs"]),
+ flatc_args = FLATC_ARGS,
+ gen_reflections = True,
+ visibility = ["//visibility:public"],
+)
+
+load("@org_frc971//aos:flatbuffers.bzl", "cc_static_flatbuffer")
+
+[cc_static_flatbuffer(
+ name = filename[:-4] + "_schema",
+ bfbs_name = filename[:-4] + ".bfbs",
+ function = "foxglove::" + filename[:-4] + "Schema",
+ target = ":schemas_reflection_out",
+ visibility = ["//visibility:public"],
+) for filename in glob(["*.fbs"])]
diff --git a/third_party/foxglove_ws_protocol/BUILD b/third_party/foxglove/ws_protocol/BUILD
similarity index 100%
rename from third_party/foxglove_ws_protocol/BUILD
rename to third_party/foxglove/ws_protocol/BUILD
diff --git a/third_party/foxglove_ws_protocol/foxglove_ws_protocol.BUILD b/third_party/foxglove/ws_protocol/foxglove_ws_protocol.BUILD
similarity index 100%
rename from third_party/foxglove_ws_protocol/foxglove_ws_protocol.BUILD
rename to third_party/foxglove/ws_protocol/foxglove_ws_protocol.BUILD
diff --git a/third_party/foxglove_ws_protocol/foxglove_ws_protocol.patch b/third_party/foxglove/ws_protocol/foxglove_ws_protocol.patch
similarity index 100%
rename from third_party/foxglove_ws_protocol/foxglove_ws_protocol.patch
rename to third_party/foxglove/ws_protocol/foxglove_ws_protocol.patch