Skip to content

Commit 8bca38b

Browse files
bpeckham64Shadab Naseem
authored and
Shadab Naseem
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]>
1 parent eca6275 commit 8bca38b

4 files changed

+35
-12
lines changed

Android.bp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ 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+
// (Ie3b8c36b7d60bd950c28bac566e04f43de78cf98,b/178500203)
14+
cmd: "sed 's+scripts/unifdef+$$LOC_UNIFDEF+g' $(in) > $(out)",
1515
}
1616

1717
cc_prebuilt_binary {

gen_headers_arm.bp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,10 @@ genrule {
10411041

10421042
genrule {
10431043
name: "qti_generate_kernel_headers_arm",
1044-
tools: ["headers_install.sh"],
1044+
tools: [
1045+
"headers_install.sh",
1046+
"unifdef",
1047+
],
10451048
tool_files: [
10461049
"kernel_headers.py",
10471050
"arch/arm/tools/syscallhdr.sh",
@@ -1066,6 +1069,7 @@ genrule {
10661069
"--arch_syscall_tool $(location arch/arm/tools/syscallhdr.sh) " +
10671070
"--arch_syscall_tbl $(location arch/arm/tools/syscall.tbl) " +
10681071
"--headers_install $(location headers_install.sh) " +
1072+
"--unifdef $(location unifdef) " +
10691073
"--include_uapi $(locations include/uapi/**/*.h)",
10701074
out: ["linux/version.h"] + gen_headers_out_arm,
10711075
}

gen_headers_arm64.bp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,10 @@ genrule {
10371037

10381038
genrule {
10391039
name: "qti_generate_kernel_headers_arm64",
1040-
tools: ["headers_install.sh"],
1040+
tools: [
1041+
"headers_install.sh",
1042+
"unifdef",
1043+
],
10411044
tool_files: [
10421045
"kernel_headers.py",
10431046
],
@@ -1059,6 +1062,7 @@ genrule {
10591062
"--new_gen_headers_bp $(location :qti_generate_gen_headers_arm64) " +
10601063
"--version_makefile $(location Makefile) " +
10611064
"--headers_install $(location headers_install.sh) " +
1065+
"--unifdef $(location unifdef) " +
10621066
"--include_uapi $(locations include/uapi/**/*.h)",
10631067
out: ["linux/version.h"] + gen_headers_out_arm64,
10641068
}

kernel_headers.py

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

311311

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

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

348351
if result != 0:
349352
print('error: run_headers_install: cmd %s failed %d' % (cmd, result))
@@ -510,6 +513,7 @@ def gen_blueprints(
510513

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

@@ -657,7 +661,10 @@ def gen_blueprints(
657661

658662
f.write('genrule {\n')
659663
f.write(' name: "qti_generate_kernel_headers_%s",\n' % header_arch)
660-
f.write(' tools: ["%s"],\n' % headers_install_sh)
664+
f.write(' tools: [\n')
665+
f.write(' "%s",\n' % headers_install_sh)
666+
f.write(' "%s",\n' % unifdef)
667+
f.write(' ],\n')
661668
f.write(' tool_files: [\n')
662669
f.write(' "%s",\n' % kernel_headers_py)
663670

@@ -691,6 +698,7 @@ def gen_blueprints(
691698
f.write(' "--arch_syscall_tbl $(location %s) " +\n' % arm_syscall_tbl)
692699

693700
f.write(' "--headers_install $(location %s) " +\n' % headers_install_sh)
701+
f.write(' "--unifdef $(location %s) " +\n' % unifdef)
694702
f.write(' "--include_uapi $(locations %s)",\n' % generic_src)
695703
f.write(' out: ["linux/version.h"] + gen_headers_out_%s,\n' % header_arch)
696704
f.write('}\n')
@@ -745,7 +753,7 @@ def headers_diff(old_file, new_file):
745753
def gen_headers(
746754
verbose, header_arch, gen_dir, arch_asm_kbuild, asm_generic_kbuild, module_dir,
747755
old_gen_headers_bp, new_gen_headers_bp, version_makefile,
748-
arch_syscall_tool, arch_syscall_tbl, headers_install, include_uapi,
756+
arch_syscall_tool, arch_syscall_tbl, headers_install, unifdef, include_uapi,
749757
arch_include_uapi, techpack_include_uapi):
750758
"""Generate the kernel headers.
751759
@@ -767,6 +775,7 @@ def gen_headers(
767775
arch_syscall_tool: The arch script that generates syscall headers.
768776
arch_syscall_tbl: The arch script that defines syscall vectors.
769777
headers_install: The headers_install tool to process input headers.
778+
unifdef: The unifdef tool used by headers_install.
770779
include_uapi: The list of include/uapi header files.
771780
arch_include_uapi: The list of arch/<arch>/include/uapi header files.
772781
Return:
@@ -794,20 +803,20 @@ def gen_headers(
794803

795804
for h in include_uapi:
796805
if not run_headers_install(
797-
verbose, gen_dir, headers_install,
806+
verbose, gen_dir, headers_install, unifdef,
798807
uapi_include_prefix, h):
799808
error_count += 1
800809

801810
for h in arch_include_uapi:
802811
if not run_headers_install(
803-
verbose, gen_dir, headers_install,
812+
verbose, gen_dir, headers_install, unifdef,
804813
arch_uapi_include_prefix, h):
805814
error_count += 1
806815

807816
for h in techpack_include_uapi:
808817
techpack_uapi_include_prefix = os.path.join(h.split('/include/uapi')[0], 'include', 'uapi') + os.sep
809818
if not run_headers_install(
810-
verbose, gen_dir, headers_install,
819+
verbose, gen_dir, headers_install, unifdef,
811820
techpack_uapi_include_prefix, h):
812821
error_count += 1
813822

@@ -934,6 +943,10 @@ def main():
934943
'--headers_install',
935944
required=True,
936945
help='The headers_install tool to process input headers.')
946+
parser_headers.add_argument(
947+
'--unifdef',
948+
required=True,
949+
help='The unifdef tool used by headers_install.')
937950
parser_headers.add_argument(
938951
'--include_uapi',
939952
required=True,
@@ -982,12 +995,14 @@ def main():
982995
print('arch_syscall_tool [%s]' % args.arch_syscall_tool)
983996
print('arch_syscall_tbl [%s]' % args.arch_syscall_tbl)
984997
print('headers_install [%s]' % args.headers_install)
998+
print('unifdef [%s]' % args.unifdef)
985999

9861000
return gen_headers(
9871001
args.verbose, args.header_arch, args.gen_dir, args.arch_asm_kbuild,
9881002
args.asm_generic_kbuild, module_dir, args.old_gen_headers_bp, args.new_gen_headers_bp,
9891003
args.version_makefile, args.arch_syscall_tool, args.arch_syscall_tbl,
990-
args.headers_install, args.include_uapi, args.arch_include_uapi, args.techpack_include_uapi)
1004+
args.headers_install, args.unifdef, args.include_uapi, args.arch_include_uapi,
1005+
args.techpack_include_uapi)
9911006

9921007
print('error: unknown mode: %s' % args.mode)
9931008
return 1

0 commit comments

Comments
 (0)