From 7c7ac82a6b94b92fe4ff7248b0fc28f7c88209e2 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 22 Jan 2019 00:00:00 +0000 Subject: [PATCH] forward _args_given with common options Use _args_given instead of is None everywhere. The problem is as follows: emulator=gem5 implies a non "virt" machine. However, when we call ./build baremetal-gem5, we don't set the emulator to gem5, and so machine=virt. Then when we do a Python call, machine=virt is still set. --- cli_function.py | 11 ++++++++++- common.py | 47 +++++++++++++++++++---------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cli_function.py b/cli_function.py index 07a22b1..bdaa1c6 100755 --- a/cli_function.py +++ b/cli_function.py @@ -155,6 +155,12 @@ class CliFunction: return '\n'.join(str(arg[key]) for key in self._arguments) def _get_args(self, kwargs): + ''' + Resolve default arguments from the config file and CLI param defaults. + + Add an extra _args_given argument which determines if an argument was given or not. + If _args_given is already present in kwargs, preserve it. + ''' args_with_defaults = kwargs.copy() # Add missing args from config file. config_file = None @@ -189,7 +195,10 @@ class CliFunction: args_with_defaults[key] = argument.default else: raise Exception('Value not given for mandatory argument: ' + key) - args_with_defaults['_args_given'] = args_given + if '_args_given' in kwargs: + args_with_defaults['_args_given'] = kwargs['_args_given'] + else: + args_with_defaults['_args_given'] = args_given if 'config_file' in args_with_defaults: del args_with_defaults['config_file'] return args_with_defaults diff --git a/common.py b/common.py index b5544b9..7fea3af 100644 --- a/common.py +++ b/common.py @@ -389,44 +389,27 @@ Valid emulators: {} return os.path.join(*paths) if env['emulator'] in env['emulator_short_to_long_dict']: env['emulator'] = env['emulator_short_to_long_dict'][env['emulator']] - if env['userland_build_id'] is None: + if not env['_args_given']['userland_build_id']: env['userland_build_id'] = env['default_build_id'] - env['userland_build_id_given'] = False - else: - env['userland_build_id_given'] = True - if env['gem5_build_id'] is None: - if env['gem5_worktree'] is not None: + if not env['_args_given']['gem5_build_id']: + if env['_args_given']['gem5_worktree']: env['gem5_build_id'] = env['gem5_worktree'] else: env['gem5_build_id'] = consts['default_build_id'] env['is_arm'] = False if env['arch'] == 'arm': env['armv'] = 7 - env['gem5_arch'] = 'ARM' env['mcpu'] = 'cortex-a15' env['buildroot_toolchain_prefix'] = 'arm-buildroot-linux-uclibcgnueabihf' env['crosstool_ng_toolchain_prefix'] = 'arm-unknown-eabi' env['ubuntu_toolchain_prefix'] = 'arm-linux-gnueabihf' - if env['emulator'] == 'gem5': - if env['machine'] is None: - env['machine'] = 'VExpress_GEM5_V1' - else: - if env['machine'] is None: - env['machine'] = 'virt' env['is_arm'] = True elif env['arch'] == 'aarch64': env['armv'] = 8 - env['gem5_arch'] = 'ARM' env['mcpu'] = 'cortex-a57' env['buildroot_toolchain_prefix'] = 'aarch64-buildroot-linux-uclibc' env['crosstool_ng_toolchain_prefix'] = 'aarch64-unknown-elf' env['ubuntu_toolchain_prefix'] = 'aarch64-linux-gnu' - if env['emulator'] == 'gem5': - if env['machine'] is None: - env['machine'] = 'VExpress_GEM5_V1' - else: - if env['machine'] is None: - env['machine'] = 'virt' env['is_arm'] = True elif env['arch'] == 'x86_64': env['crosstool_ng_toolchain_prefix'] = 'x86_64-unknown-elf' @@ -434,11 +417,19 @@ Valid emulators: {} env['buildroot_toolchain_prefix'] = 'x86_64-buildroot-linux-uclibc' env['ubuntu_toolchain_prefix'] = 'x86_64-linux-gnu' if env['emulator'] == 'gem5': - if env['machine'] is None: + if not env['_args_given']['machine']: env['machine'] = 'TODO' else: - if env['machine'] is None: + if not env['_args_given']['machine']: env['machine'] = 'pc' + if env['is_arm']: + env['gem5_arch'] = 'ARM' + if env['emulator'] == 'gem5': + if not env['_args_given']['machine']: + env['machine'] = 'VExpress_GEM5_V1' + else: + if not env['_args_given']['machine']: + env['machine'] = 'virt' # Buildroot env['buildroot_build_dir'] = join(env['buildroot_out_dir'], 'build', env['buildroot_build_id'], env['arch']) @@ -456,7 +447,7 @@ Valid emulators: {} env['staging_dir'] = join(env['out_dir'], 'staging', env['arch']) env['buildroot_staging_dir'] = join(env['buildroot_build_dir'], 'staging') env['target_dir'] = join(env['buildroot_build_dir'], 'target') - if env['linux_source_dir'] is None: + if not env['_args_given']['linux_source_dir']: env['linux_source_dir'] = os.path.join(consts['submodules_dir'], 'linux') common.extract_vmlinux = os.path.join(env['linux_source_dir'], 'scripts', 'extract-vmlinux') env['linux_buildroot_build_dir'] = join(env['buildroot_build_build_dir'], 'linux-custom') @@ -469,7 +460,7 @@ Valid emulators: {} env['qemu_img_executable'] = join(env['qemu_build_dir'], env['qemu_img_basename']) # gem5 - if env['gem5_build_dir'] is None: + if not env['_args_given']['gem5_build_dir']: env['gem5_build_dir'] = join(env['gem5_out_dir'], env['gem5_build_id'], env['gem5_build_type']) env['gem5_fake_iso'] = join(env['gem5_out_dir'], 'fake.iso') env['gem5_m5term'] = join(env['gem5_build_dir'], 'm5term') @@ -518,7 +509,7 @@ Valid emulators: {} env['gem5_out_dir'] = join(env['out_dir'], 'gem5') # Ports - if env['port_offset'] is None: + if not env['_args_given']['port_offset']: try: env['port_offset'] = int(env['run_id']) except ValueError: @@ -552,7 +543,7 @@ Valid emulators: {} env['run_cmd_file'] = join(env['run_dir'], 'run.sh') # Linux kernl. - if env['linux_build_dir'] is None: + if not env['_args_given']['linux_build_dir']: env['linux_build_dir'] = join(env['out_dir'], 'linux', env['linux_build_id'], env['arch']) env['lkmc_vmlinux'] = join(env['linux_build_dir'], 'vmlinux') if env['arch'] == 'arm': @@ -609,7 +600,7 @@ Valid emulators: {} env['qcow2_file'] = env['buildroot_qcow2_file'] # Image - if env['baremetal'] is None: + if not env['_args_given']['baremetal']: if env['emulator'] == 'gem5': env['image'] = env['vmlinux'] env['disk_image'] = env['rootfs_raw_file'] @@ -679,7 +670,7 @@ Valid emulators: {} return files def get_common_args(self): - return {key:self.env[key] for key in self._common_args} + return {key:self.env[key] for key in self._common_args | {'_args_given'}} def get_stats(self, stat_re=None, stats_file=None): if stat_re is None: