[llvm-commits] [llvm] r146437 - in /llvm/trunk: docs/LLVMBuild.html utils/llvm-build/llvmbuild/componentinfo.py utils/llvm-build/llvmbuild/main.py

Daniel Dunbar daniel at zuster.org
Mon Dec 12 14:45:59 PST 2011


Author: ddunbar
Date: Mon Dec 12 16:45:59 2011
New Revision: 146437

URL: http://llvm.org/viewvc/llvm-project?rev=146437&view=rev
Log:
llvm-build: Switch to using the common subdirectory list instead of
autodiscovery.

Modified:
    llvm/trunk/docs/LLVMBuild.html
    llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py
    llvm/trunk/utils/llvm-build/llvmbuild/main.py

Modified: llvm/trunk/docs/LLVMBuild.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LLVMBuild.html?rev=146437&r1=146436&r2=146437&view=diff
==============================================================================
--- llvm/trunk/docs/LLVMBuild.html (original)
+++ llvm/trunk/docs/LLVMBuild.html Mon Dec 12 16:45:59 2011
@@ -147,7 +147,7 @@
 <i>; Comments start with a semi-colon.</i>
 
 <i>; Sections are declared using square brackets.</i>
-[component 0]
+[component_0]
 
 <i>; Properties are declared using '=' and are contained in the previous section.
 ;
@@ -160,7 +160,7 @@
 </pre>
   </div>
 
-  <p>LLVMBuild files are expected to define a strict set of section and
+  <p>LLVMBuild files are expected to define a strict set of sections and
   properties. An typical component description file for a library
   component would look typically look like the following example:</p>
   <div class="doc_code">
@@ -176,14 +176,22 @@
   <p>A full description of the exact sections and properties which are allowed
  follows.</p>
 
+  <p>Each file may define exactly one common component, named "common". The
+  common component may define the following properties:</p>
+  <ul>
+    <li><i>subdirectories</i> <b>[optional]</b>
+      <p>If given, a list of the names of the subdirectories from the current
+        subpath to search for additional LLVMBuild files.</p></li>
+  </ul>
+
   <p>Each file may define multiple components. Each component is described by a
   section who name starts with "component". The remainder of the section name is
   ignored, but each section name must be unique. Typically components are just
   number in order for files with multiple components ("component_0",
   "component_1", and so on).<p>
 
-  <p><b>Section names not matches this format are currently
-  unused and are disallowed.</b></p>
+  <p><b>Section names not matches this format (or the "common" section) are
+  currently unused and are disallowed.</b></p>
 
   <p>Every component is defined by the properties in the section. The exact list
   of properties that are allowed depends on the component

Modified: llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py?rev=146437&r1=146436&r2=146437&view=diff
==============================================================================
--- llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py (original)
+++ llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py Mon Dec 12 16:45:59 2011
@@ -381,6 +381,16 @@
     parser = ConfigParser.RawConfigParser()
     parser.read(path)
 
+    # Extract the common section.
+    if parser.has_section("common"):
+        common = IniFormatParser(parser.items("common"))
+        parser.remove_section("common")
+    else:
+        common = IniFormatParser({})
+
+    return common, _read_components_from_parser(parser, path, subpath)
+
+def _read_components_from_parser(parser, path, subpath):
     # We load each section which starts with 'component' as a distinct component
     # description (so multiple components can be described in one file).
     for section in parser.sections():

Modified: llvm/trunk/utils/llvm-build/llvmbuild/main.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/llvm-build/llvmbuild/main.py?rev=146437&r1=146436&r2=146437&view=diff
==============================================================================
--- llvm/trunk/utils/llvm-build/llvmbuild/main.py (original)
+++ llvm/trunk/utils/llvm-build/llvmbuild/main.py Mon Dec 12 16:45:59 2011
@@ -64,31 +64,25 @@
 class LLVMProjectInfo(object):
     @staticmethod
     def load_infos_from_path(llvmbuild_source_root):
-        # FIXME: Implement a simple subpath file list cache, so we don't restat
-        # directories we have already traversed.
+        def recurse(subpath):
+            # Load the LLVMBuild file.
+            llvmbuild_path = os.path.join(llvmbuild_source_root + subpath,
+                                          'LLVMBuild.txt')
+            if not os.path.exists(llvmbuild_path):
+                fatal("missing LLVMBuild.txt file at: %r" % (llvmbuild_path,))
+
+            # Parse the components from it.
+            common,info_iter = componentinfo.load_from_path(llvmbuild_path,
+                                                            subpath)
+            for info in info_iter:
+                yield info
 
-        # First, discover all the LLVMBuild.txt files.
-        #
-        # FIXME: We would like to use followlinks=True here, but that isn't
-        # compatible with Python 2.4. Instead, we will either have to special
-        # case projects we would expect to possibly be linked to, or implement
-        # our own walk that can follow links. For now, it doesn't matter since
-        # we haven't picked up the LLVMBuild system in any other LLVM projects.
-        for dirpath,dirnames,filenames in os.walk(llvmbuild_source_root):
-            # If there is no LLVMBuild.txt file in a directory, we don't recurse
-            # past it. This is a simple way to prune our search, although it
-            # makes it easy for users to add LLVMBuild.txt files in places they
-            # won't be seen.
-            if 'LLVMBuild.txt' not in filenames:
-                del dirnames[:]
-                continue
+            # Recurse into the specified subdirectories.
+            for subdir in common.get_list("subdirectories"):
+                for item in recurse(os.path.join(subpath, subdir)):
+                    yield item
 
-            # Otherwise, load the LLVMBuild file in this directory.
-            assert dirpath.startswith(llvmbuild_source_root)
-            subpath = '/' + dirpath[len(llvmbuild_source_root)+1:]
-            llvmbuild_path = os.path.join(dirpath, 'LLVMBuild.txt')
-            for info in componentinfo.load_from_path(llvmbuild_path, subpath):
-                yield info
+        return recurse("/")
 
     @staticmethod
     def load_from_path(source_root, llvmbuild_source_root):





More information about the llvm-commits mailing list