diff options
Diffstat (limited to 'modules/llvm.py')
-rw-r--r-- | modules/llvm.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/modules/llvm.py b/modules/llvm.py index 8d549fd..2625038 100644 --- a/modules/llvm.py +++ b/modules/llvm.py @@ -1,6 +1,8 @@ import os import re +from functools import partial + from linaropy.git.worktree import Worktree @@ -98,6 +100,10 @@ class LLVMSourceConfig(object): self.llvmSourceTree = Worktree(proj, sourcePath) self.subprojs = subprojs + def get_path(self): + """Get the path corresponding to this source config.""" + return self.llvmSourceTree.repodir + def get_enabled_subprojects(self): """Get a list of the subprojects enabled in this configuration.""" enabled = [] @@ -263,6 +269,63 @@ class LLVMSourceConfig(object): worktree.clean(False) +class LLVMBuildConfig(object): + """Class for managing an LLVM build directory. + + It should know how to configure a build directory (with CMake) and how to + run a build command. The directory must already exist, but it may be empty. + """ + + def __init__(self, sourceConfig, buildDir=None): + """Create an LLVMBuildConfig.""" + self.sourceConfig = sourceConfig + self.buildDir = buildDir + + def cmake(self, commandConsumer, cmakeFlags, generator): + """ + Generate the CMake command needed for configuring the build directory + with the given flags and generator, and pass it to the 'commandConsumer'. + + The command will always explicitly enable or disable the build of + specific subprojects to mirror the source config. This is important + because projects can always be added or removed from the source config, + and CMake doesn't by default pick up the new situation (so we might end + up trying to build subprojects that were removed, or not build + subprojects that were added). + + The 'commandConsumer' should have a 'consume' method taking two + parameters: the command to be consumed (in the form of a list) and the + directory where the command should be run. Any exceptions that may be + raised by that method should be handled by the calling code. + """ + cmakeSubprojFlags = self.__get_subproj_flags() + command = ["cmake", "-G", generator] + cmakeSubprojFlags + \ + cmakeFlags + [self.sourceConfig.get_path()] + commandConsumer.consume(command, self.buildDir) + + def __get_subproj_flags(self): + """ + Get the CMake flags needed to explicitly enable or disable the build of + each specific subproject, depending on whether it is enabled or disabled + in the source config. + """ + def append_cmake_var(cmakeVars, subproj, enabled): + if subproj.cmake_var is None: + return + + if enabled: + status = "ON" + else: + status = "OFF" + cmakeVars.append("-D{}={}".format(subproj.cmake_var, status)) + + cmakeSubprojFlags = [] + self.sourceConfig.for_each_subproj(partial(append_cmake_var, + cmakeSubprojFlags)) + + return cmakeSubprojFlags + + # FIXME: repo.pushToBranch doesn't work, because it doesn't handle remote # branches properly. Furthermore, there's no support for getting the remote URL, # so we need to resort to raw git commands. We may also consider moving the |