platform_external_dtc/BUILD.bazel
Pierre-Clément Tosi 7eeadceb3e ANDROID: Generate version_gen.h in Soong and Bazel
Upstream provides a DTC_VERSION preprocessor macro to its C code by
generating a version_gen.h header from either of its supported build
systems: Make formats the header from its internal variables (VERSION,
PATCHLEVEL, SUBLEVEL, ...) while Meson uses its vcs_tag() function on
a template, version_gen.h.in.

As AOSP doesn't make use of these build systems, aosp/204511 decided to
hardcode a version_non_gen.h file and patch the corresponding #include.
This unsurprisingly ended up bitrotting as the repo was being upgraded.

Instead, replicate the version_gen.h.in patching in our build systems,
extracting the version number from the METADATA file, which
external_updater.sh will keep up-to-date. Note that this introduces a
dependency on sed in the genrule(), the impact of which is minimized by
making METADATA_version.sed POSIX-compliant.

Keep appending the suffix '-Android-build' to the upstream version.

Test: m dtc && ${ANDROID_HOST_OUT}/bin/dtc --version
Test: bazel build //:dtc && bazel-bin/dtc --version
Change-Id: I6b780c1dbe14d415891defeb652f0692988ed0b1
2023-10-11 19:15:08 +01:00

119 lines
2.1 KiB
Python

cc_library(
name = "libfdt",
srcs = glob([
"libfdt/*.h",
"libfdt/*.c",
]),
copts = [
"-Werror",
"-Wno-macro-redefined",
"-Wno-sign-compare",
],
includes = ["libfdt"],
)
COPTS = [
"-Wall",
"-Werror",
"-Wno-sign-compare",
"-Wno-missing-field-initializers",
"-Wno-unused-parameter",
]
genrule(
name = "dtc_lexer_srcs",
srcs = ["dtc-lexer.l"],
outs = ["dtc-lexer.lex.c"],
cmd = "lex -o $@ $<",
)
genrule(
name = "dtc_parser_srcs",
srcs = ["dtc-parser.y"],
outs = [
"dtc-parser.c",
"dtc-parser.h",
],
cmd = "bison -d -o $(location dtc-parser.c) $(location dtc-parser.y)",
)
UTILS = [
"util.c",
"util.h",
":version_gen_header",
]
genrule(
name = "version_gen_header",
outs = ["version_gen.h"],
srcs = [
"METADATA",
"METADATA_version.sed",
"version_gen.h.in",
],
cmd = """
version="$$(sed -f $(location METADATA_version.sed) -n $(location METADATA))-Android-build"
sed s/@VCS_TAG@/$${version}/ $(location version_gen.h.in) > $@
""",
)
cc_binary(
name = "dtc",
srcs = UTILS + [
":dtc_lexer_srcs",
":dtc_parser_srcs",
"checks.c",
"data.c",
"dtc.c",
"dtc.h",
"flattree.c",
"fstree.c",
"livetree.c",
"srcpos.c",
"srcpos.h",
"treesource.c",
],
copts = COPTS,
defines = ["NO_YAML"],
deps = [":libfdt"],
)
cc_binary(
name = "fdtget",
srcs = UTILS + [
"fdtget.c",
],
copts = COPTS,
defines = ["NO_YAML"],
deps = [":libfdt"],
)
cc_binary(
name = "fdtput",
srcs = UTILS + [
"fdtput.c",
],
copts = COPTS,
defines = ["NO_YAML"],
deps = [":libfdt"],
)
cc_binary(
name = "fdtdump",
srcs = UTILS + [
"fdtdump.c",
],
copts = COPTS,
defines = ["NO_YAML"],
deps = [":libfdt"],
)
cc_binary(
name = "fdtoverlay",
srcs = UTILS + [
"fdtoverlay.c",
],
copts = COPTS,
defines = ["NO_YAML"],
deps = [":libfdt"],
)