OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2017 the V8 project authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 """\ | |
6 Convenience script for generating arch-specific ctags file. | |
7 This script MUST be executed at the top directory. | |
8 | |
9 Usage: | |
10 $ tools/dev/gen-tags.py [<arch>...] | |
11 | |
12 The example usage is as follows: | |
13 $ tools/dev/gen-tags.py x64 | |
14 | |
15 If no <arch> is given, it generates tags file for all arches: | |
16 $ tools/dev/gen-tags.py | |
17 """ | |
18 import os | |
19 import subprocess | |
20 import sys | |
21 from itertools import chain | |
22 | |
23 # All arches that this script understands. | |
24 ARCHES = ["ia32", "x64", "arm", "arm64", "mips", "mips64", "ppc", "s390", "x87"] | |
25 | |
26 def PrintHelpAndExit(): | |
27 print(__doc__) | |
28 sys.exit(0) | |
29 | |
30 def _Call(cmd, silent=False): | |
31 if not silent: print("# %s" % cmd) | |
32 return subprocess.call(cmd, shell=True) | |
33 | |
34 class ArgumentParser(object): | |
35 def __init__(self): | |
Jakob Kummerow
2017/03/22 12:11:09
You don't need this constructor.
honggyu.kim
2017/03/22 15:19:15
Done.
| |
36 self.global_targets = set() | |
37 self.configs = {} | |
38 | |
39 def ParseArg(self, argstring): | |
40 if argstring in ("-h", "--help", "help"): | |
41 PrintHelpAndExit() | |
42 return argstring | |
43 | |
44 def ParseArguments(self, argv): | |
45 if not "tools/dev" in argv[0]: | |
46 PrintHelpAndExit() | |
47 argv = argv[1:] | |
48 | |
49 # If no argument is given, then generate ctags for all arches. | |
50 if len(argv) == 0: | |
51 return ARCHES | |
52 | |
53 user_arches = [] | |
54 for argstring in argv: | |
55 user_arches.append(self.ParseArg(argstring)) | |
Jakob Kummerow
2017/03/22 12:11:09
If you inline ParseArg here, you don't need the cl
honggyu.kim
2017/03/22 15:19:15
Done.
| |
56 | |
57 return user_arches | |
58 | |
59 def Main(argv): | |
60 user_arches = [] | |
61 | |
62 parser = ArgumentParser() | |
63 user_arches = parser.ParseArguments(argv) | |
64 | |
65 exclude_arches = list(ARCHES) | |
66 for user_arch in user_arches: | |
67 exclude_arches.remove(user_arch) | |
68 | |
69 paths = ["include", "src", "test"] | |
70 exts = [".h", ".cc", ".c"] | |
71 | |
72 gtags_filename = "gtags.files" | |
73 gtags = open(gtags_filename, "w") | |
Jakob Kummerow
2017/03/22 12:11:10
instead of a manual open/close pair, please use a
honggyu.kim
2017/03/22 15:19:15
Done.
| |
74 | |
75 # Generate a list of files to be analyzed | |
76 for root, dirs, files in chain.from_iterable(os.walk(path) for path in paths): | |
77 for file in files: | |
78 if file.endswith(tuple(exts)): | |
79 fullpath = os.path.join(root, file) | |
80 exclude_flag = False | |
Jakob Kummerow
2017/03/22 12:11:09
A more Pythonic way would be to pull out the inner
honggyu.kim
2017/03/22 15:19:15
Done.
| |
81 for arch in exclude_arches: | |
82 arch = "/%s/" % arch | |
83 if arch in fullpath: | |
84 exclude_flag = True | |
85 break | |
86 if not exclude_flag: | |
87 gtags.write(os.path.join(root, file) + os.linesep) | |
88 | |
89 gtags.close() | |
90 | |
91 command = "ctags --fields=+l -L " + gtags_filename | |
Jakob Kummerow
2017/03/22 12:11:09
nit: just inline this into _Call() below, it's cle
honggyu.kim
2017/03/22 15:19:15
Done.
| |
92 _Call(command) | |
93 | |
94 if __name__ == "__main__": | |
95 sys.exit(Main(sys.argv)) | |
OLD | NEW |