Skip to content

Commit

Permalink
Automated rollback of commit 67549a7.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Breaks on windows: https://www.google.com/url?sa=D&q=https%3A%2F%2Fbuildkite.com%2Fbazel%2Fgoogle-bazel-presubmit%2Fbuilds%2F624%234a68440b-948b-437b-a633-4f0595721bab

*** Original change description ***

Automated rollback of commit 3c5a109.

*** Reason for rollback ***

Breaks bazel ci: #4894 (comment)

*** Original change description ***

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: 189906675
  • Loading branch information
hlopko authored and Copybara-Service committed Mar 21, 2018
1 parent 339b5e4 commit 5cee7f4
Show file tree
Hide file tree
Showing 6 changed files with 863 additions and 15 deletions.
36 changes: 24 additions & 12 deletions src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
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;
Expand Down Expand Up @@ -105,11 +106,8 @@ public void collectMetadataArtifacts(Iterable<Artifact> objectFiles,
}
};

/** 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,
Expand All @@ -120,16 +118,29 @@ public void collectMetadataArtifacts(Iterable<Artifact> objectFiles,
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 =
Expand All @@ -142,6 +153,7 @@ public void collectMetadataArtifacts(Iterable<Artifact> objectFiles,
CppRuleClasses.INCLUDE_PATHS,
CppRuleClasses.PIC,
CppRuleClasses.PREPROCESSOR_DEFINES);

public static final String CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME = ":cc_toolchain";

/** C++ configuration */
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
@RunWith(JUnit4.class)
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()
Expand All @@ -47,7 +56,135 @@ public void testSplitEscaped() throws Exception {
.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
Expand All @@ -56,6 +193,9 @@ private ModalTestCase newTest(String... skylarkOptions) throws IOException {
.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"));
}
}
10 changes: 10 additions & 0 deletions tools/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ filegroup(
srcs = ["lib_cc_configure.bzl"],
)

filegroup(
name = "crosstool_utils",
srcs = ["crosstool_utils.bzl"],
)

filegroup(
name = "crosstool_lib",
srcs = ["crosstool_lib.bzl"],
)

cc_toolchain_type(name = "toolchain_type")

# A dummy toolchain is necessary to satisfy toolchain resolution until platforms
Expand Down
Loading

0 comments on commit 5cee7f4

Please sign in to comment.