aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2015-07-23 12:55:53 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-07-23 12:59:16 +0000
commit196d3b4fbbc343851e5c86dba2b1fdd4ec47eb40 (patch)
tree40f2a8ddce2e0eea671328bd68cb515f136e2e4c /src/main/java/com/google/devtools/build
parent35248d35a220331d8fd985df1d2b82bcdf158438 (diff)
Change the default for CcLibraryHelper.emitLinkActionsIfEmpty to false.
This is renamed from the previous name emitCompileActionsIfEmpty, which was a misnomer, because it didn't affect compile actions at all. Update the callers to no longer call the method if not necessary, which leaves only CcLibrary. CcBinary doesn't hit the link action code path, as it sets the link type to either DYNAMIC_LIBRARY or EXECUTABLE. This is in preparation for removing the implicit outputs from cc_library, which should allow building header-only libraries on MacOS. -- MOS_MIGRATED_REVID=98927221
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java54
3 files changed, 42 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java
index fcbd836416..10edf664f3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java
@@ -76,6 +76,13 @@ public class CcCompilationOutputs {
}
/**
+ * Returns whether this set of outputs has any object or .pic object files.
+ */
+ public boolean isEmpty() {
+ return picObjectFiles.isEmpty() && objectFiles.isEmpty();
+ }
+
+ /**
* Returns an unmodifiable view of the .o or .pic.o files set.
*
* @param usePic whether to return .pic.o files
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
index a20532921b..62d3dd7e7f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
@@ -131,6 +131,9 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
.enableCcNativeLibrariesProvider()
.enableInterfaceSharedObjects()
.enableCompileProviders()
+ // Generate .a and .so outputs even without object files to fulfill the rule class contract
+ // wrt. implicit output files.
+ .setGenerateLinkActionsIfEmpty(true)
.setNeverLink(neverLink)
.setHeadersCheckingMode(common.determineHeadersCheckingMode())
.addCopts(common.getCopts())
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
index b74165e034..535ec3cd83 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
@@ -178,7 +178,7 @@ public final class CcLibraryHelper {
private final List<LibraryToLink> picStaticLibraries = new ArrayList<>();
private final List<LibraryToLink> dynamicLibraries = new ArrayList<>();
- private boolean emitCompileActionsIfEmpty = true;
+ private boolean emitLinkActionsIfEmpty;
private boolean emitCcNativeLibrariesProvider;
private boolean emitCcSpecificLinkParamsProvider;
private boolean emitInterfaceSharedObjects;
@@ -517,12 +517,14 @@ public final class CcLibraryHelper {
}
/**
- * Enables or disables generation of compile actions if there are no sources. Some rules declare a
- * .a or .so implicit output, which requires that these files are created even if there are no
- * source files, so be careful when calling this.
+ * Enables or disables generation of link actions if there are no object files. Some rules declare
+ * a <code>.a</code> or <code>.so</code> implicit output, which requires that these files are
+ * created even if there are no object files, so be careful when calling this.
+ *
+ * <p>This is disabled by default.
*/
- public CcLibraryHelper setGenerateCompileActionsIfEmpty(boolean emitCompileActionsIfEmpty) {
- this.emitCompileActionsIfEmpty = emitCompileActionsIfEmpty;
+ public CcLibraryHelper setGenerateLinkActionsIfEmpty(boolean emitLinkActionsIfEmpty) {
+ this.emitLinkActionsIfEmpty = emitLinkActionsIfEmpty;
return this;
}
@@ -593,9 +595,6 @@ public final class CcLibraryHelper {
}
}
- CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY;
- CcCompilationOutputs ccOutputs = new CcCompilationOutputs.Builder().build();
-
CppModel model = new CppModel(ruleContext, semantics)
.addSources(sources)
.addCopts(copts)
@@ -615,19 +614,30 @@ public final class CcLibraryHelper {
initializeCppCompilationContext(model, featureConfiguration);
model.setContext(cppCompilationContext);
boolean compileHeaderModules = featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES);
- if (emitCompileActionsIfEmpty || !sources.isEmpty() || compileHeaderModules) {
- Preconditions.checkState(
- !compileHeaderModules || cppCompilationContext.getCppModuleMap() != null,
- "All cc rules must support module maps.");
- ccOutputs = model.createCcCompileActions();
- if (!objectFiles.isEmpty() || !picObjectFiles.isEmpty()) {
- // Merge the pre-compiled object files into the compiler outputs.
- ccOutputs = new CcCompilationOutputs.Builder()
- .merge(ccOutputs)
- .addObjectFiles(objectFiles)
- .addPicObjectFiles(picObjectFiles)
- .build();
- }
+ Preconditions.checkState(
+ !compileHeaderModules || cppCompilationContext.getCppModuleMap() != null,
+ "All cc rules must support module maps.");
+
+ // Create compile actions (both PIC and non-PIC).
+ CcCompilationOutputs ccOutputs = model.createCcCompileActions();
+ if (!objectFiles.isEmpty() || !picObjectFiles.isEmpty()) {
+ // Merge the pre-compiled object files into the compiler outputs.
+ ccOutputs = new CcCompilationOutputs.Builder()
+ .merge(ccOutputs)
+ .addObjectFiles(objectFiles)
+ .addPicObjectFiles(picObjectFiles)
+ .build();
+ }
+
+ // Create link actions (only if there are object files or if explicitly requested).
+ CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY;
+ if (emitLinkActionsIfEmpty || !ccOutputs.isEmpty()) {
+ // On some systems, the linker gives an error message if there are no input files. Even with
+ // the check above, this can still happen if there is a .nopic.o or .o files in srcs, but no
+ // other files. To fix that, we'd have to check for each link action individually.
+ //
+ // An additional pre-existing issue is that the header check tokens are dropped if we don't
+ // generate any link actions, effectively disabling header checking in some cases.
if (linkType.isStaticLibraryLink()) {
// TODO(bazel-team): This can't create the link action for a cc_binary yet.
ccLinkingOutputs = model.createCcLinkActions(ccOutputs);