From 6d29c9240cd831e159f73d7e927ba4d0318a3280 Mon Sep 17 00:00:00 2001 From: Bill Peckham Date: Tue, 26 Jan 2021 13:06:41 -0800 Subject: [PATCH] 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 Signed-off-by: Shadab Naseem Signed-off-by: Srinivasarao P --- Android.bp | 4 ++-- gen_headers_arm.bp | 6 +++++- gen_headers_arm64.bp | 6 +++++- kernel_headers.py | 31 +++++++++++++++++++++++-------- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Android.bp b/Android.bp index 1fd921a0e88c..3d5382bfbd47 100644 --- a/Android.bp +++ b/Android.bp @@ -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 { diff --git a/gen_headers_arm.bp b/gen_headers_arm.bp index e8678343488b..6aa574ba1e65 100644 --- a/gen_headers_arm.bp +++ b/gen_headers_arm.bp @@ -1019,7 +1019,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", @@ -1044,6 +1047,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, } diff --git a/gen_headers_arm64.bp b/gen_headers_arm64.bp index 8b884b3ed6ad..b8ff10a8f030 100644 --- a/gen_headers_arm64.bp +++ b/gen_headers_arm64.bp @@ -1013,7 +1013,10 @@ genrule { genrule { name: "qti_generate_kernel_headers_arm64", - tools: ["headers_install.sh"], + tools: [ + "headers_install.sh", + "unifdef", + ], tool_files: [ "kernel_headers.py", ], @@ -1035,6 +1038,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, } diff --git a/kernel_headers.py b/kernel_headers.py index 7ca19c12e281..3397308f8697 100644 --- a/kernel_headers.py +++ b/kernel_headers.py @@ -310,7 +310,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 @@ -325,6 +325,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: @@ -344,7 +345,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)) @@ -511,6 +514,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' @@ -658,7 +662,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) @@ -692,6 +699,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') @@ -746,7 +754,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. @@ -768,6 +776,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//include/uapi header files. Return: @@ -795,20 +804,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 @@ -935,6 +944,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, @@ -983,12 +996,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