mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Use Label() to resolve repo name (#8493)
This makes sure it doesn't break users when they choose a different repo_name.
This commit is contained in:
@@ -7,13 +7,19 @@ Rules for building C++ flatbuffers with Bazel.
|
|||||||
|
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||||
|
|
||||||
TRUE_FLATC_PATH = "@com_github_google_flatbuffers//:flatc"
|
def repo_name(label):
|
||||||
|
if hasattr(label, "repo_name"): # Added in Bazel 7.1
|
||||||
|
return label.repo_name
|
||||||
|
else:
|
||||||
|
return "com_github_google_flatbuffers"
|
||||||
|
|
||||||
|
TRUE_FLATC_PATH = Label("//:flatc")
|
||||||
|
|
||||||
DEFAULT_INCLUDE_PATHS = [
|
DEFAULT_INCLUDE_PATHS = [
|
||||||
"./",
|
"./",
|
||||||
"$(GENDIR)",
|
"$(GENDIR)",
|
||||||
"$(BINDIR)",
|
"$(BINDIR)",
|
||||||
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
"$(execpath %s).runfiles/%s" % (TRUE_FLATC_PATH, repo_name(TRUE_FLATC_PATH)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def default_include_paths(flatc_path):
|
def default_include_paths(flatc_path):
|
||||||
@@ -21,7 +27,7 @@ def default_include_paths(flatc_path):
|
|||||||
"./",
|
"./",
|
||||||
"$(GENDIR)",
|
"$(GENDIR)",
|
||||||
"$(BINDIR)",
|
"$(BINDIR)",
|
||||||
"$(execpath %s).runfiles/com_github_google_flatbuffers" % (flatc_path),
|
"$(execpath %s).runfiles/%s" % (flatc_path, repo_name(flatc_path)),
|
||||||
]
|
]
|
||||||
|
|
||||||
DEFAULT_FLATC_ARGS = [
|
DEFAULT_FLATC_ARGS = [
|
||||||
@@ -47,7 +53,7 @@ def flatbuffer_library_public(
|
|||||||
compatible_with = None,
|
compatible_with = None,
|
||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
target_compatible_with = None,
|
target_compatible_with = None,
|
||||||
flatc_path = "@com_github_google_flatbuffers//:flatc",
|
flatc_path = None,
|
||||||
output_to_bindir = False,
|
output_to_bindir = False,
|
||||||
tools = None,
|
tools = None,
|
||||||
extra_env = None,
|
extra_env = None,
|
||||||
@@ -87,6 +93,11 @@ def flatbuffer_library_public(
|
|||||||
optionally a Fileset([reflection_name]) with all generated reflection
|
optionally a Fileset([reflection_name]) with all generated reflection
|
||||||
binaries.
|
binaries.
|
||||||
"""
|
"""
|
||||||
|
if flatc_path == None:
|
||||||
|
flatc_path = TRUE_FLATC_PATH
|
||||||
|
else:
|
||||||
|
flatc_path = native.package_relative_label(flatc_path)
|
||||||
|
|
||||||
reflection_include_paths = include_paths
|
reflection_include_paths = include_paths
|
||||||
if include_paths == None:
|
if include_paths == None:
|
||||||
include_paths = default_include_paths(flatc_path)
|
include_paths = default_include_paths(flatc_path)
|
||||||
@@ -262,8 +273,8 @@ def flatbuffer_cc_library(
|
|||||||
"-parse_headers",
|
"-parse_headers",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
"@com_github_google_flatbuffers//:runtime_cc",
|
Label("//:runtime_cc"),
|
||||||
"@com_github_google_flatbuffers//:flatbuffers",
|
Label("//:flatbuffers"),
|
||||||
] + deps,
|
] + deps,
|
||||||
includes = cc_include_paths,
|
includes = cc_include_paths,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ sh_binary(
|
|||||||
name = "compile_flat_file",
|
name = "compile_flat_file",
|
||||||
srcs = ["compile_flat_file.sh"],
|
srcs = ["compile_flat_file.sh"],
|
||||||
data = [
|
data = [
|
||||||
"@com_github_google_flatbuffers//:flatc",
|
"//:flatc",
|
||||||
"@nodejs_linux_amd64//:node_bin",
|
"@nodejs_linux_amd64//:node_bin",
|
||||||
],
|
],
|
||||||
# We just depend directly on the linux amd64 nodejs binary, so only support
|
# We just depend directly on the linux amd64 nodejs binary, so only support
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ def flatbuffer_ts_library(
|
|||||||
reflection_name = reflection_name,
|
reflection_name = reflection_name,
|
||||||
reflection_visibility = visibility,
|
reflection_visibility = visibility,
|
||||||
target_compatible_with = target_compatible_with,
|
target_compatible_with = target_compatible_with,
|
||||||
flatc_path = "@com_github_google_flatbuffers//ts:compile_flat_file",
|
flatc_path = Label("//ts:compile_flat_file"),
|
||||||
toolchains = ["@aspect_rules_esbuild//esbuild:resolved_toolchain"],
|
toolchains = ["@aspect_rules_esbuild//esbuild:resolved_toolchain"],
|
||||||
tools = ["@aspect_rules_esbuild//esbuild:resolved_toolchain"],
|
tools = ["@aspect_rules_esbuild//esbuild:resolved_toolchain"],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user