Commit graph

4 commits

Author SHA1 Message Date
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
Pierre-Clément Tosi
c8d1d863ab ANDROID: bazel: Clean up lexer and parser rules
Simplify the build file as

- dtc_gen creates an unnecessarily broad (and confusing) dependency list
  by using glob([".h"]) as its header list. Instead, dtc now lists
  explicitly the few headers it actually needs;
- generating dtc-lexer.lex.c does not require dtc-parser.{c,h};
- Bison can be told to directly create dtc-parser.{c,h} so no need for
  an unnecessarily broad copying of *.[ch] to move some intermediate
  results.

As a result, we get two genrule() wrapping the source files respectively
generated through lex and bison, which can be listed as srcs of dtc.

Test: bazel build //:all
Change-Id: I238d963af8a338c46f39c8ba9e4314fe536948cf
2023-10-11 16:54:04 +01:00
Pierre-Clément Tosi
6127032bf7 ANDROID: bazel: Fix dtc header dependencies
As dtc compiles util.c, which includes util.h and version_non_gen.h
(or version_gen.h upstream), the cc_binary should list those
dependencies explicitly so that a change in them triggers a rebuild.

Furthermore, dtc also depends on dtc.h and srcpos.h, which are only
found as dependencies by Bazel through the overkill glob(["*.h"]) header
list of dtc_gen so list them explicitly here so that that cc_library can
be dropped.

Introduce the UTILS list to DRY the build file.

Test: bazel build //:dtc
Change-Id: I32076c65b60820dc91f6dc84c3ee3cad310c1db5
2023-10-11 16:53:57 +01:00
John Moon
b148d78706 build: Add BUILD.bazel file
Currently, the dtc project builds with Make.

As some consumers of this project use Bazel, and eventually all of
AOSP will need to move to Bazel anyway, add a a Bazel build
definition.

Bug: 251879933
Change-Id: I62ea59ee306eda58b764df2a9e5f2f33778e4b5c
Signed-off-by: John Moon <quic_johmoo@quicinc.com>
2023-04-28 09:19:45 -07:00