Fix includes of reflection.fbs with static flatbuffer API
Because the base reflection_generated.h needs to be available to flatc
at compile-time, it gets checked into the repository. On top of this,
flatc special-cases `reflection/reflection.fbs` for inclusion, so we
need to treat it special in our #include paths as well.
This makes it so that we codegen the reflection_static.h from
reflection.fbs, and introduces a requirements that any flatbuffer files
which use the reflection.fbs must depend on
@aos//aos/flatbuffers/reflection:reflection_fbs
Change-Id: I22a11e86052b7bd90efadb209a7529ff58b6e0ca
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/flatbuffers/static_flatbuffers.cc b/aos/flatbuffers/static_flatbuffers.cc
index 760d92c..c1b617f 100644
--- a/aos/flatbuffers/static_flatbuffers.cc
+++ b/aos/flatbuffers/static_flatbuffers.cc
@@ -120,6 +120,22 @@
const std::string IncludePathForFbs(
std::string_view fbs_file, std::string_view include_suffix = "static") {
+ // Special case for the reflection_generated.h, which is checked into the
+ // repo.
+ // Note that we *do* autogenerated the reflection_static.h but that because
+ // it uses a special import path, we end up overriding the include anyways
+ // (note that we could muck around with the paths on the bazel side to instead
+ // get a cc_library with the correct include paths specified, although it is
+ // not clear that that would be any simpler than the extra else-if).
+ if (fbs_file == "reflection/reflection.fbs") {
+ if (include_suffix == "generated") {
+ return "flatbuffers/reflection_generated.h";
+ } else if (include_suffix == "static") {
+ return "aos/flatbuffers/reflection/reflection_static.h";
+ } else {
+ LOG(FATAL) << "This should be unreachable.";
+ }
+ }
fbs_file.remove_suffix(4);
return absl::StrCat(fbs_file, "_", include_suffix, ".h");
}