mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-22 17:55: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:
162
build-linux
162
build-linux
@@ -3,86 +3,90 @@
|
||||
import multiprocessing
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import common
|
||||
|
||||
parser = common.get_argparse()
|
||||
common.add_build_arguments(parser)
|
||||
parser.add_argument(
|
||||
'extra_make_args',
|
||||
default=[],
|
||||
metavar='extra-make-args',
|
||||
nargs='*'
|
||||
)
|
||||
args = common.setup(parser)
|
||||
if args.clean:
|
||||
common.rmrf(common.linux_build_dir)
|
||||
else:
|
||||
if not common.dry_run:
|
||||
start_time = time.time()
|
||||
os.makedirs(common.linux_build_dir, exist_ok=True)
|
||||
shutil.copy2(
|
||||
os.path.join(common.linux_config_dir, 'buildroot-{}'.format(args.arch)),
|
||||
os.path.join(common.linux_build_dir, '.config'),
|
||||
)
|
||||
tool = 'gcc'
|
||||
gcc = common.get_toolchain_tool(tool)
|
||||
prefix = gcc[:-len(tool)]
|
||||
common_args = {
|
||||
'cwd': common.linux_src_dir,
|
||||
}
|
||||
ccache = shutil.which('ccache')
|
||||
if ccache is not None:
|
||||
cc = '{} {}'.format(ccache, gcc)
|
||||
else:
|
||||
cc = gcc
|
||||
common_make_args = [
|
||||
'ARCH={}'.format(common.linux_arch),
|
||||
'CROSS_COMPILE={}'.format(prefix),
|
||||
'CC={}'.format(cc),
|
||||
'O={}'.format(common.linux_build_dir),
|
||||
]
|
||||
if args.verbose:
|
||||
verbose = ['V=1']
|
||||
else:
|
||||
verbose = []
|
||||
assert common.run_cmd(
|
||||
[
|
||||
os.path.join(common.linux_src_dir, 'scripts', 'kconfig', 'merge_config.sh'),
|
||||
'-m',
|
||||
'-O', common.linux_build_dir,
|
||||
os.path.join(common.linux_build_dir, '.config'),
|
||||
os.path.join(common.linux_config_dir, 'min'),
|
||||
os.path.join(common.linux_config_dir, 'default'),
|
||||
],
|
||||
) == 0
|
||||
assert common.run_cmd(
|
||||
(
|
||||
class LinuxComponent(common.Component):
|
||||
def add_parser_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'extra_make_args',
|
||||
default=[],
|
||||
metavar='extra-make-args',
|
||||
nargs='*'
|
||||
)
|
||||
|
||||
def do_build(self, args):
|
||||
build_dir = self.get_build_dir(args)
|
||||
os.makedirs(build_dir, exist_ok=True)
|
||||
common.cp(
|
||||
os.path.join(common.linux_config_dir, 'buildroot-{}'.format(args.arch)),
|
||||
os.path.join(build_dir, '.config'),
|
||||
)
|
||||
tool = 'gcc'
|
||||
gcc = common.get_toolchain_tool(tool)
|
||||
prefix = gcc[:-len(tool)]
|
||||
common_args = {
|
||||
'cwd': common.linux_src_dir,
|
||||
}
|
||||
ccache = shutil.which('ccache')
|
||||
if ccache is not None:
|
||||
cc = '{} {}'.format(ccache, gcc)
|
||||
else:
|
||||
cc = gcc
|
||||
common_make_args = [
|
||||
'ARCH={}'.format(common.linux_arch),
|
||||
'CROSS_COMPILE={}'.format(prefix),
|
||||
'CC={}'.format(cc),
|
||||
'O={}'.format(build_dir),
|
||||
]
|
||||
if args.verbose:
|
||||
verbose = ['V=1']
|
||||
else:
|
||||
verbose = []
|
||||
assert common.run_cmd(
|
||||
[
|
||||
'make',
|
||||
'-j', str(multiprocessing.cpu_count()),
|
||||
] +
|
||||
common_make_args +
|
||||
[
|
||||
'olddefconfig',
|
||||
]
|
||||
),
|
||||
**common_args,
|
||||
) == 0
|
||||
assert common.run_cmd(
|
||||
(
|
||||
[
|
||||
'make',
|
||||
'-j', str(multiprocessing.cpu_count()),
|
||||
] +
|
||||
common_make_args +
|
||||
verbose +
|
||||
args.extra_make_args
|
||||
),
|
||||
**common_args,
|
||||
) == 0
|
||||
if not common.dry_run:
|
||||
end_time = time.time()
|
||||
common.print_time(end_time - start_time)
|
||||
os.path.join(common.linux_src_dir, 'scripts', 'kconfig', 'merge_config.sh'),
|
||||
'-m',
|
||||
'-O', build_dir,
|
||||
os.path.join(build_dir, '.config'),
|
||||
os.path.join(common.linux_config_dir, 'min'),
|
||||
os.path.join(common.linux_config_dir, 'default'),
|
||||
],
|
||||
) == 0
|
||||
assert common.run_cmd(
|
||||
(
|
||||
[
|
||||
'make',
|
||||
'-j', str(multiprocessing.cpu_count()),
|
||||
] +
|
||||
common_make_args +
|
||||
[
|
||||
'olddefconfig',
|
||||
]
|
||||
),
|
||||
**common_args,
|
||||
) == 0
|
||||
assert common.run_cmd(
|
||||
(
|
||||
[
|
||||
'make',
|
||||
'-j', str(multiprocessing.cpu_count()),
|
||||
] +
|
||||
common_make_args +
|
||||
verbose +
|
||||
args.extra_make_args
|
||||
),
|
||||
**common_args,
|
||||
) == 0
|
||||
|
||||
def get_argparse_args(self):
|
||||
return {
|
||||
'description': '''\
|
||||
Build the Linux kernel.
|
||||
'''
|
||||
}
|
||||
|
||||
def get_build_dir(self, args):
|
||||
return common.linux_build_dir
|
||||
|
||||
LinuxComponent().build()
|
||||
|
||||
Reference in New Issue
Block a user