summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSaul Wold <Saul.Wold@windriver.com>2022-02-16 16:32:48 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-02-21 23:37:27 +0000
commit5a3d6c7bda0f158473c82d1c38ae2df26192dccb (patch)
tree0a965c917fdafbea0f4ae72ca1e3163a1bb0963f /scripts
parent1d7e1e4f632aca721d54ad21c8494db65e8cf36e (diff)
downloadpoky-5a3d6c7bda0f158473c82d1c38ae2df26192dccb.tar.gz
scripts: Add convert-variable-renames script for inclusive language variable renaming
This script searches for a list of variable that have been renamed and converts them to their more descriptive names. It also searches for a list of variables that have been removed or deprecated and prints a message. It will print a message to inform the user that there are terms that need to be updated in their files. Many of these changes are context sensitive and may not be modified as they might be existing calls to other libraries. This message is informational only. I have tested this on poky and meta-openembedded so far. (From OE-Core rev: 50fe7ba8dba05a9681c9095506f798796cfc2750) (From OE-Core rev: 75f319c105484d0b312a858cc0bd8148728c8622) Signed-off-by: Saul Wold <saul.wold@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/contrib/convert-variable-renames.py109
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
12import re
13import os
14import sys
15import tempfile
16import shutil
17import mimetypes
18
19if len(sys.argv) < 2:
20 print("Please specify a directory to run the conversion script against.")
21 sys.exit(1)
22
23renames = {
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
42removed_list = [
43"BB_STAMP_WHITELIST",
44"BB_STAMP_POLICY",
45"INHERIT_BLACKLIST",
46"TUNEABI_WHITELIST",
47]
48
49context_check_list = [
50"blacklist",
51"whitelist",
52"abort",
53]
54
55def 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
89ourname = os.path.basename(sys.argv[0])
90ourversion = "0.1"
91
92if os.path.isfile(sys.argv[1]):
93 processfile(sys.argv[1])
94 sys.exit(0)
95
96for 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
109print("All files processed with version %s" % ourversion)