userland: in-tree build and clean

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-03-13 00:00:02 +00:00
parent e32dcb85e9
commit 9581fa201c
2 changed files with 33 additions and 5 deletions

View File

@@ -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()

View File

@@ -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'