diff options
author | Guillaume Tucker <guillaume.tucker@collabora.com> | 2019-04-24 16:09:06 +0100 |
---|---|---|
committer | Guillaume Tucker <guillaume.tucker@collabora.com> | 2019-05-03 12:59:46 +0100 |
commit | 512fdcddca2d7775c277c0cf122c6cd56ffa532f (patch) | |
tree | 6642dcaffbede9eaf0cc2a8c7ae8f23edd86883e | |
parent | 7dbff1eef655856e75e69ab4df455477cc4d11be (diff) |
kci_build: add --output option for kernel builds
Add the --output option for build_kernel and install_kernel commands
to specify where the binaries should be created. By default, the same
directory as before is used in kdir/build.
Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
-rwxr-xr-x | kci_build | 15 | ||||
-rw-r--r-- | kernelci/build.py | 68 |
2 files changed, 45 insertions, 38 deletions
@@ -127,6 +127,11 @@ class Args(object): 'action': 'store_true', } + output = { + 'name': '--output', + 'help': "Path the output directory", + } + # ----------------------------------------------------------------------------- # Commands @@ -160,7 +165,6 @@ class Command(object): self._parser.add_argument(arg_name, **kw) -# ToDo: filter using arch, compiler and defconfig class cmd_list_configs(Command): help = "List the build configurations" @@ -344,20 +348,21 @@ class cmd_list_kernel_configs(Command): class cmd_build_kernel(Command): help = "Build a kernel" args = [Args.build_env, Args.arch, Args.kdir] - opt_args = [Args.defconfig, Args.j, Args.verbose] + opt_args = [Args.defconfig, Args.j, Args.verbose, Args.output] def __call__(self, configs, args): build_env = configs['build_environments'][args.build_env] return kernelci.build.build_kernel( build_env, args.kdir, args.arch, args.defconfig, args.j, - args.verbose) + args.verbose, args.output) class cmd_install_kernel(Command): help = "Install the kernel binaries and build.json locally" args = [Args.kdir] opt_args = [Args.config, Args.tree_name, Args.tree_url, Args.branch, - Args.commit, Args.describe, Args.describe_verbose] + Args.commit, Args.describe, Args.describe_verbose, + Args.output] def __call__(self, configs, args): if args.config: @@ -379,7 +384,7 @@ or return False return kernelci.build.install_kernel( args.kdir, tree_name, tree_url, branch, args.commit, args.describe, - args.describe_verbose) + args.describe_verbose, args.output) class cmd_push_kernel(Command): diff --git a/kernelci/build.py b/kernelci/build.py index 2351aad..ed85638 100644 --- a/kernelci/build.py +++ b/kernelci/build.py @@ -278,6 +278,8 @@ def _run_make(kdir, arch, target=None, jopt=None, silent=True, cc='gcc', if opts: args += ['='.join([k, v]) for k, v in opts.iteritems()] + args += ['-C{}'.format(kdir)] + if jopt: args.append('-j{}'.format(jopt)) @@ -300,7 +302,7 @@ def _run_make(kdir, arch, target=None, jopt=None, silent=True, cc='gcc', args.append('CC={}'.format(cc)) if output: - args.append('O={}'.format(output)) + args.append('O={}'.format(os.path.relpath(output, kdir))) if target: args.append(target) @@ -308,17 +310,14 @@ def _run_make(kdir, arch, target=None, jopt=None, silent=True, cc='gcc', cmd = ' '.join(args) print(cmd) if log_file: - log_file_path = os.path.join(kdir, output, log_file) - open(log_file_path, 'a').write("#\n# {}\n#\n".format(cmd)) + open(log_file, 'a').write("#\n# {}\n#\n".format(cmd)) cmd = "/bin/bash -c '(set -o pipefail; {} 2>&1 | tee -a {})'".format( cmd, log_file) - cmd = "cd {} && {}".format(kdir, cmd) return shell_cmd(cmd, True) def _make_defconfig(defconfig, kwargs, fragments): - kdir, output = (kwargs.get(k) for k in ('kdir', 'output')) - kdir_output = os.path.join(kdir, output) + kdir, output_path = (kwargs.get(k) for k in ('kdir', 'output')) result = True tmpfile_fd, tmpfile_path = tempfile.mkstemp(prefix='kconfig-') @@ -342,17 +341,18 @@ def _make_defconfig(defconfig, kwargs, fragments): if result and fragments: kconfig_frag_name = 'frag.config' - kconfig_frag = os.path.join(kdir_output, kconfig_frag_name) + kconfig_frag = os.path.join(output_path, kconfig_frag_name) shutil.copy(tmpfile_path, kconfig_frag) os.chmod(kconfig_frag, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) + rel_path = os.path.relpath(output_path, kdir) cmd = """\ cd {kdir} export ARCH={arch} scripts/kconfig/merge_config.sh -O {output} '{base}' '{frag}' > /dev/null 2>&1 -""".format(kdir=kdir, arch=kwargs['arch'], output=output, - base=os.path.join(output, '.config'), - frag=os.path.join(output, kconfig_frag_name)) +""".format(kdir=kdir, arch=kwargs['arch'],output=rel_path, + base=os.path.join(rel_path, '.config'), + frag=os.path.join(rel_path, kconfig_frag_name)) print(cmd.strip()) result = shell_cmd(cmd, True) @@ -363,19 +363,20 @@ scripts/kconfig/merge_config.sh -O {output} '{base}' '{frag}' > /dev/null 2>&1 def build_kernel(build_env, kdir, arch, defconfig=None, jopt=None, - verbose=False, output='build', mod_path='_modules_'): + verbose=False, output_path=None, mod_path='_modules_'): cc = build_env.cc cross_compile = build_env.get_cross_compile(arch) or None use_ccache = shell_cmd("which ccache > /dev/null", True) - kdir_output = os.path.join(kdir, output) - build_log = 'build.log' - log_file = os.path.join(kdir_output, build_log) - dot_config = os.path.join(kdir_output, '.config') target = MAKE_TARGETS.get(arch) if jopt is None: jopt = int(shell_cmd("nproc")) + 2 - if not os.path.exists(kdir_output): - os.mkdir(kdir_output) + if not output_path: + output_path = os.path.join(kdir, 'build') + if not os.path.exists(output_path): + os.mkdir(output_path) + build_log = 'build.log' + log_file = os.path.join(output_path, build_log) + dot_config = os.path.join(output_path, '.config') if os.path.exists(log_file): os.unlink(log_file) @@ -389,9 +390,9 @@ def build_kernel(build_env, kdir, arch, defconfig=None, jopt=None, 'cc': cc, 'cross_compile': cross_compile, 'use_ccache': use_ccache, - 'output': output, + 'output': output_path, 'silent': not verbose, - 'log_file': build_log, + 'log_file': log_file, 'opts': opts, } @@ -413,7 +414,7 @@ def build_kernel(build_env, kdir, arch, defconfig=None, jopt=None, build_time = time.time() - start_time if result and mods and mod_path: - abs_mod_path = os.path.join(kdir_output, mod_path) + abs_mod_path = os.path.join(output_path, mod_path) if os.path.exists(abs_mod_path): shutil.rmtree(abs_mod_path) os.makedirs(abs_mod_path) @@ -449,23 +450,24 @@ def build_kernel(build_env, kdir, arch, defconfig=None, jopt=None, 'defconfig_full': '+'.join([defconfig_target] + fragments), }) - vmlinux_file = os.path.join(kdir_output, 'vmlinux') + vmlinux_file = os.path.join(output_path, 'vmlinux') if os.path.isfile(vmlinux_file): vmlinux_meta = kernelci.elf.read(vmlinux_file) bmeta.update(vmlinux_meta) bmeta['vmlinux_file_size'] = os.stat(vmlinux_file).st_size - with open(os.path.join(kdir_output, 'bmeta.json'), 'w') as json_file: + with open(os.path.join(output_path, 'bmeta.json'), 'w') as json_file: json.dump(bmeta, json_file, indent=4, sort_keys=True) return result -def install_kernel(kdir, tree_name, tree_url, git_branch, - git_commit=None, describe=None, describe_v=None, - output='build', install='_install_', mod_path='_modules_'): - kdir_output = os.path.join(kdir, output) +def install_kernel(kdir, tree_name, tree_url, git_branch, git_commit=None, + describe=None, describe_v=None, output_path=None, + install='_install_', mod_path='_modules_'): install_path = os.path.join(kdir, install) + if not output_path: + output_path = os.path.join(kdir, 'build') if not git_commit: git_commit = head_commit(kdir) if not describe: @@ -477,10 +479,10 @@ def install_kernel(kdir, tree_name, tree_url, git_branch, shutil.rmtree(install_path) os.makedirs(install_path) - with open(os.path.join(kdir_output, 'bmeta.json')) as json_file: + with open(os.path.join(output_path, 'bmeta.json')) as json_file: bmeta = json.load(json_file) - system_map = os.path.join(kdir, output, 'System.map') + system_map = os.path.join(output_path, 'System.map') if os.path.exists(system_map): virt_text = shell_cmd('grep " _text" {}'.format(system_map)).split()[0] text_offset = int(virt_text, 16) & (1 << 30)-1 # phys: cap at 1G @@ -488,19 +490,19 @@ def install_kernel(kdir, tree_name, tree_url, git_branch, else: text_offset = None - dot_config = os.path.join(kdir_output, '.config') + dot_config = os.path.join(output_path, '.config') dot_config_installed = os.path.join(install_path, 'kernel.config') shutil.copy(dot_config, dot_config_installed) - build_log = os.path.join(kdir_output, 'build.log') + build_log = os.path.join(output_path, 'build.log') shutil.copy(build_log, install_path) - frags = os.path.join(kdir_output, 'frag.config') + frags = os.path.join(output_path, 'frag.config') if os.path.exists(frags): shutil.copy(frags, install_path) arch = bmeta['arch'] - boot_dir = os.path.join(kdir, output, 'arch', arch, 'boot') + boot_dir = os.path.join(output_path, 'arch', arch, 'boot') kimage_names = KERNEL_IMAGE_NAMES[arch] kimages = [] kimage_file = None @@ -532,7 +534,7 @@ def install_kernel(kdir, tree_name, tree_url, git_branch, modules_tarball = None if mod_path: - abs_mod_path = os.path.join(kdir_output, mod_path) + abs_mod_path = os.path.join(output_path, mod_path) if os.path.exists(abs_mod_path): modules_tarball = 'modules.tar.xz' modules_tarball_path = os.path.join(install_path, modules_tarball) |