diff --git a/llvm/test/LLVMBuild/enabled/Input/LLVMBuild.txt b/llvm/test/LLVMBuild/enabled/Input/LLVMBuild.txt new file mode 100644 --- /dev/null +++ b/llvm/test/LLVMBuild/enabled/Input/LLVMBuild.txt @@ -0,0 +1,48 @@ +;===- ./LLVMBuild.txt ------------------------------------------*- Conf -*--===; +; +; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +; See https://llvm.org/LICENSE.txt for license information. +; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[common] +subdirectories = lib + +[component_0] +type = LibraryGroup +name = Engine +parent = $ROOT + +[component_1] +type = Library +name = Interpreter +parent = $ROOT + +[component_2] +type = Group +name = Miscellaneous +parent = $ROOT + +[component_3] +type = LibraryGroup +name = Native +parent = $ROOT + +[component_4] +type = LibraryGroup +name = NativeCodeGen +parent = $ROOT + +[component_5] +type = LibraryGroup +name = all-targets +parent = $ROOT diff --git a/llvm/test/LLVMBuild/enabled/Input/lib/IR/Function.cpp b/llvm/test/LLVMBuild/enabled/Input/lib/IR/Function.cpp new file mode 100644 diff --git a/llvm/test/LLVMBuild/enabled/Input/lib/LLVMBuild.txt b/llvm/test/LLVMBuild/enabled/Input/lib/LLVMBuild.txt new file mode 100644 --- /dev/null +++ b/llvm/test/LLVMBuild/enabled/Input/lib/LLVMBuild.txt @@ -0,0 +1,37 @@ +;===- ./LLVMBuild.txt ------------------------------------------*- Conf -*--===; +; +; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +; See https://llvm.org/LICENSE.txt for license information. +; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = OptionalLibrary +name = DisabledByCmdLib +enabled_component = 1 +parent = $ROOT + +[component_1] +type = OptionalLibrary +name = DisabledDefaultLib +parent = $ROOT + +[component_2] +type = OptionalLibrary +name = EnabledByCmdLib +parent = $ROOT + +[component_3] +type = OptionalLibrary +name = EnabledDefaultLib +enabled_component = 1 +parent = $ROOT diff --git a/llvm/test/LLVMBuild/enabled/enabled.test b/llvm/test/LLVMBuild/enabled/enabled.test new file mode 100644 --- /dev/null +++ b/llvm/test/LLVMBuild/enabled/enabled.test @@ -0,0 +1,24 @@ +RUN: %llvmbuild --source-root=%S/Input --write-llvmbuild=%T --enable-optional-components=EnabledByCmdLib +RUN: FileCheck %s < %T/lib/LLVMBuild.txt + +; CHECK: [component_0] +; CHECK-NEXT: type = OptionalLibrary +; CHECK-NEXT: name = DisabledByCmdLib +; CHECK-NEXT: parent = $ROOT + +; CHECK: [component_1] +; CHECK-NEXT: type = OptionalLibrary +; CHECK-NEXT: name = DisabledDefaultLib +; CHECK-NEXT: parent = $ROOT + +; CHECK: [component_2] +; CHECK-NEXT: type = OptionalLibrary +; CHECK-NEXT: name = EnabledByCmdLib +; CHECK-NEXT: parent = $ROOT +; CHECK-NEXT: enabled_component = 1 + +; CHECK: [component_3] +; CHECK-NEXT: type = OptionalLibrary +; CHECK-NEXT: name = EnabledDefaultLib +; CHECK-NEXT: parent = $ROOT +; CHECK-NEXT: enabled_component = 1 diff --git a/llvm/test/LLVMBuild/lit.local.cfg b/llvm/test/LLVMBuild/lit.local.cfg new file mode 100644 --- /dev/null +++ b/llvm/test/LLVMBuild/lit.local.cfg @@ -0,0 +1,4 @@ +config.substitutions.append( + ('%llvmbuild', os.path.join(config.root.llvm_src_root, 'utils', 'llvm-build', + 'llvm-build'))) +config.suffixes = ['.test'] diff --git a/llvm/utils/llvm-build/llvmbuild/componentinfo.py b/llvm/utils/llvm-build/llvmbuild/componentinfo.py --- a/llvm/utils/llvm-build/llvmbuild/componentinfo.py +++ b/llvm/utils/llvm-build/llvmbuild/componentinfo.py @@ -36,6 +36,8 @@ self.subpath = subpath self.name = name self.dependencies = list(dependencies) + self.optional_component = False + self.enabled_component = True # The name of the parent component to logically group this component # under. @@ -201,13 +203,25 @@ @staticmethod def parse(subpath, items): kwargs = LibraryComponentInfo.parse_items(items) + kwargs['enabled_component'] = \ + items.get_optional_bool('enabled_component', False) return OptionalLibraryComponentInfo(subpath, **kwargs) def __init__(self, subpath, name, dependencies, parent, library_name, - required_libraries, add_to_library_groups, installed): + required_libraries, add_to_library_groups, installed, + enabled_component): LibraryComponentInfo.__init__(self, subpath, name, dependencies, parent, library_name, required_libraries, add_to_library_groups, installed) + self.enabled_component = enabled_component + self.optional_component = True + + def get_llvmbuild_fragment(self): + result = super(OptionalLibraryComponentInfo, + self).get_llvmbuild_fragment() + if self.enabled_component: + result += 'enabled_component = 1\n' + return result class LibraryGroupComponentInfo(ComponentInfo): type_name = 'LibraryGroup' diff --git a/llvm/utils/llvm-build/llvmbuild/main.py b/llvm/utils/llvm-build/llvmbuild/main.py --- a/llvm/utils/llvm-build/llvmbuild/main.py +++ b/llvm/utils/llvm-build/llvmbuild/main.py @@ -303,7 +303,7 @@ f.close() - def write_library_table(self, output_path, enabled_optional_components): + def write_library_table(self, output_path): # Write out the mapping from component names to required libraries. # # We do this in topological order so that we know we can append the @@ -311,8 +311,7 @@ entries = {} for c in self.ordered_component_infos: # Skip optional components which are not enabled. - if c.type_name == 'OptionalLibrary' \ - and c.name not in enabled_optional_components: + if not c.enabled_component: continue # Skip target groups which are not enabled. @@ -493,13 +492,11 @@ yield path def foreach_cmake_library(self, f, - enabled_optional_components, skip_disabled, skip_not_installed): for ci in self.ordered_component_infos: # Skip optional components which are not enabled. - if ci.type_name == 'OptionalLibrary' \ - and ci.name not in enabled_optional_components: + if not ci.enabled_component: continue # We only write the information for libraries currently. @@ -519,7 +516,7 @@ f(ci) - def write_cmake_fragment(self, output_path, enabled_optional_components): + def write_cmake_fragment(self, output_path): """ write_cmake_fragment(output_path) -> None @@ -585,14 +582,13 @@ dep.get_prefixed_library_name() for dep in self.get_required_libraries_for_component(ci))))) , - enabled_optional_components, skip_disabled = False, skip_not_installed = False # Dependency info must be emitted for internals libs too ) f.close() - def write_cmake_exports_fragment(self, output_path, enabled_optional_components): + def write_cmake_exports_fragment(self, output_path): """ write_cmake_exports_fragment(output_path) -> None @@ -621,7 +617,6 @@ dep.get_prefixed_library_name() for dep in self.get_required_libraries_for_component(ci))))) , - enabled_optional_components, skip_disabled = True, skip_not_installed = True # Do not export internal libraries like gtest ) @@ -784,10 +779,15 @@ "list of targets, or all targets if not present"), action="store", default=None) group.add_option("", "--enable-optional-components", - dest="optional_components", metavar="NAMES", + dest="enable_optional_components", metavar="NAMES", help=("Enable the given space or semi-colon separated " "list of optional components"), action="store", default="") + group.add_option("", "--disable-optional-components", + dest="disable_optional_components", metavar="NAMES", + help=("Disable the given space or semi-colon separated " + "list of optional components"), + action="store", default="") parser.add_option_group(group) (opts, args) = parser.parse_args() @@ -815,6 +815,19 @@ # Add the magic target based components. add_magic_target_components(parser, project_info, opts) + # Apply options that change component.enabled_component + for c in project_info.component_infos: + if c.name in opts.enable_optional_components: + if c.optional_component: + c.enabled_component = True + else: + parser.error('component `%s` is not optional' % c.name) + if c.name in opts.disable_optional_components: + if c.optional_component: + c.enabled_component = False + else: + parser.error('component `%s` is not optional' % c.name) + # Validate the project component info. project_info.validate_components() @@ -829,16 +842,13 @@ # Write out the required library table, if requested. if opts.write_library_table: - project_info.write_library_table(opts.write_library_table, - opts.optional_components) + project_info.write_library_table(opts.write_library_table) # Write out the cmake fragment, if requested. if opts.write_cmake_fragment: - project_info.write_cmake_fragment(opts.write_cmake_fragment, - opts.optional_components) + project_info.write_cmake_fragment(opts.write_cmake_fragment) if opts.write_cmake_exports_fragment: - project_info.write_cmake_exports_fragment(opts.write_cmake_exports_fragment, - opts.optional_components) + project_info.write_cmake_exports_fragment(opts.write_cmake_exports_fragment) if __name__=='__main__': main()