Skip to content

Commit a6248a1

Browse files
bpeckham64Eruvaram Kumar Raja Reddy
authored and
Eruvaram Kumar Raja Reddy
committed
Use environment variable to find unifdef tool
Tools used within the sandbox are now copied into the sandbox, see aosp/1531944. This caused the modified headers_install.sh, which is no longer installed, to point to a non-existent location. This change adds a level of indirection. The gen-headers_install.sh module no longer uses unifdef as a tool, but still modifies the headers_install.sh script, but not to point to a particular location, but to find the unifdef tool via an environment variable, LOC_UNIFDEF. Next, we modify qti_generate_kernel_headers_arm and qti_generate_kernel_headers_arm64 to need the unifdef tool (which is copied into the sandbox for these tools). We add a new --unifdef option to the kernel_headers.py script so that it can find the tool in the sandbox. The kernel_headers.py script sets the LOC_UNIFDEF environment variable before invoking the altered headers_install.sh script (also copied into the sandbox). Finally, we generate gen_headers_arm.bp and gen_headers_arm64.bp with all of these changes. Bug: 178500203 Change-Id: Ie3b8c36b7d60bd950c28bac566e04f43de78cf98 Signed-off-by: Mohammed Athar <[email protected]> Signed-off-by: Shadab Naseem <[email protected]> Signed-off-by: Eruvaram Kumar Raja Reddy <[email protected]>
1 parent 3cbf9a9 commit a6248a1

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

Androidbp

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ cc_binary_host {
99
genrule {
1010
name: "gen-headers_install.sh",
1111
srcs: ["scripts/headers_install.sh"],
12-
tools: ["unifdef"],
1312
out: ["headers_install.sh"],
14-
cmd: "sed 's+scripts/unifdef+$(location unifdef)+g' $(in) > $(out)",
13+
cmd: "sed 's+scripts/unifdef+$$LOC_UNIFDEF+g' $(in) > $(out)",
1514
}
1615

1716
cc_prebuilt_binary {

gen_headers_arm.bp

+5-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,10 @@ genrule {
951951

952952
genrule {
953953
name: "qti_generate_kernel_headers_arm",
954-
tools: ["headers_install.sh"],
954+
tools: [
955+
"headers_install.sh",
956+
"unifdef",
957+
],
955958
tool_files: [
956959
"kernel_headers.py",
957960
"arch/arm/tools/syscallhdr.sh",
@@ -975,6 +978,7 @@ genrule {
975978
"--arch_syscall_tool $(location arch/arm/tools/syscallhdr.sh) " +
976979
"--arch_syscall_tbl $(location arch/arm/tools/syscall.tbl) " +
977980
"--headers_install $(location headers_install.sh) " +
981+
"--unifdef $(location unifdef) " +
978982
"--include_uapi $(locations include/uapi/**/*.h)",
979983
out: ["linux/version.h"] + gen_headers_out_arm,
980984
}

gen_headers_arm64.bp

+5-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,10 @@ genrule {
948948

949949
genrule {
950950
name: "qti_generate_kernel_headers_arm64",
951-
tools: ["headers_install.sh"],
951+
tools: [
952+
"headers_install.sh",
953+
"unifdef",
954+
],
952955
tool_files: [
953956
"kernel_headers.py",
954957
],
@@ -969,6 +972,7 @@ genrule {
969972
"--new_gen_headers_bp $(location :qti_generate_gen_headers_arm64) " +
970973
"--version_makefile $(location Makefile) " +
971974
"--headers_install $(location headers_install.sh) " +
975+
"--unifdef $(location unifdef) " +
972976
"--include_uapi $(locations include/uapi/**/*.h)",
973977
out: ["linux/version.h"] + gen_headers_out_arm64,
974978
}

kernel_headers.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def gen_arch_headers(
310310
return error_count
311311

312312

313-
def run_headers_install(verbose, gen_dir, headers_install, prefix, h):
313+
def run_headers_install(verbose, gen_dir, headers_install, unifdef, prefix, h):
314314
"""Process a header through the headers_install script.
315315
316316
The headers_install script does some processing of a header so that it is
@@ -325,6 +325,7 @@ def run_headers_install(verbose, gen_dir, headers_install, prefix, h):
325325
verbose: Set True to print progress messages.
326326
gen_dir: Where to place the generated files.
327327
headers_install: The script that munges the header.
328+
unifdef: The unifdef tool used by headers_install.
328329
prefix: The prefix to strip from h to generate the output filename.
329330
h: The input header to process.
330331
Return:
@@ -344,7 +345,9 @@ def run_headers_install(verbose, gen_dir, headers_install, prefix, h):
344345
if verbose:
345346
print('run_headers_install: cmd is %s' % cmd)
346347

347-
result = subprocess.call(['sh', headers_install, h, out_h])
348+
env = os.environ.copy()
349+
env["LOC_UNIFDEF"] = unifdef
350+
result = subprocess.call(['sh', headers_install, h, out_h], env=env)
348351

349352
if result != 0:
350353
print('error: run_headers_install: cmd %s failed %d' % (cmd, result))
@@ -586,6 +589,7 @@ def gen_blueprints(
586589

587590
# Tools and tool files.
588591
headers_install_sh = 'headers_install.sh'
592+
unifdef = 'unifdef'
589593
kernel_headers_py = 'kernel_headers.py'
590594
arm_syscall_tool = 'arch/arm/tools/syscallhdr.sh'
591595

@@ -740,7 +744,10 @@ def gen_blueprints(
740744

741745
f.write('genrule {\n')
742746
f.write(' name: "qti_generate_kernel_headers_%s",\n' % header_arch)
743-
f.write(' tools: ["%s"],\n' % headers_install_sh)
747+
f.write(' tools: [\n')
748+
f.write(' "%s",\n' % headers_install_sh)
749+
f.write(' "%s",\n' % unifdef)
750+
f.write(' ],\n')
744751
f.write(' tool_files: [\n')
745752
f.write(' "%s",\n' % kernel_headers_py)
746753

@@ -773,6 +780,7 @@ def gen_blueprints(
773780
f.write(' "--arch_syscall_tbl $(location %s) " +\n' % arm_syscall_tbl)
774781

775782
f.write(' "--headers_install $(location %s) " +\n' % headers_install_sh)
783+
f.write(' "--unifdef $(location %s) " +\n' % unifdef)
776784
f.write(' "--include_uapi $(locations %s)",\n' % generic_src)
777785
f.write(' out: ["linux/version.h"] + gen_headers_out_%s,\n' % header_arch)
778786
f.write('}\n')
@@ -827,7 +835,7 @@ def headers_diff(old_file, new_file):
827835
def gen_headers(
828836
verbose, header_arch, gen_dir, arch_asm_kbuild, asm_generic_kbuild, module_dir,
829837
old_gen_headers_bp, new_gen_headers_bp, version_makefile,
830-
arch_syscall_tool, arch_syscall_tbl, headers_install, include_uapi,
838+
arch_syscall_tool, arch_syscall_tbl, headers_install, unifdef, include_uapi,
831839
arch_include_uapi, techpack_include_uapi):
832840
"""Generate the kernel headers.
833841
@@ -849,6 +857,7 @@ def gen_headers(
849857
arch_syscall_tool: The arch script that generates syscall headers.
850858
arch_syscall_tbl: The arch script that defines syscall vectors.
851859
headers_install: The headers_install tool to process input headers.
860+
unifdef: The unifdef tool used by headers_install.
852861
include_uapi: The list of include/uapi header files.
853862
arch_include_uapi: The list of arch/<arch>/include/uapi header files.
854863
Return:
@@ -876,20 +885,20 @@ def gen_headers(
876885

877886
for h in include_uapi:
878887
if not run_headers_install(
879-
verbose, gen_dir, headers_install,
888+
verbose, gen_dir, headers_install, unifdef,
880889
uapi_include_prefix, h):
881890
error_count += 1
882891

883892
for h in arch_include_uapi:
884893
if not run_headers_install(
885-
verbose, gen_dir, headers_install,
894+
verbose, gen_dir, headers_install, unifdef,
886895
arch_uapi_include_prefix, h):
887896
error_count += 1
888897

889898
for h in techpack_include_uapi:
890899
techpack_uapi_include_prefix = os.path.join(h.split('/include/uapi')[0], 'include', 'uapi') + os.sep
891900
if not run_headers_install(
892-
verbose, gen_dir, headers_install,
901+
verbose, gen_dir, headers_install, unifdef,
893902
techpack_uapi_include_prefix, h):
894903
error_count += 1
895904

@@ -1011,6 +1020,10 @@ def main():
10111020
'--headers_install',
10121021
required=True,
10131022
help='The headers_install tool to process input headers.')
1023+
parser_headers.add_argument(
1024+
'--unifdef',
1025+
required=True,
1026+
help='The unifdef tool used by headers_install.')
10141027
parser_headers.add_argument(
10151028
'--include_uapi',
10161029
required=True,
@@ -1061,12 +1074,14 @@ def main():
10611074
print('arch_syscall_tool [%s]' % args.arch_syscall_tool)
10621075
print('arch_syscall_tbl [%s]' % args.arch_syscall_tbl)
10631076
print('headers_install [%s]' % args.headers_install)
1077+
print('unifdef [%s]' % args.unifdef)
10641078

10651079
return gen_headers(
10661080
args.verbose, args.header_arch, args.gen_dir, args.arch_asm_kbuild,
10671081
args.asm_generic_kbuild, module_dir, args.old_gen_headers_bp, args.new_gen_headers_bp,
10681082
args.version_makefile, args.arch_syscall_tool, args.arch_syscall_tbl,
1069-
args.headers_install, args.include_uapi, args.arch_include_uapi, techpack_include_uapi)
1083+
args.headers_install, args.unifdef, args.include_uapi, args.arch_include_uapi,
1084+
techpack_include_uapi)
10701085

10711086
print('error: unknown mode: %s' % args.mode)
10721087
return 1

0 commit comments

Comments
 (0)