diff options
author | hlopko <hlopko@google.com> | 2018-03-21 04:03:40 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-21 04:05:40 -0700 |
commit | 3c5a1098af0c5ae80d4e3b1fc52dd1fef6027d43 (patch) | |
tree | 41f0992a75318cd2cf05082abc5baa4070aa3654 /src | |
parent | 01a0fbc9d2fc77503f3ea23498b0959ca8b5fef3 (diff) |
Add crosstool_lib.bzl and crosstool_utils.bzl
These will be used to rewrite current crosstool autoconfiguration into
action_configs and features.
RELNOTES: None.
PiperOrigin-RevId: 189888171
Diffstat (limited to 'src')
3 files changed, 170 insertions, 15 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index b25dc7fc85..a2da30d674 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -50,6 +50,7 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.DynamicMode; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode; import com.google.devtools.build.lib.rules.cpp.FdoSupport.FdoMode; +import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; import com.google.devtools.build.lib.shell.ShellUtils; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; @@ -105,11 +106,8 @@ public final class CcCommon { } }; - /** Action configs we request to enable. */ - private static final ImmutableSet<String> DEFAULT_ACTION_CONFIGS = + public static final ImmutableSet<String> ALL_COMPILE_ACTIONS = ImmutableSet.of( - CppCompileAction.CC_FLAGS_MAKE_VARIABLE_ACTION_NAME, - CppCompileAction.STRIP_ACTION_NAME, CppCompileAction.C_COMPILE, CppCompileAction.CPP_COMPILE, CppCompileAction.CPP_HEADER_PARSING, @@ -120,16 +118,29 @@ public final class CcCommon { CppCompileAction.PREPROCESS_ASSEMBLE, CppCompileAction.CLIF_MATCH, CppCompileAction.LINKSTAMP_COMPILE, - Link.LinkTargetType.STATIC_LIBRARY.getActionName(), - // We need to create pic-specific actions for link actions, as they will produce - // differently named outputs. - Link.LinkTargetType.PIC_STATIC_LIBRARY.getActionName(), + CppCompileAction.CC_FLAGS_MAKE_VARIABLE_ACTION_NAME); + + public static final ImmutableSet<String> ALL_LINK_ACTIONS = + ImmutableSet.of( Link.LinkTargetType.INTERFACE_DYNAMIC_LIBRARY.getActionName(), - Link.LinkTargetType.NODEPS_DYNAMIC_LIBRARY.getActionName(), Link.LinkTargetType.DYNAMIC_LIBRARY.getActionName(), - Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY.getActionName(), - Link.LinkTargetType.ALWAYS_LINK_PIC_STATIC_LIBRARY.getActionName(), - Link.LinkTargetType.EXECUTABLE.getActionName()); + Link.LinkTargetType.NODEPS_DYNAMIC_LIBRARY.getActionName(), + LinkTargetType.EXECUTABLE.getActionName()); + + public static final ImmutableSet<String> ALL_ARCHIVE_ACTIONS = + ImmutableSet.of(Link.LinkTargetType.STATIC_LIBRARY.getActionName()); + + public static final ImmutableSet<String> ALL_OTHER_ACTIONS = + ImmutableSet.of(CppCompileAction.STRIP_ACTION_NAME); + + /** Action configs we request to enable. */ + public static final ImmutableSet<String> DEFAULT_ACTION_CONFIGS = + ImmutableSet.<String>builder() + .addAll(ALL_COMPILE_ACTIONS) + .addAll(ALL_LINK_ACTIONS) + .addAll(ALL_ARCHIVE_ACTIONS) + .addAll(ALL_OTHER_ACTIONS) + .build(); /** Features we request to enable unless a rule explicitly doesn't support them. */ private static final ImmutableSet<String> DEFAULT_FEATURES = @@ -142,6 +153,7 @@ public final class CcCommon { CppRuleClasses.INCLUDE_PATHS, CppRuleClasses.PIC, CppRuleClasses.PREPROCESSOR_DEFINES); + public static final String CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME = ":cc_toolchain"; /** C++ configuration */ diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD b/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD index 7e0b17115b..9d5482bada 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD @@ -13,7 +13,10 @@ filegroup( java_test( name = "cpp-rules-tests", srcs = glob(["*.java"]) + ["proto/CcProtoLibraryTest.java"], - resources = ["//tools/cpp:lib_cc_configure"], + resources = [ + "//tools/cpp:crosstool_utils", + "//tools/cpp:lib_cc_configure", + ], tags = ["rules"], test_class = "com.google.devtools.build.lib.AllTests", deps = [ diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java index dbaa612fb3..c3386fff9a 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/SkylarkCcToolchainConfigureTest.java @@ -27,6 +27,15 @@ import org.junit.runners.JUnit4; public class SkylarkCcToolchainConfigureTest extends EvaluationTestCase { @Test + public void testActionNames() throws Exception { + newTest() + .testStatement("COMPILE_ACTIONS", MutableList.copyOf(env, CcCommon.ALL_COMPILE_ACTIONS)) + .testStatement("LINK_ACTIONS", MutableList.copyOf(env, CcCommon.ALL_LINK_ACTIONS)) + .testStatement("ARCHIVE_ACTIONS", MutableList.copyOf(env, CcCommon.ALL_ARCHIVE_ACTIONS)) + .testStatement("OTHER_ACTIONS", MutableList.copyOf(env, CcCommon.ALL_OTHER_ACTIONS)); + } + + @Test public void testSplitEscaped() throws Exception { newTest() .testStatement("split_escaped('a:b:c', ':')", MutableList.of(env, "a", "b", "c")) @@ -47,7 +56,135 @@ public class SkylarkCcToolchainConfigureTest extends EvaluationTestCase { .testStatement("split_escaped('a%%b', ':')", MutableList.of(env, "a%b")) .testStatement("split_escaped('a%:', ':')", MutableList.of(env, "a:")); } - + + @Test + public void testActionConfig() throws Exception { + newTest() + .testStatement( + "action_config('c++-compile', '/usr/bin/gcc')", + "\n" + + " action_config {\n" + + " config_name: 'c++-compile'\n" + + " action_name: 'c++-compile'\n" + + " tool {\n" + + " tool_path: '/usr/bin/gcc'\n" + + " }\n" + + " }"); + } + + @Test + public void testFeature() throws Exception { + newTest() + .testStatement( + "feature(" + + "'fully_static_link', " + + " [ " + + " flag_set(" + + " ['c++-link-dynamic-library', 'c++-link-nodeps-dynamic-library'], " + + " [flag_group([flag('-a'), flag('-b'), flag('-c')])])])", + "\n" + + " feature {\n" + + " name: 'fully_static_link'\n" + + " enabled: true\n" + + " flag_set {\n" + + " action: 'c++-link-dynamic-library'\n" + + " action: 'c++-link-nodeps-dynamic-library'\n" + + " flag_group {\n" + + " flag: '-a'\n" + + " flag: '-b'\n" + + " flag: '-c'\n" + + " }\n" + + " }\n" + + " }"); + } + + @Test + public void testFeatureThoroughly() throws Exception { + newTest() + .testStatement( + "feature(" + + "'fully_static_link', " + + " [ " + + " flag_set(" + + " ['c++-link-dynamic-library'], " + + " [flag_group([flag('-a')])])," + + " flag_set(" + + " ['c++-link-dynamic-library']," + + " [" + + " flag_group(" + + " [flag('-a')]," + + " iterate_over='a')," + + " flag_group(" + + " [flag('-c')]," + + " expand_if_all_available=['a','b']," + + " expand_if_none_available=['a']," + + " expand_if_true=['a','b']," + + " expand_if_false=['a']," + + " expand_if_equal=[['a','val']]," + + " )," + + " flag_group(" + + " [flag('-c')]," + + " iterate_over='a'," + + " expand_if_all_available=['a','b']," + + " expand_if_none_available=['a']," + + " expand_if_true=['a','b']," + + " expand_if_false=['a']," + + " expand_if_equal=[['a','val']]," + + " )" + + " ])," + + " flag_set(" + + " ['c++-link-dynamic-library'], " + + " [flag_group([flag_group([flag('-a')])])])" + + " ])", + "\n" + + " feature {\n" + + " name: 'fully_static_link'\n" + + " enabled: true\n" + + " flag_set {\n" + + " action: 'c++-link-dynamic-library'\n" + + " flag_group {\n" + + " flag: '-a'\n" + + " }\n" + + " }\n" + + " flag_set {\n" + + " action: 'c++-link-dynamic-library'\n" + + " flag_group {\n" + + " iterate_over: 'a'\n" + + " flag: '-a'\n" + + " }\n" + + " flag_group {\n" + + " expand_if_all_available: 'a'\n" + + " expand_if_all_available: 'b'\n" + + " expand_if_none_available: 'a'\n" + + " expand_if_true: 'a'\n" + + " expand_if_true: 'b'\n" + + " expand_if_false: 'a'\n" + + " expand_if_equal { variable: 'a' value: 'val' }\n" + + " flag: '-c'\n" + + " }\n" + + " flag_group {\n" + + " expand_if_all_available: 'a'\n" + + " expand_if_all_available: 'b'\n" + + " expand_if_none_available: 'a'\n" + + " expand_if_true: 'a'\n" + + " expand_if_true: 'b'\n" + + " expand_if_false: 'a'\n" + + " expand_if_equal { variable: 'a' value: 'val' }\n" + + " iterate_over: 'a'\n" + + " flag: '-c'\n" + + " }\n" + + " }\n" + + " flag_set {\n" + + " action: 'c++-link-dynamic-library'\n" + + " flag_group {\n" + + " flag_group {\n" + + " flag: '-a'\n" + + " }\n" + + " }\n" + + " }\n" + + " }"); + } + private ModalTestCase newTest(String... skylarkOptions) throws IOException { return new SkylarkTest(skylarkOptions) // A mock implementation of Label to be able to parse lib_cc_configure under default @@ -56,6 +193,9 @@ public class SkylarkCcToolchainConfigureTest extends EvaluationTestCase { .setUp("def Label(arg):\n return 42") .setUp( ResourceLoader.readFromResources( - TestConstants.BAZEL_REPO_PATH + "tools/cpp/lib_cc_configure.bzl")); + TestConstants.BAZEL_REPO_PATH + "tools/cpp/lib_cc_configure.bzl")) + .setUp( + ResourceLoader.readFromResources( + TestConstants.BAZEL_REPO_PATH + "tools/cpp/crosstool_utils.bzl")); } } |