def get_parsed_kunitconfig( build_dir: str, kunitconfig_paths: Optional[List[str]] = None) -> kunit_config.Kconfig: if not kunitconfig_paths: path = get_kunitconfig_path(build_dir) if not os.path.exists(path): shutil.copyfile(DEFAULT_KUNITCONFIG_PATH, path) return kunit_config.parse_file(path) merged = kunit_config.Kconfig() for path in kunitconfig_paths: if os.path.isdir(path): path = os.path.join(path, KUNITCONFIG_PATH) if not os.path.exists(path): raise ConfigError(f'Specified kunitconfig ({path}) does not exist') partial = kunit_config.parse_file(path) diff = merged.conflicting_options(partial) if diff: diff_str = '\n\n'.join(f'{a}\n vs from {path}\n{b}' for a, b in diff) raise ConfigError( f'Multiple values specified for {len(diff)} options in kunitconfig:\n{diff_str}' ) merged.merge_in_entries(partial) return merged
def _kunitconfig_changed(self, build_dir: str) -> bool: old_path = get_old_kunitconfig_path(build_dir) if not os.path.exists(old_path): return True old_kconfig = kunit_config.parse_file(old_path) return old_kconfig.entries() != self._kconfig.entries()
def test_read_from_file(self): kconfig_path = test_data_path('test_read_from_file.kconfig') kconfig = kunit_config.parse_file(kconfig_path) expected_kconfig = kunit_config.Kconfig() expected_kconfig.add_entry('UML', 'y') expected_kconfig.add_entry('MMU', 'y') expected_kconfig.add_entry('TEST', 'y') expected_kconfig.add_entry('EXAMPLE_TEST', 'y') expected_kconfig.add_entry('MK8', 'n') self.assertEqual(kconfig, expected_kconfig)
def validate_config(self, build_dir) -> bool: kconfig_path = get_kconfig_path(build_dir) validated_kconfig = kunit_config.parse_file(kconfig_path) if self._kconfig.is_subset_of(validated_kconfig): return True invalid = self._kconfig.entries() - validated_kconfig.entries() message = 'Not all Kconfig options selected in kunitconfig were in the generated .config.\n' \ 'This is probably due to unsatisfied dependencies.\n' \ 'Missing: ' + ', '.join([str(e) for e in invalid]) if self._arch == 'um': message += '\nNote: many Kconfig options aren\'t available on UML. You can try running ' \ 'on a different architecture with something like "--arch=x86_64".' logging.error(message) return False
def test_write_to_file(self): kconfig_path = os.path.join(test_tmpdir, '.config') expected_kconfig = kunit_config.Kconfig() expected_kconfig.add_entry('UML', 'y') expected_kconfig.add_entry('MMU', 'y') expected_kconfig.add_entry('TEST', 'y') expected_kconfig.add_entry('EXAMPLE_TEST', 'y') expected_kconfig.add_entry('MK8', 'n') expected_kconfig.write_to_file(kconfig_path) actual_kconfig = kunit_config.parse_file(kconfig_path) self.assertEqual(actual_kconfig, expected_kconfig)
def build_reconfig(self, build_dir, make_options) -> bool: """Creates a new .config if it is not a subset of the .kunitconfig.""" kconfig_path = get_kconfig_path(build_dir) if not os.path.exists(kconfig_path): print('Generating .config ...') return self.build_config(build_dir, make_options) existing_kconfig = kunit_config.parse_file(kconfig_path) self._ops.make_arch_qemuconfig(self._kconfig) if self._kconfig.is_subset_of( existing_kconfig) and not self._kunitconfig_changed(build_dir): return True print('Regenerating .config ...') os.remove(kconfig_path) return self.build_config(build_dir, make_options)
def __init__(self, build_dir: str, load_config=True, kunitconfig_path='', kconfig_add: Optional[List[str]] = None, arch=None, cross_compile=None, qemu_config_path=None) -> None: signal.signal(signal.SIGINT, self.signal_handler) if qemu_config_path: self._arch, self._ops = get_source_tree_ops_from_qemu_config( qemu_config_path, cross_compile) else: self._arch = 'um' if arch is None else arch self._ops = get_source_tree_ops(self._arch, cross_compile) if not load_config: return if kunitconfig_path: if os.path.isdir(kunitconfig_path): kunitconfig_path = os.path.join(kunitconfig_path, KUNITCONFIG_PATH) if not os.path.exists(kunitconfig_path): raise ConfigError( f'Specified kunitconfig ({kunitconfig_path}) does not exist' ) else: kunitconfig_path = get_kunitconfig_path(build_dir) if not os.path.exists(kunitconfig_path): shutil.copyfile(DEFAULT_KUNITCONFIG_PATH, kunitconfig_path) self._kconfig = kunit_config.parse_file(kunitconfig_path) if kconfig_add: kconfig = kunit_config.parse_from_string('\n'.join(kconfig_add)) self._kconfig.merge_in_entries(kconfig)
def make_arch_config( self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig: kconfig = kunit_config.parse_file(UML_KCONFIG_PATH) kconfig.merge_in_entries(base_kunitconfig) return kconfig