diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-08 20:54:01 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-08 20:54:01 +0000 |
commit | 94c5349ef2a609ea161e65b9d01a65af77de32a2 (patch) | |
tree | a97b369ccbe9803082fd6e532892f171a93b87d4 | |
parent | bd374da130b9f1835e666088bb9c241e2bfce74b (diff) | |
download | bcm5719-llvm-94c5349ef2a609ea161e65b9d01a65af77de32a2.tar.gz bcm5719-llvm-94c5349ef2a609ea161e65b9d01a65af77de32a2.zip |
Add a Python script to change what version of Clang is used by Xcode for static analysis (and ONLY static analysis).
llvm-svn: 95569
-rwxr-xr-x | clang/tools/scan-build/set-xcode-analyzer | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/clang/tools/scan-build/set-xcode-analyzer b/clang/tools/scan-build/set-xcode-analyzer new file mode 100755 index 00000000000..c8229da7f3c --- /dev/null +++ b/clang/tools/scan-build/set-xcode-analyzer @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import os +import sys +import re +import tempfile +import shutil +import stat + +def FindClangSpecs(path): + for root, dirs, files in os.walk(path): + for f in files: + if f.endswith(".xcspec") and f.startswith("Clang LLVM"): + yield os.path.join(root, f) + +def ModifySpec(path, pathToChecker): + print "Updating:", path + t = tempfile.NamedTemporaryFile(delete=False) + foundAnalyzer = False + with open(path) as f: + for line in f: + if not foundAnalyzer: + if line.find("Static Analyzer") >= 0: + foundAnalyzer = True + else: + m = re.search('^(\s*ExecPath\s*=\s*")', line) + if m: + line = "".join([m.group(0), pathToChecker, '";\n']) + t.write(line) + t.close() + shutil.copy(t.name, path) + os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) + os.unlink(t.name) + +def main(): + from optparse import OptionParser + parser = OptionParser('usage: %prog [options]') + parser.set_description(__doc__) + parser.add_option("--use-checker-build", dest="path", + help="Use the Clang located at the provided absolute path, e.g. /Users/foo/checker-1") + parser.add_option("--use-xcode-clang", action="store_const", + const="$(CLANG)", dest="default", + help="Use the Clang bundled with Xcode") + (options, args) = parser.parse_args() + if options.path is None and options.default is None: + parser.error("You must specify a version of Clang to use for static analysis. Specify '-h' for details") + + if options.path: + # Expand tildes. + path = os.path.expanduser(options.path) + if not path.endswith("clang"): + print "Using Clang bundled with checker build:", path + path = os.path.join(path, "bin", "clang"); + else: + print "Using Clang located at:", path + else: + print "Using the Clang bundled with Xcode" + path = options.default + + for x in FindClangSpecs('/Developer'): + ModifySpec(x, path) + +if __name__ == '__main__': + main() + |