devtools: add script to ease backport of renamed files
authorBruce Richardson <bruce.richardson@intel.com>
Tue, 20 Apr 2021 10:22:31 +0000 (11:22 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 21 Apr 2021 12:17:29 +0000 (14:17 +0200)
With all the library folders renamed to remove the "librte_" prefix,
we need to fixup patches for easier backport, i.e. add back in the
prefix for any references to those renamed files.

In the script itself we use a general approach to allow other functions
to be added in future for other modifications needed to patches.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
MAINTAINERS
devtools/update-patches.py [new file with mode: 0755]

index 84e080b..44f3d32 100644 (file)
@@ -87,6 +87,7 @@ F: devtools/checkpatches.sh
 F: devtools/get-maintainer.sh
 F: devtools/git-log-fixes.sh
 F: devtools/load-devel-config
+F: devtools/update-patches.py
 F: devtools/words-case.txt
 F: license/
 F: .editorconfig
diff --git a/devtools/update-patches.py b/devtools/update-patches.py
new file mode 100755 (executable)
index 0000000..0cff215
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+import os
+import sys
+import shutil
+from os.path import abspath, dirname, join
+
+def fixup_library_renames(contents):
+    """since library directory names have dropped the 'librte_' prefix,
+    add those prefixes back in for patches than need it"""
+    modified = False
+
+    # first get all the DPDK libs to build up replacement list
+    # stored in function attribute between calls
+    try:
+        libdirs = fixup_library_renames.libdirs
+    except AttributeError:
+        dpdk_libdir = abspath(join(dirname(sys.argv[0]), '..', 'lib'))
+        for root, dirs, files in os.walk(dpdk_libdir):
+            fixup_library_renames.libdirs = dirs
+            libdirs = dirs
+            break
+
+    for i in range(len(contents)):
+        # skip over any lines which don't have lib in it
+        if not "lib/" in contents[i]:
+            continue
+        for d in libdirs:
+            if f'lib/{d}' in contents[i]:
+                modified = True
+                contents[i] = contents[i].replace(f'lib/{d}', f'lib/librte_{d}')
+    return modified
+
+def main():
+    "takes list of patches off argv and processes each"
+    for patch in sys.argv[1:]:
+        modified = False
+        with open(patch) as f:
+            contents = f.readlines()
+
+        modified |= fixup_library_renames(contents)
+        # other functions to change the patch go here
+
+        if not modified:
+            continue
+        shutil.copyfile(f'{patch}', f'{patch}.bak')
+        with open(patch, 'w') as f:
+            f.writelines(contents)
+
+if __name__ == "__main__":
+    main()