[OS-BUILD PATCHv3 1/4] redhat: update merge.py to handle merge.pl corner cases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Clark Williams <williams@xxxxxxxxxx>

redhat: update merge.py to handle merge.pl corner cases

Change merge.py to handle input config files in  similar manner to
how merge.pl did it.

Signed-off-by: Clark Williams <williams@xxxxxxxxxx>

diff --git a/redhat/configs/merge.py b/redhat/configs/merge.py
index blahblah..blahblah 100755
--- a/redhat/configs/merge.py
+++ b/redhat/configs/merge.py
@@ -5,54 +5,77 @@
 #
 # merge.py - a direct replacement for merge.pl in the redhat/configs directory
 #
-# invocation:   python merge.py overrides baseconfig
+# invocation:   python merge.py overrides baseconfig [arch]
 #
-# 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.
+# This script merges two kernel configuration files, an override file and a
+# base config file and writes the results to stdout.
 #
+# The script reads the overrides into a dictionary, then reads the baseconfig
+# file, looking for overrides and replacing any found, then printing the result
+# to stdout. Finally any remaining (new) configs in the override are appended to the
+# end of the output
 
 import sys
+import re
 import os.path
 
 def usage(msg):
-    print(msg)
-    print("usage: merge.py overrides baseconfig")
+    sys.stderr.write(msg + "\n")
+    sys.stderr.write("usage: merge.py overrides baseconfig [arch]\n")
     sys.exit(1)
 
-# read a config file and return a dictionary of the contents
-def read_config_file(cfgfile):
-    configs = {}
-    with open(cfgfile) as f:
-        for l in [n.strip() for n in f.readlines()]:
-            if not l:  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])
-
-# update baseconfigs with the overrides values
-baseconfigs.update(overrides)
-
-# print the new config to stdout
-for v in baseconfigs.values():
-    print(v)
+isset = re.compile(r'^(CONFIG_\w+)=')
+notset = re.compile(r'^#\s+(CONFIG_\w+)\s+is not set')
+
+# search an input line for a config (set or notset) pattern
+# if we get a match return the config that is being changed
+def find_config(line):
+    if m := isset .match(line):
+        return m.group(1)
+    if m := notset.match(line):
+        return m.group(1)
+    return None
+
+#########################################################
+
+if len(sys.argv) < 3:
+    usage("must have two input files")
+
+override_file = sys.argv[1]
+baseconfig_file = sys.argv[2]
+
+if not os.path.exists(override_file):
+    usage("overrides config file %s does not exist!" % override_file)
+
+if not os.path.exists(baseconfig_file):
+    usage("base configs file %s does not exist" % baseconfig_file)
+
+if len(sys.argv) == 4:
+    print("# %s" % sys.argv[3])
+
+# read each line of the override file and store any configuration values
+# in the overrides dictionary, keyed by the configuration name.
+overrides = {}
+with open(override_file, "rt") as f:
+    for l in [n.strip() for n in f.readlines()]:
+        if c := find_config(l):
+            overrides[c] = l
+
+# now read and print the base config, checking each line
+# that defines a config value and printing the override if
+# it exists
+with open(baseconfig_file, "rt") as f:
+    for line in [ l.strip() for l in f.readlines() ]:
+        c = find_config(line)
+        if c and c in overrides:
+            print(overrides[c])
+            del overrides[c]
+        else:
+            print(line)
+
+# print out the remaining configs (new values)
+# from the overrides file
+for c in overrides:
+    print (overrides[c])
+
+sys.exit(0)

--
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2262
_______________________________________________
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




[Index of Archives]     [Fedora General Discussion]     [Older Fedora Users Archive]     [Fedora Advisory Board]     [Fedora Security]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Mentors]     [Fedora Package Announce]     [Fedora Package Review]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Coolkey]     [Yum Users]     [Tux]     [Yosemite News]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [USB]     [Asterisk PBX]

  Powered by Linux