11 def FindClangSpecs(path):
12 for root, dirs, files in os.walk(path):
14 if f.endswith(".xcspec") and f.startswith("Clang LLVM"):
15 yield os.path.join(root, f)
17 def ModifySpec(path, pathToChecker):
18 t = tempfile.NamedTemporaryFile(delete=False)
23 if line.find("Static Analyzer") >= 0:
26 m = re.search('^(\s*ExecPath\s*=\s*")', line)
28 line = "".join([m.group(0), pathToChecker, '";\n'])
31 print "(+) processing:", path
33 shutil.copy(t.name, path)
34 os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
36 print " (-) Cannot update file:", why, "\n"
38 print " (-) Cannot update file:", why, "\n"
42 from optparse import OptionParser
43 parser = OptionParser('usage: %prog [options]')
44 parser.set_description(__doc__)
45 parser.add_option("--use-checker-build", dest="path",
46 help="Use the Clang located at the provided absolute path, e.g. /Users/foo/checker-1")
47 parser.add_option("--use-xcode-clang", action="store_const",
48 const="$(CLANG)", dest="default",
49 help="Use the Clang bundled with Xcode")
50 (options, args) = parser.parse_args()
51 if options.path is None and options.default is None:
52 parser.error("You must specify a version of Clang to use for static analysis. Specify '-h' for details")
54 # determine if Xcode is running
55 for x in NSWorkspace.sharedWorkspace().runningApplications():
56 if x.localizedName().find("Xcode") >= 0:
57 print "(-) You must quit Xcode first before modifying its configuration files."
62 path = os.path.expanduser(options.path)
63 if not path.endswith("clang"):
64 print "(+) Using Clang bundled with checker build:", path
65 path = os.path.join(path, "bin", "clang");
67 print "(+) Using Clang located at:", path
69 print "(+) Using the Clang bundled with Xcode"
70 path = options.default
72 for x in FindClangSpecs('/Developer'):
75 if __name__ == '__main__':