Merge changes I6b780c1d,I238d963a,I32076c65 into main

* changes:
  ANDROID: Generate version_gen.h in Soong and Bazel
  ANDROID: bazel: Clean up lexer and parser rules
  ANDROID: bazel: Fix dtc header dependencies
This commit is contained in:
Pierre-Clément Tosi 2023-10-12 09:16:53 +00:00 committed by Gerrit Code Review
commit 51f1006440
5 changed files with 48 additions and 43 deletions

View file

@ -62,6 +62,7 @@ cc_defaults {
"-DNO_YAML" "-DNO_YAML"
], ],
generated_headers: ["dtc_version_gen.h"],
shared_libs: ["libfdt"], shared_libs: ["libfdt"],
stl: "none", stl: "none",
@ -117,3 +118,17 @@ cc_binary_host {
"util.c", "util.c",
], ],
} }
genrule {
name: "dtc_version_gen.h",
out: ["version_gen.h"],
srcs: ["version_gen.h.in"],
tool_files: [
"METADATA",
"METADATA_version.sed",
],
cmd: "version=$$("
+ "sed -f $(location METADATA_version.sed) -n $(location METADATA)"
+ ")-Android-build;"
+ "sed s/@VCS_TAG@/$${version}/ $(in) > $(out)",
}

View file

@ -18,68 +18,67 @@ cc_library(
) )
genrule( genrule(
name = "lexer", name = "dtc_lexer_srcs",
srcs = [ srcs = ["dtc-lexer.l"],
"dtc-lexer.l",
":parser",
],
outs = ["dtc-lexer.lex.c"], outs = ["dtc-lexer.lex.c"],
cmd = "lex -o$@ $(location dtc-lexer.l)", cmd = "lex -o $@ $<",
) )
genrule( genrule(
name = "parser", name = "dtc_parser_srcs",
srcs = ["dtc-parser.y"], srcs = ["dtc-parser.y"],
outs = [ outs = [
"dtc-parser.c", "dtc-parser.c",
"dtc-parser.h", "dtc-parser.h",
], ],
cmd = """ cmd = "bison -d -o $(location dtc-parser.c) $(location dtc-parser.y)",
bison -b dtc-parser -d $(location dtc-parser.y)
cp ./*.c $(location dtc-parser.c)
cp ./*.h $(location dtc-parser.h)
""",
) )
cc_library( UTILS = [
name = "dtc_gen", "util.c",
"util.h",
":version_gen_header",
]
genrule(
name = "version_gen_header",
outs = ["version_gen.h"],
srcs = [ srcs = [
":lexer", "METADATA",
":parser", "METADATA_version.sed",
"version_gen.h.in",
], ],
hdrs = glob(["*.h"]), cmd = """
copts = COPTS, version="$$(sed -f $(location METADATA_version.sed) -n $(location METADATA))-Android-build"
deps = [":libfdt"], sed s/@VCS_TAG@/$${version}/ $(location version_gen.h.in) > $@
""",
) )
cc_binary( cc_binary(
name = "dtc", name = "dtc",
srcs = [ srcs = UTILS + [
":dtc_lexer_srcs",
":dtc_parser_srcs",
"checks.c", "checks.c",
"data.c", "data.c",
"dtc.c", "dtc.c",
"dtc.h",
"flattree.c", "flattree.c",
"fstree.c", "fstree.c",
"livetree.c", "livetree.c",
"srcpos.c", "srcpos.c",
"srcpos.h",
"treesource.c", "treesource.c",
"util.c",
], ],
copts = COPTS, copts = COPTS,
defines = ["NO_YAML"], defines = ["NO_YAML"],
deps = [ deps = [":libfdt"],
":dtc_gen",
":libfdt",
],
) )
cc_binary( cc_binary(
name = "fdtget", name = "fdtget",
srcs = [ srcs = UTILS + [
"fdtget.c", "fdtget.c",
"util.c",
"util.h",
"version_non_gen.h",
], ],
copts = COPTS, copts = COPTS,
defines = ["NO_YAML"], defines = ["NO_YAML"],
@ -88,11 +87,8 @@ cc_binary(
cc_binary( cc_binary(
name = "fdtput", name = "fdtput",
srcs = [ srcs = UTILS + [
"fdtput.c", "fdtput.c",
"util.c",
"util.h",
"version_non_gen.h",
], ],
copts = COPTS, copts = COPTS,
defines = ["NO_YAML"], defines = ["NO_YAML"],
@ -101,11 +97,8 @@ cc_binary(
cc_binary( cc_binary(
name = "fdtdump", name = "fdtdump",
srcs = [ srcs = UTILS + [
"fdtdump.c", "fdtdump.c",
"util.c",
"util.h",
"version_non_gen.h",
], ],
copts = COPTS, copts = COPTS,
defines = ["NO_YAML"], defines = ["NO_YAML"],
@ -114,11 +107,8 @@ cc_binary(
cc_binary( cc_binary(
name = "fdtoverlay", name = "fdtoverlay",
srcs = [ srcs = UTILS + [
"fdtoverlay.c", "fdtoverlay.c",
"util.c",
"util.h",
"version_non_gen.h",
], ],
copts = COPTS, copts = COPTS,
defines = ["NO_YAML"], defines = ["NO_YAML"],

1
METADATA_version.sed Normal file
View file

@ -0,0 +1 @@
s/^[[:space:]]*version:[[:space:]]*"v\([[:digit:]][[:digit:]]*.[[:digit:]][[:digit:]]*.[[:digit:]][[:digit:]]*\)"[[:space:]]*/\1/p

2
util.c
View file

@ -21,7 +21,7 @@
#include "libfdt.h" #include "libfdt.h"
#include "util.h" #include "util.h"
#include "version_non_gen.h" #include "version_gen.h"
char *xstrdup(const char *s) char *xstrdup(const char *s)
{ {

View file

@ -1 +0,0 @@
#define DTC_VERSION "DTC 1.6.0-Android-build"