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 <athar@codeaurora.org>
Signed-off-by: Shadab Naseem <snaseem@codeaurora.org>
This commit is contained in:
Bill Peckham 2021-01-26 13:06:41 -08:00 committed by Shadab Naseem
parent eca62752fe
commit 8bca38b4d8
4 changed files with 35 additions and 12 deletions

View File

@ -9,9 +9,9 @@ cc_binary_host {
genrule {
name: "gen-headers_install.sh",
srcs: ["scripts/headers_install.sh"],
tools: ["unifdef"],
out: ["headers_install.sh"],
cmd: "sed 's+scripts/unifdef+$(location unifdef)+g' $(in) > $(out)",
// (Ie3b8c36b7d60bd950c28bac566e04f43de78cf98,b/178500203)
cmd: "sed 's+scripts/unifdef+$$LOC_UNIFDEF+g' $(in) > $(out)",
}
cc_prebuilt_binary {

View File

@ -1041,7 +1041,10 @@ genrule {
genrule {
name: "qti_generate_kernel_headers_arm",
tools: ["headers_install.sh"],
tools: [
"headers_install.sh",
"unifdef",
],
tool_files: [
"kernel_headers.py",
"arch/arm/tools/syscallhdr.sh",
@ -1066,6 +1069,7 @@ genrule {
"--arch_syscall_tool $(location arch/arm/tools/syscallhdr.sh) " +
"--arch_syscall_tbl $(location arch/arm/tools/syscall.tbl) " +
"--headers_install $(location headers_install.sh) " +
"--unifdef $(location unifdef) " +
"--include_uapi $(locations include/uapi/**/*.h)",
out: ["linux/version.h"] + gen_headers_out_arm,
}

View File

@ -1037,7 +1037,10 @@ genrule {
genrule {
name: "qti_generate_kernel_headers_arm64",
tools: ["headers_install.sh"],
tools: [
"headers_install.sh",
"unifdef",
],
tool_files: [
"kernel_headers.py",
],
@ -1059,6 +1062,7 @@ genrule {
"--new_gen_headers_bp $(location :qti_generate_gen_headers_arm64) " +
"--version_makefile $(location Makefile) " +
"--headers_install $(location headers_install.sh) " +
"--unifdef $(location unifdef) " +
"--include_uapi $(locations include/uapi/**/*.h)",
out: ["linux/version.h"] + gen_headers_out_arm64,
}

View File

@ -309,7 +309,7 @@ def gen_arch_headers(
return error_count
def run_headers_install(verbose, gen_dir, headers_install, prefix, h):
def run_headers_install(verbose, gen_dir, headers_install, unifdef, prefix, h):
"""Process a header through the headers_install script.
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):
verbose: Set True to print progress messages.
gen_dir: Where to place the generated files.
headers_install: The script that munges the header.
unifdef: The unifdef tool used by headers_install.
prefix: The prefix to strip from h to generate the output filename.
h: The input header to process.
Return:
@ -343,7 +344,9 @@ def run_headers_install(verbose, gen_dir, headers_install, prefix, h):
if verbose:
print('run_headers_install: cmd is %s' % cmd)
result = subprocess.call(['sh', headers_install, h, out_h])
env = os.environ.copy()
env["LOC_UNIFDEF"] = unifdef
result = subprocess.call(['sh', headers_install, h, out_h], env=env)
if result != 0:
print('error: run_headers_install: cmd %s failed %d' % (cmd, result))
@ -510,6 +513,7 @@ def gen_blueprints(
# Tools and tool files.
headers_install_sh = 'headers_install.sh'
unifdef = 'unifdef'
kernel_headers_py = 'kernel_headers.py'
arm_syscall_tool = 'arch/arm/tools/syscallhdr.sh'
@ -657,7 +661,10 @@ def gen_blueprints(
f.write('genrule {\n')
f.write(' name: "qti_generate_kernel_headers_%s",\n' % header_arch)
f.write(' tools: ["%s"],\n' % headers_install_sh)
f.write(' tools: [\n')
f.write(' "%s",\n' % headers_install_sh)
f.write(' "%s",\n' % unifdef)
f.write(' ],\n')
f.write(' tool_files: [\n')
f.write(' "%s",\n' % kernel_headers_py)
@ -691,6 +698,7 @@ def gen_blueprints(
f.write(' "--arch_syscall_tbl $(location %s) " +\n' % arm_syscall_tbl)
f.write(' "--headers_install $(location %s) " +\n' % headers_install_sh)
f.write(' "--unifdef $(location %s) " +\n' % unifdef)
f.write(' "--include_uapi $(locations %s)",\n' % generic_src)
f.write(' out: ["linux/version.h"] + gen_headers_out_%s,\n' % header_arch)
f.write('}\n')
@ -745,7 +753,7 @@ def headers_diff(old_file, new_file):
def gen_headers(
verbose, header_arch, gen_dir, arch_asm_kbuild, asm_generic_kbuild, module_dir,
old_gen_headers_bp, new_gen_headers_bp, version_makefile,
arch_syscall_tool, arch_syscall_tbl, headers_install, include_uapi,
arch_syscall_tool, arch_syscall_tbl, headers_install, unifdef, include_uapi,
arch_include_uapi, techpack_include_uapi):
"""Generate the kernel headers.
@ -767,6 +775,7 @@ def gen_headers(
arch_syscall_tool: The arch script that generates syscall headers.
arch_syscall_tbl: The arch script that defines syscall vectors.
headers_install: The headers_install tool to process input headers.
unifdef: The unifdef tool used by headers_install.
include_uapi: The list of include/uapi header files.
arch_include_uapi: The list of arch/<arch>/include/uapi header files.
Return:
@ -794,20 +803,20 @@ def gen_headers(
for h in include_uapi:
if not run_headers_install(
verbose, gen_dir, headers_install,
verbose, gen_dir, headers_install, unifdef,
uapi_include_prefix, h):
error_count += 1
for h in arch_include_uapi:
if not run_headers_install(
verbose, gen_dir, headers_install,
verbose, gen_dir, headers_install, unifdef,
arch_uapi_include_prefix, h):
error_count += 1
for h in techpack_include_uapi:
techpack_uapi_include_prefix = os.path.join(h.split('/include/uapi')[0], 'include', 'uapi') + os.sep
if not run_headers_install(
verbose, gen_dir, headers_install,
verbose, gen_dir, headers_install, unifdef,
techpack_uapi_include_prefix, h):
error_count += 1
@ -934,6 +943,10 @@ def main():
'--headers_install',
required=True,
help='The headers_install tool to process input headers.')
parser_headers.add_argument(
'--unifdef',
required=True,
help='The unifdef tool used by headers_install.')
parser_headers.add_argument(
'--include_uapi',
required=True,
@ -982,12 +995,14 @@ def main():
print('arch_syscall_tool [%s]' % args.arch_syscall_tool)
print('arch_syscall_tbl [%s]' % args.arch_syscall_tbl)
print('headers_install [%s]' % args.headers_install)
print('unifdef [%s]' % args.unifdef)
return gen_headers(
args.verbose, args.header_arch, args.gen_dir, args.arch_asm_kbuild,
args.asm_generic_kbuild, module_dir, args.old_gen_headers_bp, args.new_gen_headers_bp,
args.version_makefile, args.arch_syscall_tool, args.arch_syscall_tbl,
args.headers_install, args.include_uapi, args.arch_include_uapi, args.techpack_include_uapi)
args.headers_install, args.unifdef, args.include_uapi, args.arch_include_uapi,
args.techpack_include_uapi)
print('error: unknown mode: %s' % args.mode)
return 1