diff options
author | Pierre-Clément Tosi <ptosi@google.com> | 2023-10-11 16:37:55 +0100 |
---|---|---|
committer | Pierre-Clément Tosi <ptosi@google.com> | 2023-10-11 16:54:04 +0100 |
commit | c8d1d863ab72b74efe7bda4c80579968716708a6 (patch) | |
tree | f98131a548060575351ccec043846f3531f7d5da | |
parent | 6127032bf7a8477115afb15c66fcefe86ed3601f (diff) | |
download | dtc-c8d1d863ab72b74efe7bda4c80579968716708a6.tar.gz |
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
-rw-r--r-- | BUILD.bazel | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/BUILD.bazel b/BUILD.bazel index 8a65ba8..634115c 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -21,38 +21,20 @@ COPTS = [ ] genrule( - name = "lexer", - srcs = [ - "dtc-lexer.l", - ":parser", - ], + name = "dtc_lexer_srcs", + srcs = ["dtc-lexer.l"], outs = ["dtc-lexer.lex.c"], - cmd = "lex -o$@ $(location dtc-lexer.l)", + cmd = "lex -o $@ $<", ) genrule( - name = "parser", + name = "dtc_parser_srcs", srcs = ["dtc-parser.y"], outs = [ "dtc-parser.c", "dtc-parser.h", ], - cmd = """ - bison -b dtc-parser -d $(location dtc-parser.y) - cp ./*.c $(location dtc-parser.c) - cp ./*.h $(location dtc-parser.h) - """, -) - -cc_library( - name = "dtc_gen", - srcs = [ - ":lexer", - ":parser", - ], - hdrs = glob(["*.h"]), - copts = COPTS, - deps = [":libfdt"], + cmd = "bison -d -o $(location dtc-parser.c) $(location dtc-parser.y)", ) UTILS = [ @@ -64,6 +46,8 @@ UTILS = [ cc_binary( name = "dtc", srcs = UTILS + [ + ":dtc_lexer_srcs", + ":dtc_parser_srcs", "checks.c", "data.c", "dtc.c", @@ -77,10 +61,7 @@ cc_binary( ], copts = COPTS, defines = ["NO_YAML"], - deps = [ - ":dtc_gen", - ":libfdt", - ], + deps = [":libfdt"], ) cc_binary( |