6 class LLVMProjectInfo(object):
8 def load_infos_from_path(llvmbuild_source_root):
9 # FIXME: Implement a simple subpath file list cache, so we don't restat
10 # directories we have already traversed.
12 # First, discover all the LLVMBuild.txt files.
13 for dirpath,dirnames,filenames in os.walk(llvmbuild_source_root,
15 # If there is no LLVMBuild.txt file in a directory, we don't recurse
16 # past it. This is a simple way to prune our search, although it
17 # makes it easy for users to add LLVMBuild.txt files in places they
19 if 'LLVMBuild.txt' not in filenames:
23 # Otherwise, load the LLVMBuild file in this directory.
24 assert dirpath.startswith(llvmbuild_source_root)
25 subpath = '/' + dirpath[len(llvmbuild_source_root)+1:]
26 llvmbuild_path = os.path.join(dirpath, 'LLVMBuild.txt')
27 for info in componentinfo.load_from_path(llvmbuild_path, subpath):
31 def load_from_path(source_root, llvmbuild_source_root):
33 LLVMProjectInfo.load_infos_from_path(llvmbuild_source_root))
35 return LLVMProjectInfo(source_root, infos)
37 def __init__(self, source_root, component_infos):
38 self.source_root = source_root
39 self.component_infos = component_infos
42 from optparse import OptionParser, OptionGroup
43 parser = OptionParser("usage: %prog [options]")
44 parser.add_option("", "--source-root", dest="source_root", metavar="PATH",
45 help="Path to the LLVM source (inferred if not given)",
46 action="store", default=None)
48 "", "--llvmbuild-source-root", dest="llvmbuild_source_root",
49 help="If given, an alternate path to search for LLVMBuild.txt files",
50 action="store", default=None, metavar="PATH")
51 (opts, args) = parser.parse_args()
53 # Determine the LLVM source path, if not given.
54 source_root = opts.source_root
56 if not os.path.exists(os.path.join(source_root, 'lib', 'VMCore',
58 parser.error('invalid LLVM source root: %r' % source_root)
60 llvmbuild_path = os.path.dirname(__file__)
61 llvm_build_path = os.path.dirname(llvmbuild_path)
62 utils_path = os.path.dirname(llvm_build_path)
63 source_root = os.path.dirname(utils_path)
64 if not os.path.exists(os.path.join(source_root, 'lib', 'VMCore',
66 parser.error('unable to infer LLVM source root, please specify')
68 # Construct the LLVM project information.
69 llvmbuild_source_root = opts.llvmbuild_source_root or source_root
70 project_info = LLVMProjectInfo.load_from_path(
71 source_root, llvmbuild_source_root)
73 if __name__=='__main__':