Skip to content

Commit e4be7f7

Browse files
bpeckham64Forenche
authored andcommitted
kernel_headers: 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]> Signed-off-by: Forenche <[email protected]>
1 parent ffbb5b1 commit e4be7f7

4 files changed

+32
-11
lines changed

Android.bp

+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
@@ -995,7 +995,10 @@ genrule {
995995

996996
genrule {
997997
name: "qti_generate_kernel_headers_arm",
998-
tools: ["headers_install.sh"],
998+
tools: [
999+
"headers_install.sh",
1000+
"unifdef",
1001+
],
9991002
tool_files: [
10001003
"kernel_headers.py",
10011004
"arch/arm/tools/syscallhdr.sh",
@@ -1019,6 +1022,7 @@ genrule {
10191022
"--arch_syscall_tool $(location arch/arm/tools/syscallhdr.sh) " +
10201023
"--arch_syscall_tbl $(location arch/arm/tools/syscall.tbl) " +
10211024
"--headers_install $(location headers_install.sh) " +
1025+
"--unifdef $(location unifdef) " +
10221026
"--include_uapi $(locations include/uapi/**/*.h)",
10231027
out: ["linux/version.h"] + gen_headers_out_arm,
10241028
}

gen_headers_arm64.bp

+5-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,10 @@ genrule {
989989

990990
genrule {
991991
name: "qti_generate_kernel_headers_arm64",
992-
tools: ["headers_install.sh"],
992+
tools: [
993+
"headers_install.sh",
994+
"unifdef",
995+
],
993996
tool_files: [
994997
"kernel_headers.py",
995998
],
@@ -1010,6 +1013,7 @@ genrule {
10101013
"--new_gen_headers_bp $(location :qti_generate_gen_headers_arm64) " +
10111014
"--version_makefile $(location Makefile) " +
10121015
"--headers_install $(location headers_install.sh) " +
1016+
"--unifdef $(location unifdef) " +
10131017
"--include_uapi $(locations include/uapi/**/*.h)",
10141018
out: ["linux/version.h"] + gen_headers_out_arm64,
10151019
}

kernel_headers.py

+21-7
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))
@@ -511,6 +514,7 @@ def gen_blueprints(
511514

512515
# Tools and tool files.
513516
headers_install_sh = 'headers_install.sh'
517+
unifdef = 'unifdef'
514518
kernel_headers_py = 'kernel_headers.py'
515519
arm_syscall_tool = 'arch/arm/tools/syscallhdr.sh'
516520

@@ -646,7 +650,10 @@ def gen_blueprints(
646650

647651
f.write('genrule {\n')
648652
f.write(' name: "qti_generate_kernel_headers_%s",\n' % header_arch)
649-
f.write(' tools: ["%s"],\n' % headers_install_sh)
653+
f.write(' tools: [\n')
654+
f.write(' "%s",\n' % headers_install_sh)
655+
f.write(' "%s",\n' % unifdef)
656+
f.write(' ],\n')
650657
f.write(' tool_files: [\n')
651658
f.write(' "%s",\n' % kernel_headers_py)
652659

@@ -679,6 +686,7 @@ def gen_blueprints(
679686
f.write(' "--arch_syscall_tbl $(location %s) " +\n' % arm_syscall_tbl)
680687

681688
f.write(' "--headers_install $(location %s) " +\n' % headers_install_sh)
689+
f.write(' "--unifdef $(location %s) " +\n' % unifdef)
682690
f.write(' "--include_uapi $(locations %s)",\n' % generic_src)
683691
f.write(' out: ["linux/version.h"] + gen_headers_out_%s,\n' % header_arch)
684692
f.write('}\n')
@@ -733,7 +741,7 @@ def headers_diff(old_file, new_file):
733741
def gen_headers(
734742
verbose, header_arch, gen_dir, arch_asm_kbuild, asm_generic_kbuild, module_dir,
735743
old_gen_headers_bp, new_gen_headers_bp, version_makefile,
736-
arch_syscall_tool, arch_syscall_tbl, headers_install, include_uapi,
744+
arch_syscall_tool, arch_syscall_tbl, headers_install, unifdef, include_uapi,
737745
arch_include_uapi):
738746
"""Generate the kernel headers.
739747
@@ -755,6 +763,7 @@ def gen_headers(
755763
arch_syscall_tool: The arch script that generates syscall headers.
756764
arch_syscall_tbl: The arch script that defines syscall vectors.
757765
headers_install: The headers_install tool to process input headers.
766+
unifdef: The unifdef tool used by headers_install.
758767
include_uapi: The list of include/uapi header files.
759768
arch_include_uapi: The list of arch/<arch>/include/uapi header files.
760769
Return:
@@ -782,13 +791,13 @@ def gen_headers(
782791

783792
for h in include_uapi:
784793
if not run_headers_install(
785-
verbose, gen_dir, headers_install,
794+
verbose, gen_dir, headers_install, unifdef,
786795
uapi_include_prefix, h):
787796
error_count += 1
788797

789798
for h in arch_include_uapi:
790799
if not run_headers_install(
791-
verbose, gen_dir, headers_install,
800+
verbose, gen_dir, headers_install, unifdef,
792801
arch_uapi_include_prefix, h):
793802
error_count += 1
794803

@@ -865,6 +874,10 @@ def main():
865874
'--headers_install',
866875
required=True,
867876
help='The headers_install tool to process input headers.')
877+
parser_headers.add_argument(
878+
'--unifdef',
879+
required=True,
880+
help='The unifdef tool used by headers_install.')
868881
parser_headers.add_argument(
869882
'--include_uapi',
870883
required=True,
@@ -912,12 +925,13 @@ def main():
912925
print('arch_syscall_tool [%s]' % args.arch_syscall_tool)
913926
print('arch_syscall_tbl [%s]' % args.arch_syscall_tbl)
914927
print('headers_install [%s]' % args.headers_install)
928+
print('unifdef [%s]' % args.unifdef)
915929

916930
return gen_headers(
917931
args.verbose, args.header_arch, args.gen_dir, args.arch_asm_kbuild,
918932
args.asm_generic_kbuild, module_dir, args.old_gen_headers_bp, args.new_gen_headers_bp,
919933
args.version_makefile, args.arch_syscall_tool, args.arch_syscall_tbl,
920-
args.headers_install, args.include_uapi, args.arch_include_uapi)
934+
args.headers_install, args.unifdef, args.include_uapi, args.arch_include_uapi)
921935

922936
print('error: unknown mode: %s' % args.mode)
923937
return 1

0 commit comments

Comments
 (0)