mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
common: create a Component class to factor out builds
Not yet finished factoring, but half way there, do for all build-
This commit is contained in:
105
build-userland
105
build-userland
@@ -5,65 +5,68 @@ import os
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import common
|
||||
|
||||
parser = common.get_argparse(argparse_args={
|
||||
'description': 'Build our compiled userland examples',
|
||||
})
|
||||
common.add_build_arguments(parser)
|
||||
parser.add_argument(
|
||||
'--has-package',
|
||||
action='append',
|
||||
default=[],
|
||||
help='''\
|
||||
class UserlandComponent(common.Component):
|
||||
def add_parser_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--has-package',
|
||||
action='append',
|
||||
default=[],
|
||||
help='''\
|
||||
Indicate that a given package is present in the root filesystem, which
|
||||
allows us to build examples that rely on it.
|
||||
''',
|
||||
)
|
||||
parser.add_argument(
|
||||
'targets',
|
||||
default=[],
|
||||
help='''\
|
||||
)
|
||||
parser.add_argument(
|
||||
'targets',
|
||||
default=[],
|
||||
help='''\
|
||||
Build only the given userland programs.
|
||||
Default: build all examples that have their package dependencies met.
|
||||
For example, an OpenBLAS example can only be built if the target root filesystem
|
||||
has the OpenBLAS libraries and headers installed.
|
||||
''',
|
||||
metavar='programs',
|
||||
nargs='*',
|
||||
)
|
||||
args = common.setup(parser)
|
||||
if args.clean:
|
||||
common.rmrf(common.userland_build_dir)
|
||||
else:
|
||||
start_time = time.time()
|
||||
os.makedirs(common.userland_build_dir, exist_ok=True)
|
||||
allowed_toolchains = ['buildroot']
|
||||
cc = common.get_toolchain_tool('gcc', allowed_toolchains=allowed_toolchains)
|
||||
cxx = common.get_toolchain_tool('g++', allowed_toolchains=allowed_toolchains)
|
||||
assert common.run_cmd(
|
||||
(
|
||||
[
|
||||
'make',
|
||||
'-j', str(multiprocessing.cpu_count()),
|
||||
'CC={}'.format(cc),
|
||||
'CXX={}'.format(cxx),
|
||||
'PKG_CONFIG={}'.format(common.buildroot_pkg_config),
|
||||
'STAGING_DIR={}'.format(common.buildroot_staging_dir),
|
||||
'OUT_DIR={}'.format(common.userland_build_dir),
|
||||
] +
|
||||
['HAS_{}=y'.format(package.upper()) for package in args.has_package] +
|
||||
[os.path.join(common.userland_build_dir, os.path.splitext(os.path.split(target)[1])[0]) + common.executable_ext for target in args.targets]
|
||||
),
|
||||
cwd=common.userland_src_dir,
|
||||
extra_paths=[common.ccache_dir],
|
||||
) == 0
|
||||
common.copy_dir_if_update_non_recursive(
|
||||
srcdir=common.userland_build_dir,
|
||||
destdir=common.out_rootfs_overlay_dir,
|
||||
filter_ext=common.executable_ext,
|
||||
)
|
||||
end_time = time.time()
|
||||
common.print_time(end_time - start_time)
|
||||
metavar='programs',
|
||||
nargs='*',
|
||||
)
|
||||
|
||||
def do_build(self, args):
|
||||
build_dir = self.get_build_dir(args)
|
||||
os.makedirs(build_dir, exist_ok=True)
|
||||
allowed_toolchains = ['buildroot']
|
||||
cc = common.get_toolchain_tool('gcc', allowed_toolchains=allowed_toolchains)
|
||||
cxx = common.get_toolchain_tool('g++', allowed_toolchains=allowed_toolchains)
|
||||
assert common.run_cmd(
|
||||
(
|
||||
[
|
||||
'make',
|
||||
'-j', str(multiprocessing.cpu_count()),
|
||||
'CC={}'.format(cc),
|
||||
'CXX={}'.format(cxx),
|
||||
'PKG_CONFIG={}'.format(common.buildroot_pkg_config),
|
||||
'STAGING_DIR={}'.format(common.buildroot_staging_dir),
|
||||
'OUT_DIR={}'.format(build_dir),
|
||||
] +
|
||||
['HAS_{}=y'.format(package.upper()) for package in args.has_package] +
|
||||
[os.path.join(build_dir, os.path.splitext(os.path.split(target)[1])[0]) + common.executable_ext for target in args.targets]
|
||||
),
|
||||
cwd=common.userland_src_dir,
|
||||
extra_paths=[common.ccache_dir],
|
||||
) == 0
|
||||
common.copy_dir_if_update_non_recursive(
|
||||
srcdir=build_dir,
|
||||
destdir=common.out_rootfs_overlay_dir,
|
||||
filter_ext=common.executable_ext,
|
||||
)
|
||||
|
||||
def get_argparse_args(self):
|
||||
return {
|
||||
'description': 'Build our compiled userland examples',
|
||||
}
|
||||
|
||||
def get_build_dir(self, args):
|
||||
return common.userland_build_dir
|
||||
|
||||
UserlandComponent().build()
|
||||
|
||||
Reference in New Issue
Block a user