aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2015-08-03 13:22:57 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-08-04 09:08:13 +0000
commitb8634721b2446a895729d48d92bee230769078ae (patch)
tree917188f5c1151cf2e6b9d95534d8358c0889d52f /src/main/java/com/google/devtools/build/lib
parent48685bf34fdde1f68d9decb5060802e7b559db63 (diff)
Lazy evaluation of C & C++ sources in CcCommon.
-- MOS_MIGRATED_REVID=99718820
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java20
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java1
4 files changed, 14 insertions, 21 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
index a0d4f052db..4be3a57e69 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
@@ -90,13 +90,13 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
public static final String INTERMEDIATE_DWP_DIR = "_dwps";
private static Runfiles collectRunfiles(RuleContext context,
- CcCommon common,
CcLinkingOutputs linkingOutputs,
CppCompilationContext cppCompilationContext,
LinkStaticness linkStaticness,
NestedSet<Artifact> filesToBuild,
Iterable<Artifact> fakeLinkerInputs,
- boolean fake) {
+ boolean fake,
+ ImmutableList<Pair<Artifact, Label>> cAndCppSources) {
Runfiles.Builder builder = new Runfiles.Builder();
Function<TransitiveInfoCollection, Runfiles> runfilesMapping =
CppRunfilesProvider.runfilesFunction(linkStaticness != LinkStaticness.DYNAMIC);
@@ -136,7 +136,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
// attribute. We do not provide the auxiliary inputs, because they are only used when we
// do FDO compilation, and cc_fake_binary does not support FDO.
builder.addSymlinksToArtifacts(
- Iterables.transform(common.getCAndCppSources(), Pair.<Artifact, Label>firstFunction()));
+ Iterables.transform(cAndCppSources, Pair.<Artifact, Label>firstFunction()));
builder.addSymlinksToArtifacts(cppCompilationContext.getDeclaredIncludeSrcs());
// Add additional files that are referenced from the compile command, like module maps
// or header modules.
@@ -163,9 +163,11 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
List<String> linkopts = common.getLinkopts();
LinkStaticness linkStaticness = getLinkStaticness(ruleContext, linkopts, cppConfiguration);
+ ImmutableList<Pair<Artifact, Label>> cAndCppSources = common.getCAndCppSources();
CcLibraryHelper helper =
new CcLibraryHelper(ruleContext, semantics, featureConfiguration)
.fromCommon(common)
+ .addSources(cAndCppSources)
.addDeps(ImmutableList.of(CppHelper.mallocForTarget(ruleContext)))
.addPrivateHeaders(
FileType.filter(
@@ -270,8 +272,9 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
// logical since all symlinked libraries will be linked anyway and would
// not require manual loading but if we do, then we would need to collect
// their names and use a different constructor below.
- Runfiles runfiles = collectRunfiles(ruleContext, common, linkingOutputs,
- cppCompilationContext, linkStaticness, filesToBuild, fakeLinkerInputs, fake);
+ Runfiles runfiles = collectRunfiles(
+ ruleContext, linkingOutputs, cppCompilationContext, linkStaticness, filesToBuild,
+ fakeLinkerInputs, fake, cAndCppSources);
RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(
ruleContext, runfiles, executable, ruleContext.getConfiguration().buildRunfiles());
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 770b948088..84c677aa07 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
@@ -98,15 +98,12 @@ public final class CcCommon {
/** Active toolchain features. */
private final FeatureConfiguration featureConfiguration;
- private final ImmutableList<Pair<Artifact, Label>> cAndCppSources;
-
private final RuleContext ruleContext;
public CcCommon(RuleContext ruleContext, FeatureConfiguration featureConfiguration) {
this.ruleContext = ruleContext;
this.cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
this.featureConfiguration = featureConfiguration;
- this.cAndCppSources = collectCAndCppSources();
}
/**
@@ -196,25 +193,18 @@ public final class CcCommon {
return new TransitiveLipoInfoProvider(scannableBuilder.build());
}
+ private boolean shouldProcessHeaders() {
+ return featureConfiguration.isEnabled(CppRuleClasses.PREPROCESS_HEADERS)
+ || featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS);
+ }
+
/**
* Returns a list of ({@link Artifact}, {@link Label}) pairs. Each pair represents an input
* source file and the label of the rule that generates it (or the label of the source file
* itself if it is an input file)
*/
ImmutableList<Pair<Artifact, Label>> getCAndCppSources() {
- return cAndCppSources;
- }
-
- private boolean shouldProcessHeaders() {
- return featureConfiguration.isEnabled(CppRuleClasses.PREPROCESS_HEADERS)
- || featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS);
- }
-
- private ImmutableList<Pair<Artifact, Label>> collectCAndCppSources() {
Map<Artifact, Label> map = Maps.newLinkedHashMap();
- if (!hasAttribute("srcs", Type.LABEL_LIST)) {
- return ImmutableList.<Pair<Artifact, Label>>of();
- }
Iterable<FileProvider> providers =
ruleContext.getPrerequisites("srcs", Mode.TARGET, FileProvider.class);
// TODO(bazel-team): Move header processing logic down in the stack (to CcLibraryHelper or
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 5c1be9593e..1a6a75dfe0 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
@@ -120,6 +120,7 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
.fromCommon(common)
.addLinkopts(common.getLinkopts())
+ .addSources(common.getCAndCppSources())
.addPublicHeaders(CcCommon.getHeaders(ruleContext))
.enableCcNativeLibrariesProvider()
.enableCompileProviders()
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 795f31f3e5..440c715b9a 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
@@ -207,7 +207,6 @@ public final class CcLibraryHelper {
.addIncludeDirs(common.getIncludeDirs())
.addLooseIncludeDirs(common.getLooseIncludeDirs())
.addPicIndependentObjectFiles(common.getLinkerScripts())
- .addSources(common.getCAndCppSources())
.addSystemIncludeDirs(common.getSystemIncludeDirs())
.setNoCopts(common.getNoCopts())
.setHeadersCheckingMode(common.determineHeadersCheckingMode());