1 """Contains helper functions to compute checksums for LLVM checkouts.
3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
13 class LLVMProject(object):
14 """An LLVM project with a descriptive name and a relative checkout path.
17 def __init__(self
, name
, relpath
):
19 self
.relpath
= relpath
21 def is_subproject(self
, other_project
):
22 """ Check if self is checked out as a subdirectory of other_project.
24 return self
.relpath
.startswith(other_project
.relpath
)
27 def WalkProjectFiles(checkout_root
, all_projects
, project
, visitor
):
28 """ Walk over all files inside a project without recursing into subprojects, '.git' and '.svn' subfolders.
30 checkout_root: root of the LLVM checkout.
31 all_projects: projects in the LLVM checkout.
32 project: a project to walk the files of. Must be inside all_projects.
33 visitor: a function called on each visited file.
35 assert project
in all_projects
38 for other_project
in all_projects
:
39 if other_project
!= project
and other_project
.is_subproject(project
):
40 ignored_paths
.add(os
.path
.join(checkout_root
, other_project
.relpath
))
45 project_root
= os
.path
.join(checkout_root
, project
.relpath
)
46 for root
, dirs
, files
in os
.walk(project_root
, onerror
=raise_error
):
49 if d
!= ".svn" and d
!= ".git" and
50 os
.path
.join(root
, d
) not in ignored_paths
53 visitor(os
.path
.join(root
, f
))
56 def CreateLLVMProjects(single_tree_checkout
):
57 """Returns a list of LLVMProject instances, describing relative paths of a typical LLVM checkout.
61 When True, relative paths for each project points to a typical single
63 When False, relative paths for each projects points to a separate
64 directory. However, clang-tools-extra is an exception, its relative path
65 will always be 'clang/tools/extra'.
67 # FIXME: cover all of llvm projects.
69 # Projects that reside inside 'projects/' in a single source tree checkout.
71 "compiler-rt", "dragonegg", "libcxx", "libcxxabi", "libunwind",
72 "parallel-libs", "test-suite"
74 # Projects that reside inside 'tools/' in a single source tree checkout.
75 TOOLS_PROJECTS
= ["clang", "lld", "lldb", "llgo"]
77 if single_tree_checkout
:
78 projects
= [LLVMProject("llvm", "")]
80 LLVMProject(p
, os
.path
.join("projects", p
)) for p
in ORDINARY_PROJECTS
83 LLVMProject(p
, os
.path
.join("tools", p
)) for p
in TOOLS_PROJECTS
86 LLVMProject("clang-tools-extra",
87 os
.path
.join("tools", "clang", "tools", "extra")))
89 projects
= [LLVMProject("llvm", "llvm")]
90 projects
+= [LLVMProject(p
, p
) for p
in ORDINARY_PROJECTS
]
91 projects
+= [LLVMProject(p
, p
) for p
in TOOLS_PROJECTS
]
93 LLVMProject("clang-tools-extra", os
.path
.join("clang", "tools",