build-linux and build-gem5 seem to work

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2018-12-09 00:00:00 +00:00
parent 1768421dbd
commit 5e20ba833b
33 changed files with 702 additions and 707 deletions

View File

@@ -6,8 +6,13 @@ import shutil
import common
from shell_helpers import LF
class LinuxComponent(common.Component):
def __init__(self, parser):
class Main(common.BuildCliFunction):
def __init__(self):
super().__init__(
description='''\
Build the Linux kernel.
'''
)
self.add_argument(
'--config', default=[], action='append',
help='''\
@@ -44,48 +49,48 @@ Configure the kernel, but don't build it.
nargs='*'
)
def build(self, **kwargs):
build_dir = self.get_build_dir(**kwargs)
if kwargs['initrd'] or kwargs['initramfs']:
def build(self):
build_dir = self.get_build_dir()
if self.env['initrd'] or self.env['initramfs']:
raise Exception('just trolling, --initrd and --initramfs are broken for now')
os.makedirs(build_dir, exist_ok=True)
tool = 'gcc'
gcc = common.get_toolchain_tool(tool)
gcc = self.get_toolchain_tool(tool)
prefix = gcc[:-len(tool)]
common_args = {
'cwd': common.linux_src_dir,
'cwd': self.env['linux_src_dir'],
}
ccache = shutil.which('ccache')
if ccache is not None:
cc = '{} {}'.format(ccache, gcc)
else:
cc = gcc
if kwargs['verbose']:
if self.env['verbose']:
verbose = ['V=1']
else:
verbose = []
common_make_args = [
'make', LF,
'-j', str(kwargs['nproc']), LF,
'ARCH={}'.format(common.linux_arch), LF,
'-j', str(self.env['nproc']), LF,
'ARCH={}'.format(self.env['linux_arch']), LF,
'CROSS_COMPILE={}'.format(prefix), LF,
'CC={}'.format(cc), LF,
'O={}'.format(build_dir), LF,
] + verbose
if kwargs['custom_config_file'] is not None:
if not os.path.exists(kwargs['custom_config_file']):
raise Exception('config fragment file does not exist: {}'.format(kwargs['custom_config_file']))
base_config_file = kwargs['custom_config_file']
if self.env['custom_config_file'] is not None:
if not os.path.exists(self.env['custom_config_file']):
raise Exception('config fragment file does not exist: {}'.format(self.env['custom_config_file']))
base_config_file = self.env['custom_config_file']
config_fragments = []
else:
base_config_file = os.path.join(common.linux_config_dir, 'buildroot-{}'.format(kwargs['arch']))
base_config_file = os.path.join(self.env['linux_config_dir'], 'buildroot-{}'.format(self.env['arch']))
config_fragments = ['min', 'default']
for i, config_fragment in enumerate(config_fragments):
config_fragments[i] = os.path.join(common.linux_config_dir, config_fragment)
config_fragments.extend(kwargs['config_fragment'])
if kwargs['config'] != []:
config_fragments[i] = os.path.join(self.env['linux_config_dir'], config_fragment)
config_fragments.extend(self.env['config_fragment'])
if self.env['config'] != []:
cli_config_fragment_path = os.path.join(build_dir, 'lkmc_cli_config_fragment')
cli_config_str = '\n'.join(kwargs['config'])
cli_config_str = '\n'.join(self.env['config'])
common.write_string_to_file(cli_config_fragment_path, cli_config_str)
config_fragments.append(cli_config_fragment_path)
self.sh.cp(
@@ -94,12 +99,12 @@ Configure the kernel, but don't build it.
)
self.sh.run_cmd(
[
os.path.join(common.linux_src_dir, 'scripts', 'kconfig', 'merge_config.sh'), LF,
os.path.join(self.env['linux_src_dir'], 'scripts', 'kconfig', 'merge_config.sh'), LF,
'-m', LF,
'-O', build_dir, LF,
os.path.join(build_dir, '.config'), LF,
] +
common.add_newlines(config_fragments)
self.sh.add_newlines(config_fragments)
)
self.sh.run_cmd(
(
@@ -108,11 +113,11 @@ Configure the kernel, but don't build it.
),
**common_args
)
if not kwargs['config_only']:
if not self.env['config_only']:
self.sh.run_cmd(
(
common_make_args +
common.add_newlines(kwargs['extra_make_args'])
self.sh.add_newlines(self.env['extra_make_args'])
),
**common_args
)
@@ -120,7 +125,7 @@ Configure the kernel, but don't build it.
(
common_make_args +
[
'INSTALL_MOD_PATH={}'.format(common.out_rootfs_overlay_dir), LF,
'INSTALL_MOD_PATH={}'.format(self.env['out_rootfs_overlay_dir']), LF,
'modules_install', LF,
]
),
@@ -130,15 +135,8 @@ Configure the kernel, but don't build it.
# TODO Basically all kernel modules also basically leak full host paths. Just terrible. Buildroot deals with that stuff nicely for us.
# common.rmrf()
def get_argparse_args(self):
return {
'description': '''\
Build the Linux kernel.
'''
}
def get_build_dir(self, args):
return common.linux_build_dir
def get_build_dir(self):
return self.env['linux_build_dir']
if __name__ == '__main__':
LinuxComponent().build()
Main().cli()