[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / llvm / utils / wciia.py
blob7240d3c2a9ff24439e7bf7c3996bf13955c91297
1 #!/usr/bin/env python
2 """
3 wciia - Whose Code Is It Anyway
5 Determines code owner of the file/folder relative to the llvm source root.
6 Code owner is determined from the content of the CODE_OWNERS.TXT
7 by parsing the D: field
9 usage:
11 utils/wciia.py path
13 limitations:
14 - must be run from llvm source root
15 - very simplistic algorithm
16 - only handles * as a wildcard
17 - not very user friendly
18 - does not handle the proposed F: field
20 """
22 from __future__ import print_function
23 import os
25 code_owners = {}
28 def process_files_and_folders(owner):
29 filesfolders = owner["filesfolders"]
30 # paths must be in ( ... ) so strip them
31 lpar = filesfolders.find("(")
32 rpar = filesfolders.rfind(")")
33 if rpar <= lpar:
34 # give up
35 return
36 paths = filesfolders[lpar + 1 : rpar]
37 # split paths
38 owner["paths"] = []
39 for path in paths.split():
40 owner["paths"].append(path)
43 def process_code_owner(owner):
44 if "filesfolders" in owner:
45 filesfolders = owner["filesfolders"]
46 else:
47 # print "F: field missing, using D: field"
48 owner["filesfolders"] = owner["description"]
49 process_files_and_folders(owner)
50 code_owners[owner["name"]] = owner
53 # process CODE_OWNERS.TXT first
54 code_owners_file = open("CODE_OWNERS.TXT", "r").readlines()
55 code_owner = {}
56 for line in code_owners_file:
57 for word in line.split():
58 if word == "N:":
59 name = line[2:].strip()
60 if code_owner:
61 process_code_owner(code_owner)
62 code_owner = {}
63 # reset the values
64 code_owner["name"] = name
65 if word == "E:":
66 email = line[2:].strip()
67 code_owner["email"] = email
68 if word == "D:":
69 description = line[2:].strip()
70 code_owner["description"] = description
71 if word == "F:":
72 filesfolders = line[2:].strip()
73 code_owner["filesfolders"].append(filesfolders)
76 def find_owners(fpath):
77 onames = []
78 lmatch = -1
79 # very simplistic way of findning the best match
80 for name in code_owners:
81 owner = code_owners[name]
82 if "paths" in owner:
83 for path in owner["paths"]:
84 # print "searching (" + path + ")"
85 # try exact match
86 if fpath == path:
87 return name
88 # see if path ends with a *
89 rstar = path.rfind("*")
90 if rstar > 0:
91 # try the longest match,
92 rpos = -1
93 if len(fpath) < len(path):
94 rpos = path.find(fpath)
95 if rpos == 0:
96 onames.append(name)
97 onames.append("Chris Lattner")
98 return onames
101 # now lest try to find the owner of the file or folder
102 import sys
104 if len(sys.argv) < 2:
105 print("usage " + sys.argv[0] + " file_or_folder")
106 exit(-1)
108 # the path we are checking
109 path = str(sys.argv[1])
111 # check if this is real path
112 if not os.path.exists(path):
113 print("path (" + path + ") does not exist")
114 exit(-1)
116 owners_name = find_owners(path)
118 # be grammatically correct
119 print("The owner(s) of the (" + path + ") is(are) : " + str(owners_name))
121 exit(0)
123 # bottom up walk of the current .
124 # not yet used
125 root = "."
126 for dir, subdirList, fileList in os.walk(root, topdown=False):
127 print("dir :", dir)
128 for fname in fileList:
129 print("-", fname)
130 print()