From: Clark Williams <williams@xxxxxxxxxx> redhat: python replacement for merge.pl Replace the (still functioning) merge.pl in redhat/configs with a python version (merge.py) for ease of maintenance. Signed-off-by: Clark Williams <williams@xxxxxxxxxx> diff --git a/redhat/configs/build_configs.sh b/redhat/configs/build_configs.sh index blahblah..blahblah 100755 --- a/redhat/configs/build_configs.sh +++ b/redhat/configs/build_configs.sh @@ -84,7 +84,7 @@ function merge_configs() test -n "$skip_if_missing" && test ! -e "$cfile" && continue - if ! perl merge.pl "$cfile" config-merging."$count" > config-merged."$count"; then + if ! ./merge.py "$cfile" config-merging."$count" > config-merged."$count"; then die "Failed to merge $cfile" fi mv config-merged."$count" config-merging."$count" diff --git a/redhat/configs/merge.py b/redhat/configs/merge.py new file mode 100755 index blahblah..blahblah 100755 --- /dev/null +++ b/redhat/configs/merge.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: GPL-2.0 +# Author: Clark Williams <williams@xxxxxxxxxx> +# Copyright (C) 2022 Red Hat, Inc. +# +# merge.py - a direct replacement for merge.pl in the redhat/configs directory +# +# invocation: python merge.py overrides baseconfig +# +# Both input files are kernel config files, where overides is config overides +# to the baseconfig file. Both are read into python dictionaries with the +# keys being the config name and the values being the config file text + +# The script iterates through the overrides keys adding/replacing the contents +# of the baseconfig values and then outputs the new baseconfig to stdout. +# + +import sys +import os.path + +def usage(msg): + print(msg) + print("usage: merge.py overrides baseconfig") + sys.exit(1) + +# read a config file and return a dictionary of the contents +def read_config_file(cfgfile): + configs = {} + for l in open(cfgfile).readlines(): + if len(l) == 0: continue + if l.startswith("# CONFIG_"): + configs[l.split()[1]] = l + continue + if l.startswith("CONFIG_"): + configs[l.split('=')[0]] = l + continue + return configs + + +if len(sys.argv) < 3: usage("must have two input files") + +# read in the overides file +if not os.path.exists(sys.argv[1]): + usage("overrides config file %s does not exist!" % sys.argv[1]) +overrides = read_config_file(sys.argv[1]) + +# read in the base config file +if not os.path.exists(sys.argv[2]): + usage("base config file %s does not exist!" % sys.argv[2]) +baseconfigs = read_config_file(sys.argv[2]) + +# iterate over the overrides, replacing values in the base config +for v in overrides.keys(): + baseconfigs[v] = overrides[v] + +# print the new config to stdout +for v in baseconfigs.keys(): + print(baseconfigs[v]) -- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117 _______________________________________________ kernel mailing list -- kernel@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to kernel-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kernel@xxxxxxxxxxxxxxxxxxxxxxx Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue