def main(): parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument( "--header-path", metavar="HEADER_FILE", default=DEFAULT_HEADER_PATH, help="Path for the generated header file (default: {})" .format(DEFAULT_HEADER_PATH)) parser.add_argument( "--sync-deps", dest="sync_deps_path", metavar="OUTPUT_DIR", nargs="?", const=DEFAULT_SYNC_DEPS_PATH, help="Enable generation of build dependency information for " "incremental builds, optionally specifying the output path " "(default: {})".format(DEFAULT_SYNC_DEPS_PATH)) parser.add_argument( "--config-out", dest="config_path", metavar="CONFIG_FILE", help="Write the configuration to the specified filename. " "This is useful if you include .config files in Makefiles, as " "the generated configuration file will be a full .config file " "even if .config is outdated. The generated configuration " "matches what olddefconfig would produce. If you use " "--sync-deps, you can include deps/auto.conf instead. " "--config-out is meant for cases where incremental build " "information isn't needed.") parser.add_argument( "kconfig_filename", metavar="KCONFIG_FILENAME", nargs="?", default="Kconfig", help="Top-level Kconfig file (default: Kconfig)") parser.add_argument( "--defconfig-file", dest="defconfig_file", metavar="DEFCONFIG_FILENAME", nargs="?", default=".config", help="defconfig") args = parser.parse_args() kconf = kconfiglib.Kconfig(args.kconfig_filename) kconf.load_config(args.defconfig_file) kconf.write_autoconf(args.header_path) if args.sync_deps_path is not None: kconf.sync_deps(args.sync_deps_path) if args.config_path is not None: kconf.write_config(args.config_path)
def report(): # Returns a message (string) giving the locations of all references to # undefined Kconfig symbols within the Kconfig files, or the empty string # if there are no references to undefined symbols. # # Note: This function is called directly during CI. kconf = kconfiglib.Kconfig() undef_msg = "" for name, sym in kconf.syms.items(): # - sym.nodes empty means the symbol is undefined (has no definition # locations) # # - Due to Kconfig internals, numbers show up as undefined Kconfig # symbols, but shouldn't be flagged # # - The MODULES symbol always exists but is unused in uGelis if not sym.nodes and not is_num(name) and name != "MODULES": undef_msg += ref_locations_str(sym) if undef_msg: return "Error: Found references to undefined Kconfig symbols:\n" \ + undef_msg return ""
def run(self): self.prepare() # Look up Kconfig files relative to ZEPHYR_BASE os.environ["srctree"] = zephyr_path # Parse the entire Kconfig tree, to make sure we see all symbols os.environ["SOC_DIR"] = "soc/" os.environ["BOARD_DIR"] = "boards/*/*" os.environ["ARCH"] = "*" # Enable strict Kconfig mode in Kconfiglib, which assumes there's just a # single Kconfig tree and warns for all references to undefined symbols os.environ["KCONFIG_STRICT"] = "y" undef_ref_warnings = [] for warning in kconfiglib.Kconfig().warnings: if "undefined symbol" in warning: undef_ref_warnings.append(warning) # Generating multiple JUnit <failure>s would be neater, but Shippable only # seems to display the first one if undef_ref_warnings: self.case.result = Failure("undefined Kconfig symbols", "failure") self.case.result._elem.text = "\n\n\n".join(undef_ref_warnings)
def main(argv=None): if argv is None: argv = sys.argv[1:] # Instantiate cmd options parser parser = argparse.ArgumentParser( description='Interactive Kconfig configuration editor') parser.add_argument('--kconfig', metavar='FILE', type=str, default='Kconfig', help='path to root Kconfig file') parser.add_argument('--config', metavar='FILE', type=str, help='path to .config file to load') args = parser.parse_args(argv) kconfig_path = args.kconfig config_path = args.config # Verify that Kconfig file exists if not os.path.isfile(kconfig_path): raise RuntimeError('\'{}\': no such file'.format(kconfig_path)) # Parse Kconfig files kconf = kconfiglib.Kconfig(filename=kconfig_path) mc = MenuConfig(kconf) # If config file was specified, load it if config_path: mc.open_config(config_path) tk.mainloop()
def find_experimental_symbols(logs: List[str]) -> Dict[str, Set[str]]: """Search through a list of files for experimental symbols. In cases where experimental symbols are found, but the folder in which they were found does not contain a /zephyr/.config file, the symbols are ignored. Args: logs: List of full path to all build.log files. Return: A mapping from each SoC to a set of symbols that trigger the experimental warning when built with that SoC. """ socs = {} for log in logs: path = Path(log) content = path.read_text() matches = re.findall(r"Experimental symbol ([A-Z0-9_]+) is enabled", content) if matches: config_path = path.parent / "zephyr" / ".config" if not config_path.exists(): logger.warning( f"path '{config_path.as_posix()}' does not exist") continue kconf = kconfiglib.Kconfig(filename=config_path) soc = soc_from_kconfig(kconf) for symbol in matches: symbol = "CONFIG_" + symbol if soc not in socs: socs[soc] = set() socs[soc].add(symbol) return socs
def run_kconfig_undef_ref_check(tc, commit_range): # Look up Kconfig files relative to ZEPHYR_BASE os.environ["srctree"] = repository_path # Parse the entire Kconfig tree, to make sure we see all symbols os.environ["BOARD_DIR"] = "boards/*/*" os.environ["ARCH"] = "*" # Enable strict Kconfig mode in Kconfiglib, which assumes there's just a # single Kconfig tree and warns for all references to undefined symbols os.environ["KCONFIG_STRICT"] = "y" undef_ref_warnings = [] for warning in kconfiglib.Kconfig().warnings: if "undefined symbol" in warning: undef_ref_warnings.append(warning) # Generating multiple JUnit <failure>s would be neater, but Shippable only # seems to display the first one if undef_ref_warnings: failure = ET.SubElement(tc, "failure", type="failure", message="undefined Kconfig symbols") failure.text = "\n\n\n".join(undef_ref_warnings) return 1 return 0
def defconfig(config_file): if os.path.exists(config_file): os.remove(config_file) kconf = kconfiglib.Kconfig("Kconfig") if os.path.exists(config_file): kconf.load_config(filename=config_file) kconf.write_config(filename=config_file)
def main(): parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument( "--kconfig", metavar="KCONFIG_FILENAME", dest="kconfig", default="Kconfig", help="top-level Kconfig file (default: Kconfig)") parser.add_argument( "config", metavar="CONFIG_FILENAME", help="configuration file name") parser.add_argument( "cmake", metavar="OUTPUT_FILENAME", help="generated CMake file name") args = parser.parse_args() kconf = kconfiglib.Kconfig(args.kconfig) kconf.load_config(args.config) kconf.write_cmakeconf(args.cmake)
def write_kconfig_rst(): # The "main" function. Writes index.rst and the symbol RST files. if len(sys.argv) != 3: print("usage: {} <Kconfig> <output directory>", file=sys.stderr) sys.exit(1) kconf = kconfiglib.Kconfig(sys.argv[1]) out_dir = sys.argv[2] with open(os.path.join(out_dir, "index.rst"), "w") as index_rst: index_rst.write(INDEX_RST_HEADER) # - Sort the symbols by name so that they end up in sorted order in # index.rst # # - Use set() to get rid of duplicates for symbols defined in multiple # locations. for sym in sorted(set(kconf.defined_syms), key=lambda sym: sym.name): # Write an RST file for the symbol write_sym_rst(sym, out_dir) # Add an index entry for the symbol that links to its RST file. # Also list its prompt(s), if any. (A symbol can have multiple # prompts if it has multiple definitions.) # # The strip() avoids RST choking on stuff like *foo *, when people # accidentally include leading/trailing whitespace in prompts. index_rst.write(" * - :option:`CONFIG_{}`\n - {}\n".format( sym.name, " / ".join(node.prompt[0].strip() for node in sym.nodes if node.prompt)))
def __init__(self): """Scan all the Kconfig files and create a Kconfig object.""" # Define environment variables referenced from Kconfig os.environ['srctree'] = os.getcwd() os.environ['UBOOTVERSION'] = 'dummy' os.environ['KCONFIG_OBJDIR'] = '' self._conf = kconfiglib.Kconfig(warn=False)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__) parser.add_argument( "--kconfig", default="Kconfig", help="Base Kconfig file (default: Kconfig)") parser.add_argument( "--no-check-exists", dest="check_exists", action="store_false", help="Ignore assignments to non-existent symbols instead of erroring " "out") parser.add_argument( "--no-check-value", dest="check_value", action="store_false", help="Ignore assignments that didn't \"take\" (where the symbol got a " "different value, e.g. due to unsatisfied dependencies) instead " "of erroring out") parser.add_argument( "assignments", metavar="ASSIGNMENT", nargs="*", help="A 'NAME=value' assignment") args = parser.parse_args() kconf = kconfiglib.Kconfig(args.kconfig, suppress_traceback=True) print(kconf.load_config()) for arg in args.assignments: if "=" not in arg: sys.exit("error: no '=' in assignment: '{}'".format(arg)) name, value = arg.split("=", 1) if name not in kconf.syms: if not args.check_exists: continue sys.exit("error: no symbol '{}' in configuration".format(name)) sym = kconf.syms[name] if not sym.set_value(value): sys.exit("error: '{}' is an invalid value for the {} symbol {}" .format(value, kconfiglib.TYPE_TO_STR[sym.orig_type], name)) if args.check_value and sym.str_value != value: sys.exit("error: {} was assigned the value '{}', but got the " "value '{}'. Check the symbol's dependencies, and make " "sure that it has a prompt." .format(name, value, sym.str_value)) print(kconf.write_config())
def write_kconfig_rst(): # The "main" function. Writes index.rst and the symbol RST files. if len(sys.argv) != 3: print("usage: {} <Kconfig> <output directory>", file=sys.stderr) sys.exit(1) kconf = kconfiglib.Kconfig(sys.argv[1]) out_dir = sys.argv[2] # String with the RST for the index page index_rst = INDEX_RST_HEADER # - Sort the symbols by name so that they end up in sorted order in # index.rst # # - Use set() to get rid of duplicates for symbols defined in multiple # locations. for sym in sorted(set(kconf.defined_syms), key=lambda sym: sym.name): # Write an RST file for the symbol write_sym_rst(sym, out_dir) # Add an index entry for the symbol that links to its RST file. Also # list its prompt(s), if any. (A symbol can have multiple prompts if it # has multiple definitions.) index_rst += " * - :option:`CONFIG_{}`\n - {}\n".format( sym.name, " / ".join(node.prompt[0] for node in sym.nodes if node.prompt)) for choice in kconf.choices: # Write an RST file for the choice write_choice_rst(choice, out_dir) write_if_updated(os.path.join(out_dir, "index.rst"), index_rst)
def run(self): if 'ZEPHYR_BASE' not in os.environ: raise self.severe("ZEPHYR_BASE is not in the environment") if 'NRF_BASE' not in os.environ: raise self.severe("NRF_BASE is not in the environment") if 'NRF_RST_SRC' not in os.environ: raise self.severe("NRF_RST_SRC is not in the environment") if len(self.arguments) > 0: _, path = self.env.relfn2path(self.arguments[0]) else: source = self.state_machine.input_lines.source( self.lineno - self.state_machine.input_offset - 1) source_dir = os.path.dirname(os.path.abspath(source)) path = self._get_kconfig_path(source_dir) sys.path.append( os.path.join(os.environ['ZEPHYR_BASE'], 'scripts', 'kconfig')) import kconfiglib self._monkey_patch_kconfiglib(kconfiglib) # kconfiglib wants this env var defined os.environ['srctree'] = os.path.dirname(os.path.abspath(__file__)) kconfig = kconfiglib.Kconfig(filename=path) prefix = self.options.get('prefix', None) suffix = self.options.get('suffix', None) lines = [] for sym in kconfig.unique_defined_syms: lines.append(f'.. option:: CONFIG_{sym.name}\n') if 'only-visible' in self.options: visible = kconfiglib.TRI_TO_STR[sym.visibility] if visible == 'n': continue text = '' if 'show-type' in self.options: typ_ = kconfiglib.TYPE_TO_STR[sym.type] text += '``(' + typ_ + ')`` ' if prefix is not None: if (prefix.startswith('"') and prefix.endswith('"')) or \ (prefix.startswith("'") and prefix.endswith("'")): prefix = prefix[1:-1] text += prefix help_ = f'{sym.nodes[0].prompt[0]}' if prefix is not None: text += help_[:1].lower() + help_[1:] else: text += help_ if suffix is not None: if (suffix.startswith('"') and suffix.endswith('"')) or \ (suffix.startswith("'") and suffix.endswith("'")): suffix = suffix[1:-1] text += suffix lines.append(f'{text}\n') lines = statemachine.string2lines('\n'.join(lines)) self.state_machine.insert_input(lines, path) return []
def main(): if len(sys.argv) < 3: sys.exit("usage: {} KCONFIG_FILENAME DEFCONFIG_OUTPUT_FILE".format( sys.argv[0])) kconf = kconfiglib.Kconfig(sys.argv[1]) kconf.load_config() kconf.write_min_config(sys.argv[2])
def getKconfig(kconfig): if os.path.isfile('sdkconfig'): config = kconfiglib.Kconfig(kconfig) config.load_config('sdkconfig') else: print('Not configured!') exit(1) return config
def intrusively_determine_kconfig(self): kconfig = None config_uk = UK_CONFIG_FILE % self._localdir if os.path.exists(config_uk): logger.debug("Reading: %s..." % config_uk) kconfig = kconfiglib.Kconfig(filename=config_uk) return kconfig
def intrusively_determine_kconfig(self): if self.is_downloaded: config_uk = os.path.join(self.localdir, CONFIG_UK) if os.path.exists(config_uk): logger.debug("Reading: %s..." % config_uk) return kconfiglib.Kconfig(filename=config_uk) return None
def __init__(self, reconf=False, mconfig=menuconfig, log=logging): """The JHalfs class. Args: reconf (bool): Whether or not to force menuconfig to run. mconfig: The menuconfig module. Allows dependency injection of a mocked object for testing purposes. log: The logging module. Allows dependency injection of a mocked object for testing purposes. """ self.statedir = '{}/.jhalfs'.format( os.environ.get('HOME', os.getcwd())) self.configfile = '{}/config'.format(self.statedir) os.environ['KCONFIG_CONFIG'] = self.configfile os.environ['MENUCONFIG_STYLE'] = 'selection=fg:white,bg:blue' self.kconf = kconfiglib.Kconfig('{}/Config.in'.format(PKGDIR)) self.log = log self._legacy_cmd = os.getenv('JHALFS_LEGACY_CMD', './jhalfs.sh') if not os.path.isdir(self.statedir): try: os.mkdir(self.statedir) except Exception as e: raise JHalfsException(e) if not os.path.exists(self.configfile) or reconf: with JHalfsStdio('stdout') as out: mconfig.menuconfig(self.kconf) for line in out: log.info(line) try: self.config = {} pattern = re.compile(r'^CONFIG_[\w]+=.*') with open(self.configfile, 'r') as f: for line in f: line = line.strip() if pattern.fullmatch(line): key, value = line.split('=', 1) self.config[key] = value except FileNotFoundError: raise JHalfsException('No configuration file found.') with open('{}/configuration'.format(self.statedir), 'w') as legacy_cnf: subprocess.run(['sed', 's@CONFIG_@@', self.configfile], stdout=legacy_cnf) for item in ['jhalfs.sh', 'LFS', 'BLFS', 'CLFS', 'CLFS2', 'CLFS3', 'common', 'extras', 'git-version']: src = '{}/{}'.format(PKGDIR, item) dst = '{}/{}'.format(self.statedir, item) if not os.path.exists(dst): os.symlink(src, dst) for item in ['optimize', 'pkgmngt', 'custom']: src = '{}/{}'.format(TOPDIR, item) dst = '{}/{}'.format(self.statedir, item) if not os.path.exists(dst): os.symlink(src, dst)
def __init__(self, kconfig_file, sdkconfig_file, env=[]): env = [(name, value) for (name,value) in (e.split("=",1) for e in env)] for name, value in env: value = " ".join(value.split()) os.environ[name] = value self.config = kconfiglib.Kconfig(kconfig_file) self.config.load_config(sdkconfig_file)
def parse_kconfig(self): """ Returns a kconfiglib.Kconfig object for the Kconfig files. We reuse this object for all tests to avoid having to reparse for each test. """ if not ZEPHYR_BASE: self.skip("Not a Zephyr tree (ZEPHYR_BASE unset)") # Put the Kconfiglib path first to make sure no local Kconfiglib version is # used kconfig_path = os.path.join(ZEPHYR_BASE, "scripts", "kconfig") if not os.path.exists(kconfig_path): self.error(kconfig_path + " not found") sys.path.insert(0, kconfig_path) # Import globally so that e.g. kconfiglib.Symbol can be referenced in # tests global kconfiglib import kconfiglib # Look up Kconfig files relative to ZEPHYR_BASE os.environ["srctree"] = ZEPHYR_BASE # Parse the entire Kconfig tree, to make sure we see all symbols os.environ["SOC_DIR"] = "soc/" os.environ["ARCH_DIR"] = "arch/" os.environ["BOARD_DIR"] = "boards/*/*" os.environ["ARCH"] = "*" os.environ["KCONFIG_BINARY_DIR"] = tempfile.gettempdir() os.environ['DEVICETREE_CONF'] = "dummy" os.environ['TOOLCHAIN_HAS_NEWLIB'] = "y" # Older name for DEVICETREE_CONF, for compatibility with older Zephyr # versions that don't have the renaming os.environ["GENERATED_DTS_BOARD_CONF"] = "dummy" # For multi repo support self.get_modules(os.path.join(tempfile.gettempdir(), "Kconfig.modules")) # For Kconfig.dts support self.get_kconfig_dts(os.path.join(tempfile.gettempdir(), "Kconfig.dts")) # Tells Kconfiglib to generate warnings for all references to undefined # symbols within Kconfig files os.environ["KCONFIG_WARN_UNDEF"] = "y" try: # Note this will both print warnings to stderr _and_ return # them: so some warnings might get printed # twice. "warn_to_stderr=False" could unfortunately cause # some (other) warnings to never be printed. return kconfiglib.Kconfig() except kconfiglib.KconfigError as e: self.add_failure(str(e)) raise EndTest
def init_kconfig(): global kconf os.environ.update(srctree=TOP_DIR, KCONFIG_DOC_MODE="1", ARCH_DIR="arch", SRCARCH="*") kconf = kconfiglib.Kconfig(suppress_traceback=True)
def run_exploration_from_file(self, config_file, with_initial_config=True): kconfig_file = f"{self.cwd}/{self.kconfig}" kconfig_hash = self.file_hash(kconfig_file) with cd(self.cwd): kconf = kconfiglib.Kconfig(kconfig_file) kconf.load_config(config_file) if with_initial_config: experiment = ExploreConfig() shutil.copyfile(config_file, f"{self.cwd}/.config") experiment([ "--config_hash", self.file_hash(config_file), "--kconfig_hash", kconfig_hash, "--project_version", self.git_commit_id(), "--project_root", self.cwd, "--clean_command", self.clean_command, "--build_command", self.build_command, "--attr_command", self.attribute_command, ]) for symbol in kconf.syms.values(): if kconfiglib.TYPE_TO_STR[symbol.type] == "bool": if symbol.tri_value == 0 and 2 in symbol.assignable: logger.debug(f"Set {symbol.name} to y") symbol.set_value(2) self._run_explore_experiment(kconf, kconfig_hash, config_file) elif symbol.tri_value == 2 and 0 in symbol.assignable: logger.debug(f"Set {symbol.name} to n") symbol.set_value(0) self._run_explore_experiment(kconf, kconfig_hash, config_file) elif (kconfiglib.TYPE_TO_STR[symbol.type] == "int" and symbol.visibility and symbol.ranges): for min_val, max_val, condition in symbol.ranges: if kconfiglib.expr_value(condition): min_val = int(min_val.str_value, 0) max_val = int(max_val.str_value, 0) step_size = (max_val - min_val) // 5 if step_size == 0: step_size = 1 for val in range(min_val, max_val + 1, step_size): print(f"Set {symbol.name} to {val}") symbol.set_value(str(val)) self._run_explore_experiment( kconf, kconfig_hash, config_file) break else: continue
def main(): kconf = kconfiglib.Kconfig("Kconfig") kconf.load_config() for sym in kconf.unique_defined_syms: val = sym.str_value if sym.orig_type is kconfiglib.BOOL: print("set {}{} {}\n".format(kconf.config_prefix, sym.name, val)) if sym.orig_type is kconfiglib.STRING: print("set {}{} \"{}\"\n".format(kconf.config_prefix, sym.name, val))
def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]: """Load Kconfig""" with TemporaryDirectory() as td: projects = zephyr_module.west_projects() projects = [p.posixpath for p in projects["projects"]] if projects else None modules = zephyr_module.parse_modules(ZEPHYR_BASE, projects) # generate Kconfig.modules file kconfig = "" for module in modules: kconfig += zephyr_module.process_kconfig(module.project, module.meta) with open(Path(td) / "Kconfig.modules", "w") as f: f.write(kconfig) # generate dummy Kconfig.dts file kconfig = "" with open(Path(td) / "Kconfig.dts", "w") as f: f.write(kconfig) # base environment os.environ["ZEPHYR_BASE"] = str(ZEPHYR_BASE) os.environ["srctree"] = str(ZEPHYR_BASE) os.environ["KCONFIG_DOC_MODE"] = "1" os.environ["KCONFIG_BINARY_DIR"] = td # include all archs and boards os.environ["ARCH_DIR"] = "arch" os.environ["ARCH"] = "*" os.environ["BOARD_DIR"] = "boards/*/*" # insert external Kconfigs to the environment module_paths = dict() for module in modules: name = module.meta["name"] name_var = module.meta["name-sanitized"].upper() module_paths[name] = module.project build_conf = module.meta.get("build") if not build_conf: continue if build_conf.get("kconfig"): kconfig = Path(module.project) / build_conf["kconfig"] os.environ[f"ZEPHYR_{name_var}_KCONFIG"] = str(kconfig) elif build_conf.get("kconfig-ext"): for path in app.config.kconfig_ext_paths: kconfig = Path(path) / "modules" / name / "Kconfig" if kconfig.exists(): os.environ[f"ZEPHYR_{name_var}_KCONFIG"] = str(kconfig) return kconfiglib.Kconfig(ZEPHYR_BASE / "Kconfig"), module_paths
def init(): # Initializes these globals: # # kconf: # Kconfig instance for the configuration # # out_dir: # Output directory # # index_desc: # Set to the corresponding command-line arguments (or None if # missing) # # modules: # A list of (<title>, <suffix>, <path>, <desc. path>) tuples. See the # --modules flag. Empty if --modules wasn't passed. # # <path> is an absolute pathlib.Path instance, which is handy for robust # path comparisons. # # strip_module_paths: # True unless --keep-module-paths was passed global kconf global out_dir global index_desc global modules global strip_module_paths args = parse_args() kconf = kconfiglib.Kconfig(args.kconfig) out_dir = args.out_dir index_desc = args.index_desc strip_module_paths = args.strip_module_paths modules = [] for module_spec in args.modules: if module_spec.count(":") == 2: title, suffix, path_s = module_spec.split(":") desc_path = None elif module_spec.count(":") == 3: title, suffix, path_s, desc_path = module_spec.split(":") else: sys.exit("error: --modules argument '{}' should have the format " "<title>:<suffix>:<path> or the format " "<title>:<suffix>:<path>:<index description filename>" .format(module_spec)) abspath = pathlib.Path(path_s).resolve() if not abspath.exists(): sys.exit("error: path '{}' in --modules argument does not exist" .format(abspath)) modules.append((title, suffix, abspath, desc_path))
def main(): kconf = kconfiglib.Kconfig('Kconfig') kconf.load_config() tree = ET.parse(sys.argv[1]) root = tree.getroot() for sym in kconf.unique_defined_syms: val = sym.str_value if sym.orig_type is kconfiglib.BOOL: if sym.name.startswith('STP_'): configure(root, sym.name[4:].lower(), sym.str_value == "y") tree.write('/dev/stdout')
def main(argv=None): if argv is None: argv = sys.argv[1:] # Instantiate cmd options parser parser = argparse.ArgumentParser( description='Interactive Kconfig configuration editor' ) parser.add_argument( '--kconfig', metavar='FILE', type=str, default='Kconfig', help='path to root Kconfig file' ) parser.add_argument( '--config', metavar='FILE', type=str, help='path to .config file to load' ) if "--silent" in argv: parser.add_argument( '--silent', dest = '_silent_', type=str, help='silent mode, not show window' ) args = parser.parse_args(argv) kconfig_path = args.kconfig config_path = args.config # Verify that Kconfig file exists if not os.path.isfile(kconfig_path): raise RuntimeError('\'{}\': no such file'.format(kconfig_path)) # Parse Kconfig files kconf = kconfiglib.Kconfig(filename=kconfig_path) if "--silent" not in argv: print("In normal mode. Will show menuconfig window.") mc = MenuConfig(kconf) # If config file was specified, load it if config_path: mc.open_config(config_path) print("Enter mainloop. Waiting...") tk.mainloop() else: print("In silent mode. Don`t show menuconfig window.") mc = MenuConfig(kconf, True) # If config file was specified, load it if config_path: mc.open_config(config_path) mc._close_window()
def main(): if len(sys.argv) < 3: usage() sys.exit(1) target_board = os.environ['BOARD'] target_scenario = os.environ['SCENARIO'] kconfig_path = sys.argv[1] if not os.path.isfile(kconfig_path): sys.stderr.write("Cannot find file %s\n" % kconfig_path) sys.exit(1) kconfig = kconfiglib.Kconfig(kconfig_path) defconfig_path = kconfig.defconfig_filename if not defconfig_path or not os.path.isfile(defconfig_path): sys.stderr.write("No defconfig found for BOARD %s on SCENARIO %s.\n" % (target_board, target_scenario)) sys.exit(1) kconfig.load_config(defconfig_path) config_path = sys.argv[2] if os.path.isfile(config_path): # No need to change .config if it is already equivalent to the specified # default. kconfig_current = kconfiglib.Kconfig(kconfig_path) kconfig_current.load_config(config_path) same_config = True for sym in kconfig_current.syms: if kconfig_current.syms[sym].str_value != kconfig.syms[ sym].str_value: same_config = False break if same_config: sys.exit(0) sys.stdout.write("Default configuration based on %s.\n" % defconfig_path) kconfig.write_config(config_path) sys.stdout.write("Configuration written to %s.\n" % config_path)
def init_kconfig(): global kconf os.environ.update(srctree=TOP_DIR, CMAKE_BINARY_DIR=modules_file_dir(), KCONFIG_DOC_MODE="1", ZEPHYR_BASE=TOP_DIR, SOC_DIR="soc", ARCH_DIR="arch", BOARD_DIR="boards/*/*", ARCH="*") kconf = kconfiglib.Kconfig()
def main(): # Writes index.rst and the symbol RST files if len(sys.argv) != 3: sys.exit("usage: {} <Kconfig> <output directory>".format(sys.argv[0])) kconf = kconfiglib.Kconfig(sys.argv[1]) out_dir = sys.argv[2] if os.environ.get("KCONFIG_TURBO_MODE") == "1": write_dummy_index(kconf, out_dir) else: write_rst(kconf, out_dir)