diff options
Diffstat (limited to 'scripts/contrib/convert-variable-renames.py')
| -rwxr-xr-x | scripts/contrib/convert-variable-renames.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/scripts/contrib/convert-variable-renames.py b/scripts/contrib/convert-variable-renames.py new file mode 100755 index 0000000000..2e2a74f87b --- /dev/null +++ b/scripts/contrib/convert-variable-renames.py | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | # | ||
| 3 | # Conversion script to rename variables to versions with improved terminology. | ||
| 4 | # Also highlights potentially problematic langage and removed variables. | ||
| 5 | # | ||
| 6 | # Copyright (C) 2021 Richard Purdie | ||
| 7 | # Copyright (C) 2022 Wind River Systems, Inc. | ||
| 8 | # | ||
| 9 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 10 | # | ||
| 11 | |||
| 12 | import re | ||
| 13 | import os | ||
| 14 | import sys | ||
| 15 | import tempfile | ||
| 16 | import shutil | ||
| 17 | import mimetypes | ||
| 18 | |||
| 19 | if len(sys.argv) < 2: | ||
| 20 | print("Please specify a directory to run the conversion script against.") | ||
| 21 | sys.exit(1) | ||
| 22 | |||
| 23 | renames = { | ||
| 24 | "BB_ENV_WHITELIST" : "BB_ENV_PASSTHROUGH", | ||
| 25 | "BB_ENV_EXTRAWHITE" : "BB_ENV_PASSTHROUGH_ADDITIONS", | ||
| 26 | "BB_HASHCONFIG_WHITELIST" : "BB_HASHCONFIG_IGNORE_VARS", | ||
| 27 | "BB_SETSCENE_ENFORCE_WHITELIST" : "BB_SETSCENE_ENFORCE_IGNORE_TASKS", | ||
| 28 | "BB_HASHBASE_WHITELIST" : "BB_BASEHASH_IGNORE_VARS", | ||
| 29 | "BB_HASHTASK_WHITELIST" : "BB_TASKHASH_IGNORE_TASKS", | ||
| 30 | "CVE_CHECK_PN_WHITELIST" : "CVE_CHECK_SKIP_RECIPE", | ||
| 31 | "CVE_CHECK_WHITELIST" : "CVE_CHECK_IGNORE", | ||
| 32 | "MULTI_PROVIDER_WHITELIST" : "BB_MULTI_PROVIDER_ALLOWED", | ||
| 33 | "PNBLACKLIST" : "SKIP_RECIPE", | ||
| 34 | "SDK_LOCAL_CONF_BLACKLIST" : "ESDK_LOCALCONF_REMOVE", | ||
| 35 | "SDK_LOCAL_CONF_WHITELIST" : "ESDK_LOCALCONF_ALLOW", | ||
| 36 | "SDK_INHERIT_BLACKLIST" : "ESDK_CLASS_INHERIT_DISABLE", | ||
| 37 | "SSTATE_DUPWHITELIST" : "SSTATE_ALLOW_OVERLAP_FILES", | ||
| 38 | "SYSROOT_DIRS_BLACKLIST" : "SYSROOT_DIRS_IGNORE", | ||
| 39 | "UNKNOWN_CONFIGURE_WHITELIST" : "UNKNOWN_CONFIGURE_OPT_IGNORE", | ||
| 40 | } | ||
| 41 | |||
| 42 | removed_list = [ | ||
| 43 | "BB_STAMP_WHITELIST", | ||
| 44 | "BB_STAMP_POLICY", | ||
| 45 | "INHERIT_BLACKLIST", | ||
| 46 | "TUNEABI_WHITELIST", | ||
| 47 | ] | ||
| 48 | |||
| 49 | context_check_list = [ | ||
| 50 | "blacklist", | ||
| 51 | "whitelist", | ||
| 52 | "abort", | ||
| 53 | ] | ||
| 54 | |||
| 55 | def processfile(fn): | ||
| 56 | |||
| 57 | print("processing file '%s'" % fn) | ||
| 58 | try: | ||
| 59 | fh, abs_path = tempfile.mkstemp() | ||
| 60 | modified = False | ||
| 61 | with os.fdopen(fh, 'w') as new_file: | ||
| 62 | with open(fn, "r") as old_file: | ||
| 63 | lineno = 0 | ||
| 64 | for line in old_file: | ||
| 65 | lineno += 1 | ||
| 66 | if not line or "BB_RENAMED_VARIABLE" in line: | ||
| 67 | continue | ||
| 68 | # Do the renames | ||
| 69 | for old_name, new_name in renames.items(): | ||
| 70 | if old_name in line: | ||
| 71 | line = line.replace(old_name, new_name) | ||
| 72 | modified = True | ||
| 73 | # Find removed names | ||
| 74 | for removed_name in removed_list: | ||
| 75 | if removed_name in line: | ||
| 76 | print("%s needs further work at line %s because has been deprecated" % (fn, lineno, remove_name)) | ||
| 77 | for check_word in context_check_list: | ||
| 78 | if re.search(check_word, line, re.IGNORECASE): | ||
| 79 | print("%s needs further work at line %s since it contains %s"% (fn, lineno, check_word)) | ||
| 80 | new_file.write(line) | ||
| 81 | if modified: | ||
| 82 | print("*** Modified file '%s'" % (fn)) | ||
| 83 | shutil.copymode(fn, abs_path) | ||
| 84 | os.remove(fn) | ||
| 85 | shutil.move(abs_path, fn) | ||
| 86 | except UnicodeDecodeError: | ||
| 87 | pass | ||
| 88 | |||
| 89 | ourname = os.path.basename(sys.argv[0]) | ||
| 90 | ourversion = "0.1" | ||
| 91 | |||
| 92 | if os.path.isfile(sys.argv[1]): | ||
| 93 | processfile(sys.argv[1]) | ||
| 94 | sys.exit(0) | ||
| 95 | |||
| 96 | for targetdir in sys.argv[1:]: | ||
| 97 | print("processing directory '%s'" % targetdir) | ||
| 98 | for root, dirs, files in os.walk(targetdir): | ||
| 99 | for name in files: | ||
| 100 | if name == ourname: | ||
| 101 | continue | ||
| 102 | fn = os.path.join(root, name) | ||
| 103 | if os.path.islink(fn): | ||
| 104 | continue | ||
| 105 | if "ChangeLog" in fn or "/.git/" in fn or fn.endswith(".html") or fn.endswith(".patch") or fn.endswith(".m4") or fn.endswith(".diff") or fn.endswith(".orig"): | ||
| 106 | continue | ||
| 107 | processfile(fn) | ||
| 108 | |||
| 109 | print("All files processed with version %s" % ourversion) | ||
