Chromium Code Reviews| Index: tools/dev/gen-tags.py |
| diff --git a/tools/dev/gen-tags.py b/tools/dev/gen-tags.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..3d0aa8ba889c65587f0204b0569e426eb21c1a1e |
| --- /dev/null |
| +++ b/tools/dev/gen-tags.py |
| @@ -0,0 +1,95 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2017 the V8 project authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +"""\ |
| +Convenience script for generating arch-specific ctags file. |
| +This script MUST be executed at the top directory. |
| + |
| +Usage: |
| + $ tools/dev/gen-tags.py [<arch>...] |
| + |
| +The example usage is as follows: |
| + $ tools/dev/gen-tags.py x64 |
| + |
| +If no <arch> is given, it generates tags file for all arches: |
| + $ tools/dev/gen-tags.py |
| +""" |
| +import os |
| +import subprocess |
| +import sys |
| +from itertools import chain |
| + |
| +# All arches that this script understands. |
| +ARCHES = ["ia32", "x64", "arm", "arm64", "mips", "mips64", "ppc", "s390", "x87"] |
| + |
| +def PrintHelpAndExit(): |
| + print(__doc__) |
| + sys.exit(0) |
| + |
| +def _Call(cmd, silent=False): |
| + if not silent: print("# %s" % cmd) |
| + return subprocess.call(cmd, shell=True) |
| + |
| +class ArgumentParser(object): |
| + 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.
|
| + self.global_targets = set() |
| + self.configs = {} |
| + |
| + def ParseArg(self, argstring): |
| + if argstring in ("-h", "--help", "help"): |
| + PrintHelpAndExit() |
| + return argstring |
| + |
| + def ParseArguments(self, argv): |
| + if not "tools/dev" in argv[0]: |
| + PrintHelpAndExit() |
| + argv = argv[1:] |
| + |
| + # If no argument is given, then generate ctags for all arches. |
| + if len(argv) == 0: |
| + return ARCHES |
| + |
| + user_arches = [] |
| + for argstring in argv: |
| + 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.
|
| + |
| + return user_arches |
| + |
| +def Main(argv): |
| + user_arches = [] |
| + |
| + parser = ArgumentParser() |
| + user_arches = parser.ParseArguments(argv) |
| + |
| + exclude_arches = list(ARCHES) |
| + for user_arch in user_arches: |
| + exclude_arches.remove(user_arch) |
| + |
| + paths = ["include", "src", "test"] |
| + exts = [".h", ".cc", ".c"] |
| + |
| + gtags_filename = "gtags.files" |
| + 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.
|
| + |
| + # Generate a list of files to be analyzed |
| + for root, dirs, files in chain.from_iterable(os.walk(path) for path in paths): |
| + for file in files: |
| + if file.endswith(tuple(exts)): |
| + fullpath = os.path.join(root, file) |
| + 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.
|
| + for arch in exclude_arches: |
| + arch = "/%s/" % arch |
| + if arch in fullpath: |
| + exclude_flag = True |
| + break |
| + if not exclude_flag: |
| + gtags.write(os.path.join(root, file) + os.linesep) |
| + |
| + gtags.close() |
| + |
| + 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.
|
| + _Call(command) |
| + |
| +if __name__ == "__main__": |
| + sys.exit(Main(sys.argv)) |