def _makeAllNoConfig(): pylkc.conf_read(None) # clear all symbol setttings defaultValueDict = { "EXPERT": pylkc.tristate.yes, "EMBEDDED": pylkc.tristate.yes } while True: changed = False for sym in pylkc.all_symbols(): sym.calc_value() if sym.is_choice_value(): continue if sym.name in defaultValueDict: if sym.get_tristate_value() == defaultValueDict[sym.name]: continue ret = sym.set_tristate_value(defaultValueDict[sym.name]) if not ret: raise InternalError( "failed to set default value for symbol %s" % (sym.name)) elif sym.get_type() in [ pylkc.symbol.TYPE_BOOLEAN, pylkc.symbol.TYPE_TRISTATE ]: if sym.get_tristate_value() == pylkc.tristate.no: continue ret = sym.set_tristate_value(pylkc.tristate.no) if not ret: continue else: continue changed = True if not changed: break
def _makeAllNoConfig(): pylkc.conf_read(None) # clear all symbol setttings defaultValueDict = {"EXPERT": pylkc.tristate.yes, "EMBEDDED": pylkc.tristate.yes} while True: changed = False for sym in pylkc.all_symbols(): sym.calc_value() if sym.is_choice_value(): continue if sym.name in defaultValueDict: if sym.get_tristate_value() == defaultValueDict[sym.name]: continue ret = sym.set_tristate_value(defaultValueDict[sym.name]) if not ret: raise InternalError("failed to set default value for symbol %s" % (sym.name)) elif sym.get_type() in [pylkc.symbol.TYPE_BOOLEAN, pylkc.symbol.TYPE_TRISTATE]: if sym.get_tristate_value() == pylkc.tristate.no: continue ret = sym.set_tristate_value(pylkc.tristate.no) if not ret: continue else: continue changed = True if not changed: break
def check_value(ksrcDir, cfgFile, name, value): pylkc.init(ksrcDir) try: pylkc.conf_parse(ksrcDir) pylkc.conf_read(cfgFile) for sym in pylkc.all_symbols(): sym.calc_value() if name.startswith("/"): ret = _getChoice(name) if ret != value: raise CheckError(name, value, ret) else: ret = _getValue(name) if ret != value: raise CheckError(name, value, ret) finally: pylkc.release()
def check_values(ksrcDir, cfgFile, valueDict): pylkc.init(ksrcDir) try: pylkc.conf_parse(ksrcDir) pylkc.conf_read(cfgFile) for sym in pylkc.all_symbols(): sym.calc_value() for k, v in valueDict.items(): if k.startswith("/"): ret = _getChoice(k) if ret != v: raise CheckError(k, v, ret) else: ret = _getValue(k) if ret != v: raise CheckError(k, v, ret) finally: pylkc.release()
def parseRuleFile(self, ruleFile): # fill self.ruleDict lineList = [] with open(ruleFile) as f: lineList = f.read().split("\n") for i in range(0, len(lineList)): line = lineList[i] if line == "": # remove empty line continue if line.startswith("#"): # remove comment continue m = re.match("^(.*?) +#.*$", line) # remove comment if m is not None: line = m.group(1) self.ruleDict[i + 1] = line # fill self.itemList for lineNo, line in self.ruleDict.items(): key = line.split("=")[0] value = line.split("=")[1].strip("\t ") if key.startswith("["): kis = key[1:-1].split(":") if kis[0] == "symbols": mstr = kis[1] def _filterFunc(menuObj): return False elif kis[0] == "normal-symbols": mstr = kis[1] def _filterFunc(menuObj): if pylkcx.is_menu_debugging(menuObj): return True if pylkcx.is_menu_deprecated(menuObj): return True if pylkcx.is_menu_workaround(menuObj): return True if pylkcx.is_menu_experimental(menuObj): return True if pylkcx.is_menu_dangerous(menuObj): return True return False elif kis[0] == "debugging-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_debugging(menuObj) elif kis[0] == "deprecated-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_deprecated(menuObj) elif kis[0] == "workaround-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_workaround(menuObj) elif kis[0] == "experimental-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_experimental(menuObj) elif kis[0] == "dangerous-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_dangerous(menuObj) elif kis[0] == "regex-symbols": regexPattern = kis[1] mstr = kis[2] def _filterFunc(menuObj): if menuObj.sym is None: return True if menuObj.sym.name is None: return True if not re.match(regexPattern, menuObj.sym.name): return True return False elif kis[0] == "prompt-regex-symbols": regexPattern = kis[1] mstr = kis[2] def _filterFunc(menuObj): return not re.match(regexPattern, menuObj.get_prompt()) else: raise SyntaxError(self, lineNo, "invalid key %s" % (kis[0])) self._generateMenuInfoSymbols(lineNo, mstr, _filterFunc, value) elif key.startswith("/"): self._generateMenuInfoChoice(lineNo, key, value) else: self._generateMenuInfoSymbol(lineNo, key, value) # fill self.symRefDict if True: # init for sym in pylkc.all_symbols(): self.symRefDict[sym] = set() # for "Selects" expression for sym in pylkc.all_symbols(): for prop in sym.get_properties(pylkc.property.TYPE_SELECT): self.symRefDict[sym].add(prop.get_symbol()) # for "Depends on" expression for sym in pylkc.all_symbols(): for s in _allSymbolsInExpr(sym.dir_dep.expr): if s not in self.symRefDict: continue # ??? self.symRefDict[s].add(sym) # convert set to list for k in self.symRefDict: self.symRefDict[k] = list(self.symRefDict[k]) # fill self.symItemDict for item in self.itemList: if item.symbolMenu is not None: if item.symbolMenu.sym in self.symItemDict: self.symItemDict[item.symbolMenu.sym].append(item) else: self.symItemDict[item.symbolMenu.sym] = [item] elif item.choiceMenu is not None: for m in item.choiceMenu.list: if m.sym in self.symItemDict: self.symItemDict[m.sym].append(item) else: self.symItemDict[m.sym] = [item] else: assert False # fill self.itemRunList self.itemRunList = list(self.itemList) # fill self.symValueDict for sym in pylkc.all_symbols(): self.symValueDict[sym] = (_symGetValue(sym), sym.visible, sym.rev_dep.tri)
def generate(ksrcDir, baseConfig, ruleFile, baseConfigFilename=None, output=None, eventHandler=None): if baseConfig == "file": assert baseConfigFilename is not None if output is None: output = os.path.join(ksrcDir, ".config") context = _Context() context.eventHandler = eventHandler if context.eventHandler is not None: context.eventHandler.progressChanged("initialized") pylkc.init(ksrcDir) try: pylkc.conf_parse(ksrcDir) # load base config if baseConfig == "defconfig": _makeDefConfig(ksrcDir, "") elif baseConfig == "allnoconfig": _makeAllNoConfig() elif baseConfig == "allnoconfig+module": _makeAllNoConfig() pylkc.sym_find("MODULES").set_tristate_value(pylkc.tristate.yes) elif baseConfig == "file": pylkc.conf_read(baseConfigFilename) else: assert False for sym in pylkc.all_symbols(): sym.calc_value() if context.eventHandler is not None: context.eventHandler.progressChanged("base-config-loaded") # parse rule file context.parseRuleFile(ruleFile) if context.eventHandler is not None: context.eventHandler.progressChanged("rule-file-parsed") # record pre-set values if baseConfig == "allnoconfig": _presetSymbol(context, "EXPERT", "y") _presetSymbol(context, "EMBEDDED", "y") elif baseConfig == "allnoconfig+module": _presetSymbol(context, "EXPERT", "y") _presetSymbol(context, "EMBEDDED", "y") _presetSymbol(context, "MODULES", "y") else: pass # do operation while len(context.itemRunList) > 0: item = context.itemRunList.pop(0) if item.symbolMenu is not None: if item.value.startswith("\""): _procSymbolNonYmn(context, item) elif _is_int(item.value): _procSymbolNonYmn(context, item) else: _procSymbolYmn(context, item) elif item.choiceMenu is not None: _procChoice(context, item) else: assert False pylkc.conf_write(output) # final check: # 1. check if any symbol is ignored by invisibility for item in context.itemRunList: if item.symbolMenu is not None: if item.symbolMenu in context.symValueRecord: continue if item.symbolMenu.sym.get_type() not in [pylkc.symbol.TYPE_BOOLEAN, pylkc.symbol.TYPE_TRISTATE]: continue if item.value == "n": continue if not item.vforce: continue raise NotExecutedError(context, item, "invisibility") elif item.choiceMenu is not None: if any(m in context.symValueRecord for m in item.choiceMenu.list): continue raise NotExecutedError(context, item, "invisibility") else: assert False pylkc.conf_write(output) if context.eventHandler is not None: context.eventHandler.progressChanged("finished") finally: pylkc.release()
def parseRuleFile(self, ruleFile): # fill self.ruleDict lineList = [] with open(ruleFile) as f: lineList = f.read().split("\n") for i in range(0, len(lineList)): line = lineList[i].strip() if line == "": # remove empty line continue if line.startswith("#"): # remove comment continue m = re.match("^(.*?) +#.*$", line) # remove comment if m is not None: line = m.group(1) self.ruleDict[i + 1] = line # fill self.itemList for lineNo, line in self.ruleDict.items(): key = line.split("=")[0] value = line.split("=")[1].strip("\t ") if key.startswith("["): kis = key[1:-1].split(":") if kis[0] == "symbols": mstr = kis[1] def _filterFunc(menuObj): return False elif kis[0] == "normal-symbols": mstr = kis[1] def _filterFunc(menuObj): if pylkcx.is_menu_debugging(menuObj): return True if pylkcx.is_menu_deprecated(menuObj): return True if pylkcx.is_menu_workaround(menuObj): return True if pylkcx.is_menu_experimental(menuObj): return True if pylkcx.is_menu_dangerous(menuObj): return True return False elif kis[0] == "debugging-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_debugging(menuObj) elif kis[0] == "deprecated-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_deprecated(menuObj) elif kis[0] == "workaround-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_workaround(menuObj) elif kis[0] == "experimental-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_experimental(menuObj) elif kis[0] == "dangerous-symbols": mstr = kis[1] def _filterFunc(menuObj): return not pylkcx.is_menu_dangerous(menuObj) elif kis[0] == "regex-symbols": regexPattern = kis[1] mstr = kis[2] def _filterFunc(menuObj): if menuObj.sym is None: return True if menuObj.sym.name is None: return True if not re.match(regexPattern, menuObj.sym.name): return True return False elif kis[0] == "prompt-regex-symbols": regexPattern = kis[1] mstr = kis[2] def _filterFunc(menuObj): return not re.match(regexPattern, menuObj.get_prompt()) else: raise SyntaxError(self, lineNo, "invalid key %s" % (kis[0])) self._generateMenuInfoSymbols(lineNo, mstr, _filterFunc, value) elif key.startswith("/"): self._generateMenuInfoChoice(lineNo, key, value) else: self._generateMenuInfoSymbol(lineNo, key, value) # fill self.symRefDict if True: # init for sym in pylkc.all_symbols(): self.symRefDict[sym] = set() # for "Selects" expression for sym in pylkc.all_symbols(): for prop in sym.get_properties(pylkc.property.TYPE_SELECT): self.symRefDict[sym].add(prop.get_symbol()) # for "Depends on" expression for sym in pylkc.all_symbols(): for s in _allSymbolsInExpr(sym.dir_dep.expr): if s not in self.symRefDict: continue # ??? self.symRefDict[s].add(sym) # convert set to list for k in self.symRefDict: self.symRefDict[k] = list(self.symRefDict[k]) # fill self.symItemDict for item in self.itemList: if item.symbolMenu is not None: if item.symbolMenu.sym in self.symItemDict: self.symItemDict[item.symbolMenu.sym].append(item) else: self.symItemDict[item.symbolMenu.sym] = [item] elif item.choiceMenu is not None: for m in item.choiceMenu.list: if m.sym in self.symItemDict: self.symItemDict[m.sym].append(item) else: self.symItemDict[m.sym] = [item] else: assert False # fill self.itemRunList self.itemRunList = list(self.itemList) # fill self.symValueDict for sym in pylkc.all_symbols(): self.symValueDict[sym] = (_symGetValue(sym), sym.visible, sym.rev_dep.tri)
def generate(ksrcDir, baseConfig, ruleFile, baseConfigFilename=None, output=None, eventHandler=None): if baseConfig == "file": assert baseConfigFilename is not None if output is None: output = os.path.join(ksrcDir, ".config") context = _Context() context.eventHandler = eventHandler if context.eventHandler is not None: context.eventHandler.progressChanged("initialized") pylkc.init(ksrcDir) try: pylkc.conf_parse(ksrcDir) # load base config if baseConfig == "defconfig": _makeDefConfig(ksrcDir, "") elif baseConfig == "allnoconfig": _makeAllNoConfig() elif baseConfig == "allnoconfig+module": _makeAllNoConfig() pylkc.sym_find("MODULES").set_tristate_value(pylkc.tristate.yes) elif baseConfig == "file": pylkc.conf_read(baseConfigFilename) else: assert False for sym in pylkc.all_symbols(): sym.calc_value() if context.eventHandler is not None: context.eventHandler.progressChanged("base-config-loaded") # parse rule file context.parseRuleFile(ruleFile) if context.eventHandler is not None: context.eventHandler.progressChanged("rule-file-parsed") # record pre-set values if baseConfig == "allnoconfig": _presetSymbol(context, "EXPERT", "y") _presetSymbol(context, "EMBEDDED", "y") elif baseConfig == "allnoconfig+module": _presetSymbol(context, "EXPERT", "y") _presetSymbol(context, "EMBEDDED", "y") _presetSymbol(context, "MODULES", "y") else: pass # do operation while len(context.itemRunList) > 0: item = context.itemRunList.pop(0) if item.symbolMenu is not None: if item.value.startswith("\""): _procSymbolNonYmn(context, item) elif _is_int(item.value): _procSymbolNonYmn(context, item) else: _procSymbolYmn(context, item) elif item.choiceMenu is not None: _procChoice(context, item) else: assert False pylkc.conf_write(output) # final check: # 1. check if any symbol is ignored by invisibility for item in context.itemRunList: if item.symbolMenu is not None: if item.symbolMenu in context.symValueRecord: continue if item.symbolMenu.sym.get_type() not in [ pylkc.symbol.TYPE_BOOLEAN, pylkc.symbol.TYPE_TRISTATE ]: continue if item.value == "n": continue if not item.vforce: continue raise NotExecutedError(context, item, "invisibility") elif item.choiceMenu is not None: if any(m in context.symValueRecord for m in item.choiceMenu.list): continue raise NotExecutedError(context, item, "invisibility") else: assert False pylkc.conf_write(output) if context.eventHandler is not None: context.eventHandler.progressChanged("finished") finally: pylkc.release()
def value_refresh(): for sym in pylkc.all_symbols(): sym.calc_value()