From 9581fa201c61f777104efaca11cc38f38974181c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Wed, 13 Mar 2019 00:00:02 +0000 Subject: [PATCH] userland: in-tree build and clean --- build-userland | 28 ++++++++++++++++++++++++++-- common.py | 10 +++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/build-userland b/build-userland index c532c57..7490906 100755 --- a/build-userland +++ b/build-userland @@ -26,6 +26,15 @@ Build our compiled userland examples. help='''\ Indicate that a given package is present in the root filesystem, which allows us to build examples that rely on it. +''', + ) + self.add_argument( + '--in-tree', + default=False, + help='''\ +Build in-tree, i.e. place outputs next to source files. +Mostly useful when compiling with the host toolchain to conveniently run +the output files. ''', ) self.add_argument( @@ -185,7 +194,7 @@ Default: build all examples that have their package dependencies met, e.g.: dirpath_relative_root_components[1] == self.env['arch'] ): out_dir = os.path.join( - self.env['userland_build_dir'], + build_dir, dirpath_relative_root ) os.makedirs(out_dir, exist_ok=True) @@ -255,8 +264,23 @@ Default: build all examples that have their package dependencies met, e.g.: ) return 0 + def clean(self): + build_dir = self.get_build_dir() + if self.env['in_tree']: + for path, dirnames, filenames in os.walk(build_dir): + filenames.sort() + dirnames.sort() + for filename in filenames: + if os.path.splitext(filename)[1] in self.env['userland_out_exts']: + self.sh.rmrf(os.path.join(path, filename)) + else: + self.sh.rmrf(build_dir) + def get_build_dir(self): - return self.env['userland_build_dir'] + if self.env['in_tree']: + return self.env['userland_source_dir'] + else: + return self.env['userland_build_dir'] if __name__ == '__main__': Main().cli() diff --git a/common.py b/common.py index 38c41e5..27d8c6c 100644 --- a/common.py +++ b/common.py @@ -95,14 +95,18 @@ consts['github_repo_id'] = 'cirosantilli/linux-kernel-module-cheat' consts['asm_ext'] = '.S' consts['c_ext'] = '.c' consts['cxx_ext'] = '.cpp' +consts['header_ext'] = '.h' +consts['kernel_module_ext'] = '.ko' +consts['obj_ext'] = '.o' consts['userland_in_exts'] = [ consts['asm_ext'], consts['c_ext'], consts['cxx_ext'], ] -consts['header_ext'] = '.h' -consts['kernel_module_ext'] = '.ko' -consts['obj_ext'] = '.o' +consts['userland_out_exts'] = [ + consts['userland_build_ext'], + consts['obj_ext'], +] consts['config_file'] = os.path.join(consts['data_dir'], 'config.py') consts['magic_fail_string'] = b'lkmc_test_fail' consts['baremetal_lib_basename'] = 'lib'