diff --git a/llvm/test/LLVMBuild/enable-optional-component/Input/LLVMBuild.txt b/llvm/test/LLVMBuild/enable-optional-component/Input/LLVMBuild.txt new file mode 100644 --- /dev/null +++ b/llvm/test/LLVMBuild/enable-optional-component/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/enable-optional-component/Input/lib/IR/Function.cpp b/llvm/test/LLVMBuild/enable-optional-component/Input/lib/IR/Function.cpp new file mode 100644 diff --git a/llvm/test/LLVMBuild/enable-optional-component/Input/lib/LLVMBuild.txt b/llvm/test/LLVMBuild/enable-optional-component/Input/lib/LLVMBuild.txt new file mode 100644 --- /dev/null +++ b/llvm/test/LLVMBuild/enable-optional-component/Input/lib/LLVMBuild.txt @@ -0,0 +1,30 @@ +;===- ./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 = Foo +parent = $ROOT + +[component_1] +type = OptionalLibrary +name = FooBar +parent = $ROOT + +[component_2] +type = OptionalLibrary +name = Z +parent = $ROOT diff --git a/llvm/test/LLVMBuild/enable-optional-component/enable-optional-component.test b/llvm/test/LLVMBuild/enable-optional-component/enable-optional-component.test new file mode 100644 --- /dev/null +++ b/llvm/test/LLVMBuild/enable-optional-component/enable-optional-component.test @@ -0,0 +1,24 @@ +RUN: %llvmbuild --source-root=%S/Input --write-llvmbuild=%T \ +RUN: --enable-optional-components=Foo --write-library-table=%T/table.inc +RUN: FileCheck %s < %T/lib/LLVMBuild.txt +RUN: FileCheck --check-prefix=TABLE %s < %T/table.inc + +CHECK: [component_0] +CHECK-NEXT: type = OptionalLibrary +CHECK-NEXT: name = Foo +CHECK-NEXT: parent = $ROOT +CHECK-NEXT: enabled_component = 1 + +CHECK: [component_1] +CHECK-NEXT: type = OptionalLibrary +CHECK-NEXT: name = FooBar +CHECK-NEXT: parent = $ROOT + +CHECK: [component_2] +CHECK-NEXT: type = OptionalLibrary +CHECK-NEXT: name = Z +CHECK-NEXT: parent = $ROOT + +TABLE-NOT: FooBar +TABLE: { "foo", "LLVMFoo" +TABLE-NOT: FooBar 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 @@ -9,6 +9,15 @@ ### +def space_or_semicolon_list(x): + # We support both space separated and semi-colon separated lists. + if x == '': + return [] + elif ' ' in x: + return x.split() + else: + return x.split(';') + def cmake_quote_string(value): """ cmake_quote_string(value) -> str @@ -661,13 +670,7 @@ if opts.enable_targets is None: enable_targets = available_targets.values() else: - # We support both space separated and semi-colon separated lists. - if opts.enable_targets == '': - enable_target_names = [] - elif ' ' in opts.enable_targets: - enable_target_names = opts.enable_targets.split() - else: - enable_target_names = opts.enable_targets.split(';') + enable_target_names = space_or_semicolon_list(opts.enable_targets) enable_targets = [] for name in enable_target_names: @@ -791,6 +794,10 @@ parser.add_option_group(group) (opts, args) = parser.parse_args() + opts.enable_optional_components = \ + space_or_semicolon_list(opts.enable_optional_components) + opts.disable_optional_components = \ + space_or_semicolon_list(opts.disable_optional_components) # Determine the LLVM source path, if not given. source_root = opts.source_root