aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2017-06-12 17:30:45 +0200
committerGravatar Yun Peng <pcloudy@google.com>2017-06-12 17:40:04 +0200
commitd83d9bf1d6670f2e9bd25e2f6824d8b4a7099d4f (patch)
tree1e0708fc6b422a58dc7a201317b92c0db7625fa7 /src/main/java/com/google/devtools/build/lib/rules/cpp
parentbde7c41c8b93c0f36806fed649021784700aaedd (diff)
Init absent action configs for CppCompile actions
So far only link actions were initialized in CppLinkActionConfigs. This cl changes this class to also initialize CppCompile actions. This is needed for our ongoing work removing hard-coded flags from Bazel and moving them into Crosstool. RELNOTES: None. PiperOrigin-RevId: 158715986
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java579
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java41
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java522
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java2
5 files changed, 608 insertions, 554 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java
index 72814e4042..bdc82dc92e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java
@@ -90,16 +90,14 @@ public final class CompileCommandLine {
List<String> commandLine = new ArrayList<>();
// first: The command name.
- if (!featureConfiguration.actionIsConfigured(actionName)) {
- commandLine.add(
- cppConfiguration.getToolPathFragment(CppConfiguration.Tool.GCC).getPathString());
- } else {
- commandLine.add(
- featureConfiguration
- .getToolForAction(actionName)
- .getToolPath(cppConfiguration.getCrosstoolTopPathFragment())
- .getPathString());
- }
+ Preconditions.checkArgument(
+ featureConfiguration.actionIsConfigured(actionName),
+ String.format("Expected action_config for '%s' to be configured", actionName));
+ commandLine.add(
+ featureConfiguration
+ .getToolForAction(actionName)
+ .getToolPath(cppConfiguration.getCrosstoolTopPathFragment())
+ .getPathString());
// second: The compiler options.
commandLine.addAll(getCompilerOptions(overwrittenVariables));
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java
new file mode 100644
index 0000000000..5dd5856e99
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java
@@ -0,0 +1,579 @@
+// Copyright 2014 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.rules.cpp;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import java.util.Set;
+
+/**
+ * A helper class for creating action_configs for the c++ link action.
+ *
+ * <p>TODO(b/30109612): Replace this with action_configs in the crosstool instead of putting it in
+ * legacy features.
+ */
+public class CppActionConfigs {
+
+ /** A platform for linker invocations. */
+ public static enum CppPlatform {
+ LINUX,
+ MAC
+ }
+
+ public static String getCppActionConfigs(
+ CppPlatform platform,
+ Set<String> features,
+ String gccToolPath,
+ String cppLinkDynamicLibraryToolPath,
+ String arToolPath,
+ boolean supportsEmbeddedRuntimes) {
+ String cppDynamicLibraryLinkerTool = "";
+ if (!features.contains("dynamic_library_linker_tool")) {
+ cppDynamicLibraryLinkerTool =
+ ""
+ + "feature {"
+ + " name: 'dynamic_library_linker_tool'"
+ + " flag_set {"
+ + " action: 'c++-link-dynamic-library'"
+ + " flag_group {"
+ + " flag: '"
+ + cppLinkDynamicLibraryToolPath
+ + "'"
+ + " }"
+ + " }"
+ + "}";
+ }
+
+ return Joiner.on("\n")
+ .join(
+ ImmutableList.of(
+ "action_config {",
+ " config_name: 'assemble'",
+ " action_name: 'assemble'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'preprocess-assemble'",
+ " action_name: 'preprocess-assemble'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'c-compile'",
+ " action_name: 'c-compile'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'c++-compile'",
+ " action_name: 'c++-compile'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'c++-header-parsing'",
+ " action_name: 'c++-header-parsing'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'c++-header-preprocessing'",
+ " action_name: 'c++-header-preprocessing'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'c++-module-compile'",
+ " action_name: 'c++-module-compile'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'c++-module-codegen'",
+ " action_name: 'c++-module-codegen'",
+ " tool {",
+ " tool_path: '" + gccToolPath + "'",
+ " }",
+ "}",
+ "action_config {",
+ " config_name: 'c++-link-executable'",
+ " action_name: 'c++-link-executable'",
+ " tool {",
+ " tool_path: 'DUMMY_TOOL'",
+ " }",
+ " implies: 'symbol_counts'",
+ " implies: 'strip_debug_symbols'",
+ " implies: 'linkstamps'",
+ " implies: 'output_execpath_flags_executable'",
+ " implies: 'runtime_library_search_directories'",
+ " implies: 'library_search_directories'",
+ " implies: 'libraries_to_link'",
+ " implies: 'force_pic_flags'",
+ " implies: 'legacy_link_flags'",
+ " implies: 'linker_param_file'",
+ " implies: 'fission_support'",
+ "}",
+ "action_config {",
+ " config_name: 'c++-link-dynamic-library'",
+ " action_name: 'c++-link-dynamic-library'",
+ " tool {",
+ " tool_path: 'DUMMY_TOOL'",
+ " }",
+ " implies: 'build_interface_libraries'",
+ " implies: 'dynamic_library_linker_tool'",
+ " implies: 'symbol_counts'",
+ " implies: 'strip_debug_symbols'",
+ " implies: 'shared_flag'",
+ " implies: 'linkstamps'",
+ " implies: 'output_execpath_flags'",
+ " implies: 'runtime_library_search_directories'",
+ " implies: 'library_search_directories'",
+ " implies: 'libraries_to_link'",
+ " implies: 'legacy_link_flags'",
+ " implies: 'linker_param_file'",
+ " implies: 'fission_support'",
+ "}",
+ "action_config {",
+ " config_name: 'c++-link-static-library'",
+ " action_name: 'c++-link-static-library'",
+ " tool {",
+ " tool_path: '" + arToolPath + "'",
+ " }",
+ " implies: 'archiver_flags'",
+ " implies: 'libraries_to_link'",
+ " implies: 'linker_param_file'",
+ "}",
+ "action_config {",
+ " config_name: 'c++-link-alwayslink-static-library'",
+ " action_name: 'c++-link-alwayslink-static-library'",
+ " tool {",
+ " tool_path: '" + arToolPath + "'",
+ " }",
+ " implies: 'archiver_flags'",
+ " implies: 'libraries_to_link'",
+ " implies: 'linker_param_file'",
+ "}",
+ "action_config {",
+ " config_name: 'c++-link-pic-static-library'",
+ " action_name: 'c++-link-pic-static-library'",
+ " tool {",
+ " tool_path: '" + arToolPath + "'",
+ " }",
+ " implies: 'archiver_flags'",
+ " implies: 'libraries_to_link'",
+ " implies: 'linker_param_file'",
+ "}",
+ "action_config {",
+ " config_name: 'c++-link-alwayslink-pic-static-library'",
+ " action_name: 'c++-link-alwayslink-pic-static-library'",
+ " tool {",
+ " tool_path: '" + arToolPath + "'",
+ " }",
+ " implies: 'archiver_flags'",
+ " implies: 'libraries_to_link'",
+ " implies: 'linker_param_file'",
+ "}",
+ "feature {",
+ " name: 'build_interface_libraries'",
+ " flag_set {",
+ " expand_if_all_available: 'generate_interface_library'",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " flag: '%{generate_interface_library}'",
+ " flag: '%{interface_library_builder_path}'",
+ " flag: '%{interface_library_input_path}'",
+ " flag: '%{interface_library_output_path}'",
+ " }",
+ " }",
+ "}",
+ // Order of feature declaration matters, cppDynamicLibraryLinkerTool has to follow
+ // right after build_interface_libraries.
+ cppDynamicLibraryLinkerTool,
+ "feature {",
+ " name: 'symbol_counts'",
+ " flag_set {",
+ " expand_if_all_available: 'symbol_counts_output'",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " flag: '-Wl,--print-symbol-counts=%{symbol_counts_output}'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'shared_flag'",
+ " flag_set {",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " flag: '-shared'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'linkstamps'",
+ " flag_set {",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " expand_if_all_available: 'linkstamp_paths'",
+ " flag_group {",
+ " flag: '%{linkstamp_paths}'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'output_execpath_flags'",
+ " flag_set {",
+ " expand_if_all_available: 'output_execpath'",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " flag: '-o'",
+ " flag: '%{output_execpath}'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'output_execpath_flags_executable'",
+ " flag_set {",
+ " expand_if_all_available: 'output_execpath'",
+ " action: 'c++-link-executable'",
+ " flag_group {",
+ " flag: '-o'",
+ " }",
+ " }",
+ " flag_set {",
+ " expand_if_all_available: 'skip_mostly_static'",
+ " expand_if_all_available: 'output_execpath'",
+ " action: 'c++-link-executable'",
+ " flag_group {",
+ " flag: '/dev/null'",
+ " flag: '-MMD'",
+ " flag: '-MF'",
+ " }",
+ " }",
+ " flag_set {",
+ " expand_if_all_available: 'output_execpath'",
+ " action: 'c++-link-executable'",
+ " flag_group {",
+ " flag: '%{output_execpath}'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'runtime_library_search_directories',",
+ " flag_set {",
+ " expand_if_all_available: 'runtime_library_search_directories'",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " iterate_over: 'runtime_library_search_directories'",
+ " flag_group {",
+ // TODO(b/27153401): This should probably be @loader_path on osx.
+ ifTrue(
+ supportsEmbeddedRuntimes,
+ " expand_if_all_available: 'is_cc_test_link_action'",
+ " flag: ",
+ " '-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}'",
+ " }",
+ " flag_group {",
+ " expand_if_all_available: 'is_not_cc_test_link_action'"),
+ " flag: '-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}'",
+ " }",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'library_search_directories'",
+ " flag_set {",
+ " expand_if_all_available: 'library_search_directories'",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " iterate_over: 'library_search_directories'",
+ " flag: '-L%{library_search_directories}'",
+ " }",
+ " }",
+ "}",
+ ifTrue(
+ !features.contains("archiver_flags"),
+ "feature {",
+ " name: 'archiver_flags'",
+ " flag_set {",
+ " expand_if_all_available: 'output_execpath'",
+ " action: 'c++-link-static-library'",
+ " action: 'c++-link-alwayslink-static-library'",
+ " action: 'c++-link-pic-static-library'",
+ " action: 'c++-link-alwayslink-pic-static-library'",
+ " flag_group {",
+ ifLinux(platform, " flag: 'rcsD'", " flag: '%{output_execpath}'"),
+ ifMac(
+ platform,
+ " flag: '-static'",
+ " flag: '-s'",
+ " flag: '-o'",
+ " flag: '%{output_execpath}'"),
+ " }",
+ " }",
+ "}"),
+ "feature {",
+ " name: 'libraries_to_link'",
+ " flag_set {",
+ " expand_if_all_available: 'libraries_to_link'",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " action: 'c++-link-static-library'",
+ " action: 'c++-link-alwayslink-static-library'",
+ " action: 'c++-link-pic-static-library'",
+ " action: 'c++-link-alwayslink-pic-static-library'",
+ " flag_group {",
+ " iterate_over: 'libraries_to_link'",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'object_file_group'",
+ " }",
+ " flag: '-Wl,--start-lib'",
+ " }",
+ ifLinux(
+ platform,
+ " flag_group {",
+ " expand_if_true: 'libraries_to_link.is_whole_archive'",
+ " flag: '-Wl,-whole-archive'",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'object_file_group'",
+ " }",
+ " iterate_over: 'libraries_to_link.object_files'",
+ " flag: '%{libraries_to_link.object_files}'",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'object_file'",
+ " }",
+ " flag: '%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'interface_library'",
+ " }",
+ " flag: '%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'static_library'",
+ " }",
+ " flag: '%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'dynamic_library'",
+ " }",
+ " flag: '-l%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'versioned_dynamic_library'",
+ " }",
+ " flag: '-l:%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_true: 'libraries_to_link.is_whole_archive'",
+ " flag: '-Wl,-no-whole-archive'",
+ " }"),
+ ifMac(
+ platform,
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'object_file_group'",
+ " }",
+ " iterate_over: 'libraries_to_link.object_files'",
+ " flag_group {",
+ " expand_if_false: 'libraries_to_link.is_whole_archive'",
+ " flag: '%{libraries_to_link.object_files}'",
+ " }",
+ " flag_group {",
+ " expand_if_true: 'libraries_to_link.is_whole_archive'",
+ " flag: '-Wl,-force_load,%{libraries_to_link.object_files}'",
+ " }",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'object_file'",
+ " }",
+ " flag_group {",
+ " expand_if_false: 'libraries_to_link.is_whole_archive'",
+ " flag: '%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_true: 'libraries_to_link.is_whole_archive'",
+ " flag: '-Wl,-force_load,%{libraries_to_link.name}'",
+ " }",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'interface_library'",
+ " }",
+ " flag_group {",
+ " expand_if_false: 'libraries_to_link.is_whole_archive'",
+ " flag: '%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_true: 'libraries_to_link.is_whole_archive'",
+ " flag: '-Wl,-force_load,%{libraries_to_link.name}'",
+ " }",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'static_library'",
+ " }",
+ " flag_group {",
+ " expand_if_false: 'libraries_to_link.is_whole_archive'",
+ " flag: '%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_true: 'libraries_to_link.is_whole_archive'",
+ " flag: '-Wl,-force_load,%{libraries_to_link.name}'",
+ " }",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'dynamic_library'",
+ " }",
+ " flag: '-l%{libraries_to_link.name}'",
+ " }",
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'versioned_dynamic_library'",
+ " }",
+ " flag: '-l:%{libraries_to_link.name}'",
+ " }"),
+ " flag_group {",
+ " expand_if_equal: {",
+ " variable: 'libraries_to_link.type'",
+ " value: 'object_file_group'",
+ " }",
+ " flag: '-Wl,--end-lib'",
+ " }",
+ " }",
+ " flag_group {",
+ " expand_if_true: 'thinlto_param_file'",
+ " flag: '-Wl,@%{thinlto_param_file}'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'force_pic_flags'",
+ " flag_set {",
+ " expand_if_all_available: 'force_pic'",
+ " action: 'c++-link-executable'",
+ " flag_group {",
+ " flag: '-pie'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'legacy_link_flags'",
+ " flag_set {",
+ " expand_if_all_available: 'legacy_link_flags'",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " iterate_over: 'legacy_link_flags'",
+ " flag: '%{legacy_link_flags}'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'fission_support'",
+ " flag_set {",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " action: 'c++-link-interface-dynamic-library'",
+ " flag_group {",
+ " expand_if_all_available: 'is_using_fission'",
+ " flag: '-Wl,--gdb-index'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'strip_debug_symbols'",
+ " flag_set {",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " action: 'c++-link-interface-dynamic-library'",
+ " flag_group {",
+ " expand_if_all_available: 'strip_debug_symbols'",
+ " flag: '-Wl,-S'",
+ " }",
+ " }",
+ "}",
+ "feature {",
+ " name: 'linker_param_file'",
+ " flag_set {",
+ " expand_if_all_available: 'linker_param_file'",
+ " action: 'c++-link-executable'",
+ " action: 'c++-link-dynamic-library'",
+ " flag_group {",
+ " flag: '-Wl,@%{linker_param_file}'",
+ " }",
+ " }",
+ " flag_set {",
+ " expand_if_all_available: 'linker_param_file'",
+ " action: 'c++-link-static-library'",
+ " action: 'c++-link-alwayslink-static-library'",
+ " action: 'c++-link-pic-static-library'",
+ " action: 'c++-link-alwayslink-pic-static-library'",
+ " flag_group {",
+ " flag: '@%{linker_param_file}'",
+ " }",
+ " }",
+ "}"));
+ }
+
+ private static String ifLinux(CppPlatform platform, String... lines) {
+ return ifTrue(platform == CppPlatform.LINUX, lines);
+ }
+
+ private static String ifMac(CppPlatform platform, String... lines) {
+ return ifTrue(platform == CppPlatform.MAC, lines);
+ }
+
+ private static String ifTrue(boolean condition, String... lines) {
+ if (condition) {
+ return Joiner.on("\n").join(lines);
+ } else {
+ return "";
+ }
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index f974c35624..1d50ed608c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -40,9 +40,8 @@ import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.OutputFile;
import com.google.devtools.build.lib.packages.Target;
+import com.google.devtools.build.lib.rules.cpp.CppActionConfigs.CppPlatform;
import com.google.devtools.build.lib.rules.cpp.CppConfigurationLoader.CppConfigurationParameters;
-import com.google.devtools.build.lib.rules.cpp.CppLinkActionConfigs.CppLinkPlatform;
-import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
import com.google.devtools.build.lib.rules.cpp.transitions.ContextCollectorOwnerTransition;
import com.google.devtools.build.lib.rules.cpp.transitions.DisableLipoTransition;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
@@ -599,22 +598,19 @@ public class CppConfiguration extends BuildConfiguration.Fragment {
return result.build();
}
-
- private boolean linkActionsAreConfigured(CToolchain toolchain) {
-
- for (LinkTargetType type : Link.MANDATORY_LINK_TARGET_TYPES) {
- boolean typeIsConfigured = false;
- for (ActionConfig actionConfig : toolchain.getActionConfigList()) {
- if (actionConfig.getActionName().equals(type.getActionName())) {
- typeIsConfigured = true;
- break;
- }
- }
- if (!typeIsConfigured) {
- return false;
- }
- }
- return true;
+
+ private static boolean actionsAreConfigured(CToolchain toolchain) {
+ return Iterables.any(
+ toolchain.getActionConfigList(),
+ new Predicate<ActionConfig>() {
+ @Override
+ public boolean apply(@Nullable ActionConfig actionConfig) {
+ // We cannot assume actions are configured just by presence of any action_config. Some
+ // crosstools specify unrelated action_configs (e.g. clif_match), but C/C++ part is
+ // in fact not configured.
+ return actionConfig.getActionName().contains("c++");
+ }
+ });
}
// TODO(bazel-team): Remove this once bazel supports all crosstool flags through
@@ -648,11 +644,13 @@ public class CppConfiguration extends BuildConfiguration.Fragment {
Set<String> features = featuresBuilder.build();
if (!features.contains(CppRuleClasses.NO_LEGACY_FEATURES)) {
try {
- if (!linkActionsAreConfigured(toolchain)) {
+ if (!actionsAreConfigured(toolchain)) {
+ String gccToolPath = "DUMMY_GCC_TOOL";
String linkerToolPath = "DUMMY_LINKER_TOOL";
String arToolPath = "DUMMY_AR_TOOL";
for (ToolPath tool : toolchain.getToolPathList()) {
if (tool.getName().equals(Tool.GCC.getNamePart())) {
+ gccToolPath = tool.getPath();
linkerToolPath =
crosstoolTopPathFragment
.getRelative(PathFragment.create(tool.getPath()))
@@ -663,9 +661,10 @@ public class CppConfiguration extends BuildConfiguration.Fragment {
}
}
TextFormat.merge(
- CppLinkActionConfigs.getCppLinkActionConfigs(
- getTargetLibc().equals("macosx") ? CppLinkPlatform.MAC : CppLinkPlatform.LINUX,
+ CppActionConfigs.getCppActionConfigs(
+ getTargetLibc().equals("macosx") ? CppPlatform.MAC : CppPlatform.LINUX,
features,
+ gccToolPath,
linkerToolPath,
arToolPath,
supportsEmbeddedRuntimes),
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java
deleted file mode 100644
index 5fc511d11a..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java
+++ /dev/null
@@ -1,522 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.rules.cpp;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-import java.util.Set;
-
-/**
- * A helper class for creating action_configs for the c++ link action.
- *
- * <p>TODO(b/30109612): Replace this with action_configs in the crosstool instead of putting it in
- * legacy features.
- */
-public class CppLinkActionConfigs {
-
- /** A platform for linker invocations. */
- public static enum CppLinkPlatform {
- LINUX,
- MAC
- }
-
- public static String getCppLinkActionConfigs(
- CppLinkPlatform platform,
- Set<String> features,
- String cppLinkDynamicLibraryToolPath,
- String arToolPath,
- boolean supportsEmbeddedRuntimes) {
- String cppDynamicLibraryLinkerTool = "";
- if (!features.contains("dynamic_library_linker_tool")) {
- cppDynamicLibraryLinkerTool =
- ""
- + "feature {"
- + " name: 'dynamic_library_linker_tool'"
- + " flag_set {"
- + " action: 'c++-link-dynamic-library'"
- + " flag_group {"
- + " flag: '"
- + cppLinkDynamicLibraryToolPath
- + "'"
- + " }"
- + " }"
- + "}";
- }
-
- return Joiner.on("\n")
- .join(
- ImmutableList.of(
- "action_config {",
- " config_name: 'c++-link-executable'",
- " action_name: 'c++-link-executable'",
- " tool {",
- " tool_path: 'DUMMY_TOOL'",
- " }",
- " implies: 'symbol_counts'",
- " implies: 'strip_debug_symbols'",
- " implies: 'linkstamps'",
- " implies: 'output_execpath_flags_executable'",
- " implies: 'runtime_library_search_directories'",
- " implies: 'library_search_directories'",
- " implies: 'libraries_to_link'",
- " implies: 'force_pic_flags'",
- " implies: 'legacy_link_flags'",
- " implies: 'linker_param_file'",
- " implies: 'fission_support'",
- "}",
- "action_config {",
- " config_name: 'c++-link-dynamic-library'",
- " action_name: 'c++-link-dynamic-library'",
- " tool {",
- " tool_path: 'DUMMY_TOOL'",
- " }",
- " implies: 'build_interface_libraries'",
- " implies: 'dynamic_library_linker_tool'",
- " implies: 'symbol_counts'",
- " implies: 'strip_debug_symbols'",
- " implies: 'shared_flag'",
- " implies: 'linkstamps'",
- " implies: 'output_execpath_flags'",
- " implies: 'runtime_library_search_directories'",
- " implies: 'library_search_directories'",
- " implies: 'libraries_to_link'",
- " implies: 'legacy_link_flags'",
- " implies: 'linker_param_file'",
- " implies: 'fission_support'",
- "}",
- "action_config {",
- " config_name: 'c++-link-static-library'",
- " action_name: 'c++-link-static-library'",
- " tool {",
- " tool_path: '" + arToolPath + "'",
- " }",
- " implies: 'archiver_flags'",
- " implies: 'libraries_to_link'",
- " implies: 'linker_param_file'",
- "}",
- "action_config {",
- " config_name: 'c++-link-alwayslink-static-library'",
- " action_name: 'c++-link-alwayslink-static-library'",
- " tool {",
- " tool_path: '" + arToolPath + "'",
- " }",
- " implies: 'archiver_flags'",
- " implies: 'libraries_to_link'",
- " implies: 'linker_param_file'",
- "}",
- "action_config {",
- " config_name: 'c++-link-pic-static-library'",
- " action_name: 'c++-link-pic-static-library'",
- " tool {",
- " tool_path: '" + arToolPath + "'",
- " }",
- " implies: 'archiver_flags'",
- " implies: 'libraries_to_link'",
- " implies: 'linker_param_file'",
- "}",
- "action_config {",
- " config_name: 'c++-link-alwayslink-pic-static-library'",
- " action_name: 'c++-link-alwayslink-pic-static-library'",
- " tool {",
- " tool_path: '" + arToolPath + "'",
- " }",
- " implies: 'archiver_flags'",
- " implies: 'libraries_to_link'",
- " implies: 'linker_param_file'",
- "}",
- "feature {",
- " name: 'build_interface_libraries'",
- " flag_set {",
- " expand_if_all_available: 'generate_interface_library'",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " flag: '%{generate_interface_library}'",
- " flag: '%{interface_library_builder_path}'",
- " flag: '%{interface_library_input_path}'",
- " flag: '%{interface_library_output_path}'",
- " }",
- " }",
- "}",
- // Order of feature declaration matters, cppDynamicLibraryLinkerTool has to follow
- // right after build_interface_libraries.
- cppDynamicLibraryLinkerTool,
- "feature {",
- " name: 'symbol_counts'",
- " flag_set {",
- " expand_if_all_available: 'symbol_counts_output'",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " flag: '-Wl,--print-symbol-counts=%{symbol_counts_output}'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'shared_flag'",
- " flag_set {",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " flag: '-shared'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'linkstamps'",
- " flag_set {",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " expand_if_all_available: 'linkstamp_paths'",
- " flag_group {",
- " flag: '%{linkstamp_paths}'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'output_execpath_flags'",
- " flag_set {",
- " expand_if_all_available: 'output_execpath'",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " flag: '-o'",
- " flag: '%{output_execpath}'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'output_execpath_flags_executable'",
- " flag_set {",
- " expand_if_all_available: 'output_execpath'",
- " action: 'c++-link-executable'",
- " flag_group {",
- " flag: '-o'",
- " }",
- " }",
- " flag_set {",
- " expand_if_all_available: 'skip_mostly_static'",
- " expand_if_all_available: 'output_execpath'",
- " action: 'c++-link-executable'",
- " flag_group {",
- " flag: '/dev/null'",
- " flag: '-MMD'",
- " flag: '-MF'",
- " }",
- " }",
- " flag_set {",
- " expand_if_all_available: 'output_execpath'",
- " action: 'c++-link-executable'",
- " flag_group {",
- " flag: '%{output_execpath}'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'runtime_library_search_directories',",
- " flag_set {",
- " expand_if_all_available: 'runtime_library_search_directories'",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " iterate_over: 'runtime_library_search_directories'",
- " flag_group {",
- // TODO(b/27153401): This should probably be @loader_path on osx.
- ifTrue(
- supportsEmbeddedRuntimes,
- " expand_if_all_available: 'is_cc_test_link_action'",
- " flag: ",
- " '-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}'",
- " }",
- " flag_group {",
- " expand_if_all_available: 'is_not_cc_test_link_action'"),
- " flag: '-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}'",
- " }",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'library_search_directories'",
- " flag_set {",
- " expand_if_all_available: 'library_search_directories'",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " iterate_over: 'library_search_directories'",
- " flag: '-L%{library_search_directories}'",
- " }",
- " }",
- "}",
- ifTrue(
- !features.contains("archiver_flags"),
- "feature {",
- " name: 'archiver_flags'",
- " flag_set {",
- " expand_if_all_available: 'output_execpath'",
- " action: 'c++-link-static-library'",
- " action: 'c++-link-alwayslink-static-library'",
- " action: 'c++-link-pic-static-library'",
- " action: 'c++-link-alwayslink-pic-static-library'",
- " flag_group {",
- ifLinux(platform, " flag: 'rcsD'", " flag: '%{output_execpath}'"),
- ifMac(
- platform,
- " flag: '-static'",
- " flag: '-s'",
- " flag: '-o'",
- " flag: '%{output_execpath}'"),
- " }",
- " }",
- "}"),
- "feature {",
- " name: 'libraries_to_link'",
- " flag_set {",
- " expand_if_all_available: 'libraries_to_link'",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " action: 'c++-link-static-library'",
- " action: 'c++-link-alwayslink-static-library'",
- " action: 'c++-link-pic-static-library'",
- " action: 'c++-link-alwayslink-pic-static-library'",
- " flag_group {",
- " iterate_over: 'libraries_to_link'",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'object_file_group'",
- " }",
- " flag: '-Wl,--start-lib'",
- " }",
- ifLinux(
- platform,
- " flag_group {",
- " expand_if_true: 'libraries_to_link.is_whole_archive'",
- " flag: '-Wl,-whole-archive'",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'object_file_group'",
- " }",
- " iterate_over: 'libraries_to_link.object_files'",
- " flag: '%{libraries_to_link.object_files}'",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'object_file'",
- " }",
- " flag: '%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'interface_library'",
- " }",
- " flag: '%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'static_library'",
- " }",
- " flag: '%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'dynamic_library'",
- " }",
- " flag: '-l%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'versioned_dynamic_library'",
- " }",
- " flag: '-l:%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_true: 'libraries_to_link.is_whole_archive'",
- " flag: '-Wl,-no-whole-archive'",
- " }"),
- ifMac(
- platform,
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'object_file_group'",
- " }",
- " iterate_over: 'libraries_to_link.object_files'",
- " flag_group {",
- " expand_if_false: 'libraries_to_link.is_whole_archive'",
- " flag: '%{libraries_to_link.object_files}'",
- " }",
- " flag_group {",
- " expand_if_true: 'libraries_to_link.is_whole_archive'",
- " flag: '-Wl,-force_load,%{libraries_to_link.object_files}'",
- " }",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'object_file'",
- " }",
- " flag_group {",
- " expand_if_false: 'libraries_to_link.is_whole_archive'",
- " flag: '%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_true: 'libraries_to_link.is_whole_archive'",
- " flag: '-Wl,-force_load,%{libraries_to_link.name}'",
- " }",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'interface_library'",
- " }",
- " flag_group {",
- " expand_if_false: 'libraries_to_link.is_whole_archive'",
- " flag: '%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_true: 'libraries_to_link.is_whole_archive'",
- " flag: '-Wl,-force_load,%{libraries_to_link.name}'",
- " }",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'static_library'",
- " }",
- " flag_group {",
- " expand_if_false: 'libraries_to_link.is_whole_archive'",
- " flag: '%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_true: 'libraries_to_link.is_whole_archive'",
- " flag: '-Wl,-force_load,%{libraries_to_link.name}'",
- " }",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'dynamic_library'",
- " }",
- " flag: '-l%{libraries_to_link.name}'",
- " }",
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'versioned_dynamic_library'",
- " }",
- " flag: '-l:%{libraries_to_link.name}'",
- " }"),
- " flag_group {",
- " expand_if_equal: {",
- " variable: 'libraries_to_link.type'",
- " value: 'object_file_group'",
- " }",
- " flag: '-Wl,--end-lib'",
- " }",
- " }",
- " flag_group {",
- " expand_if_true: 'thinlto_param_file'",
- " flag: '-Wl,@%{thinlto_param_file}'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'force_pic_flags'",
- " flag_set {",
- " expand_if_all_available: 'force_pic'",
- " action: 'c++-link-executable'",
- " flag_group {",
- " flag: '-pie'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'legacy_link_flags'",
- " flag_set {",
- " expand_if_all_available: 'legacy_link_flags'",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " iterate_over: 'legacy_link_flags'",
- " flag: '%{legacy_link_flags}'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'fission_support'",
- " flag_set {",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " action: 'c++-link-interface-dynamic-library'",
- " flag_group {",
- " expand_if_all_available: 'is_using_fission'",
- " flag: '-Wl,--gdb-index'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'strip_debug_symbols'",
- " flag_set {",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " action: 'c++-link-interface-dynamic-library'",
- " flag_group {",
- " expand_if_all_available: 'strip_debug_symbols'",
- " flag: '-Wl,-S'",
- " }",
- " }",
- "}",
- "feature {",
- " name: 'linker_param_file'",
- " flag_set {",
- " expand_if_all_available: 'linker_param_file'",
- " action: 'c++-link-executable'",
- " action: 'c++-link-dynamic-library'",
- " flag_group {",
- " flag: '-Wl,@%{linker_param_file}'",
- " }",
- " }",
- " flag_set {",
- " expand_if_all_available: 'linker_param_file'",
- " action: 'c++-link-static-library'",
- " action: 'c++-link-alwayslink-static-library'",
- " action: 'c++-link-pic-static-library'",
- " action: 'c++-link-alwayslink-pic-static-library'",
- " flag_group {",
- " flag: '@%{linker_param_file}'",
- " }",
- " }",
- "}"));
- }
-
- private static String ifLinux(CppLinkPlatform platform, String... lines) {
- return ifTrue(platform == CppLinkPlatform.LINUX, lines);
- }
-
- private static String ifMac(CppLinkPlatform platform, String... lines) {
- return ifTrue(platform == CppLinkPlatform.MAC, lines);
- }
-
- private static String ifTrue(boolean condition, String... lines) {
- if (condition) {
- return Joiner.on("\n").join(lines);
- } else {
- return "";
- }
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java
index 2abda844fe..1a68752351 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java
@@ -381,7 +381,7 @@ public final class LinkCommandLine extends CommandLine {
List<String> argv = new ArrayList<>();
// TODO(b/30109612): Extract this switch into individual crosstools once action configs are no
- // longer hardcoded in CppLinkActionConfigs
+ // longer hardcoded in CppActionConfigs.
switch (linkTargetType) {
case EXECUTABLE:
argv.add(cppConfiguration.getCppExecutable().getPathString());