project_tree.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. """Contains helper functions to compute checksums for LLVM checkouts.
  2. """
  3. from __future__ import absolute_import
  4. from __future__ import division
  5. from __future__ import print_function
  6. import logging
  7. import os
  8. import os.path
  9. import sys
  10. class LLVMProject(object):
  11. """An LLVM project with a descriptive name and a relative checkout path.
  12. """
  13. def __init__(self, name, relpath):
  14. self.name = name
  15. self.relpath = relpath
  16. def is_subproject(self, other_project):
  17. """ Check if self is checked out as a subdirectory of other_project.
  18. """
  19. return self.relpath.startswith(other_project.relpath)
  20. def WalkProjectFiles(checkout_root, all_projects, project, visitor):
  21. """ Walk over all files inside a project without recursing into subprojects, '.git' and '.svn' subfolders.
  22. checkout_root: root of the LLVM checkout.
  23. all_projects: projects in the LLVM checkout.
  24. project: a project to walk the files of. Must be inside all_projects.
  25. visitor: a function called on each visited file.
  26. """
  27. assert project in all_projects
  28. ignored_paths = set()
  29. for other_project in all_projects:
  30. if other_project != project and other_project.is_subproject(project):
  31. ignored_paths.add(os.path.join(checkout_root, other_project.relpath))
  32. def raise_error(err):
  33. raise err
  34. project_root = os.path.join(checkout_root, project.relpath)
  35. for root, dirs, files in os.walk(project_root, onerror=raise_error):
  36. dirs[:] = [
  37. d for d in dirs
  38. if d != ".svn" and d != ".git" and
  39. os.path.join(root, d) not in ignored_paths
  40. ]
  41. for f in files:
  42. visitor(os.path.join(root, f))
  43. def CreateLLVMProjects(single_tree_checkout):
  44. """Returns a list of LLVMProject instances, describing relative paths of a typical LLVM checkout.
  45. Args:
  46. single_tree_checkout:
  47. When True, relative paths for each project points to a typical single
  48. source tree checkout.
  49. When False, relative paths for each projects points to a separate
  50. directory. However, clang-tools-extra is an exception, its relative path
  51. will always be 'clang/tools/extra'.
  52. """
  53. # FIXME: cover all of llvm projects.
  54. # Projects that reside inside 'projects/' in a single source tree checkout.
  55. ORDINARY_PROJECTS = [
  56. "compiler-rt", "dragonegg", "libcxx", "libcxxabi", "libunwind",
  57. "parallel-libs", "test-suite"
  58. ]
  59. # Projects that reside inside 'tools/' in a single source tree checkout.
  60. TOOLS_PROJECTS = ["clang", "lld", "lldb", "llgo"]
  61. if single_tree_checkout:
  62. projects = [LLVMProject("llvm", "")]
  63. projects += [
  64. LLVMProject(p, os.path.join("projects", p)) for p in ORDINARY_PROJECTS
  65. ]
  66. projects += [
  67. LLVMProject(p, os.path.join("tools", p)) for p in TOOLS_PROJECTS
  68. ]
  69. projects.append(
  70. LLVMProject("clang-tools-extra",
  71. os.path.join("tools", "clang", "tools", "extra")))
  72. else:
  73. projects = [LLVMProject("llvm", "llvm")]
  74. projects += [LLVMProject(p, p) for p in ORDINARY_PROJECTS]
  75. projects += [LLVMProject(p, p) for p in TOOLS_PROJECTS]
  76. projects.append(
  77. LLVMProject("clang-tools-extra", os.path.join("clang", "tools",
  78. "extra")))
  79. return projects