aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
diff options
context:
space:
mode:
authorGravatar plf <plf@google.com>2018-05-25 09:36:08 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-25 09:37:29 -0700
commit780801c87227754fac166ec54d6f5f52c40fee35 (patch)
treeb86deaad808a9b2f54f4063af50d9c13931be1b3 /src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
parent9fa72497c03573175eda1130617630bb0904faf2 (diff)
C++: Separates adding sources and private headers to CcCompilationHelper
This is part of a chain of CLs that will pull initialization of CcCompilationContext from CcCompilationHelper. RELNOTES:none PiperOrigin-RevId: 198060027
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
index 5b782ef492..cec53199e4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
@@ -387,6 +387,33 @@ public final class CcCompilationHelper {
return this;
}
+ public CcCompilationHelper addPrivateHeaders(Collection<Artifact> privateHeaders) {
+ for (Artifact privateHeader : privateHeaders) {
+ addPrivateHeader(privateHeader, ruleContext.getLabel());
+ }
+ return this;
+ }
+
+ public CcCompilationHelper addPrivateHeaders(Iterable<Pair<Artifact, Label>> privateHeaders) {
+ for (Pair<Artifact, Label> headerLabelPair : privateHeaders) {
+ addPrivateHeader(headerLabelPair.first, headerLabelPair.second);
+ }
+ return this;
+ }
+
+ private CcCompilationHelper addPrivateHeader(Artifact privateHeader, Label label) {
+ boolean isHeader = CppFileTypes.CPP_HEADER.matches(privateHeader.getExecPath());
+ boolean isTextualInclude =
+ CppFileTypes.CPP_TEXTUAL_INCLUDE.matches(privateHeader.getExecPath());
+ Preconditions.checkState(isHeader || isTextualInclude);
+
+ if (shouldProcessHeaders() && !isTextualInclude) {
+ compilationUnitSources.add(CppSource.create(privateHeader, label, CppSource.Type.HEADER));
+ }
+ this.privateHeaders.add(privateHeader);
+ return this;
+ }
+
/**
* Add the corresponding files as source files. These may also be header files, in which case they
* will not be compiled, but also not made visible as includes to dependent rules. The given build
@@ -453,23 +480,19 @@ public final class CcCompilationHelper {
*/
private void addSource(Artifact source, Label label) {
Preconditions.checkNotNull(featureConfiguration);
- boolean isHeader = CppFileTypes.CPP_HEADER.matches(source.getExecPath());
- boolean isTextualInclude = CppFileTypes.CPP_TEXTUAL_INCLUDE.matches(source.getExecPath());
+ Preconditions.checkState(!CppFileTypes.CPP_HEADER.matches(source.getExecPath()));
// We assume TreeArtifacts passed in are directories containing proper sources for compilation.
- boolean isCompiledSource =
- sourceCategory.getSourceTypes().matches(source.getExecPathString())
- || source.isTreeArtifact();
- if (isHeader || isTextualInclude) {
- privateHeaders.add(source);
- }
- if (isTextualInclude || !isCompiledSource || (isHeader && !shouldProcessHeaders())) {
+ if (!sourceCategory.getSourceTypes().matches(source.getExecPathString())
+ && !source.isTreeArtifact()) {
+ // TODO(plf): If it's a non-source file we ignore it. This is only the case for precompiled
+ // files which should be forbidden in srcs of cc_library|binary and instead be migrated to
+ // cc_import rules.
return;
}
+
boolean isClifInputProto = CppFileTypes.CLIF_INPUT_PROTO.matches(source.getExecPathString());
CppSource.Type type;
- if (isHeader) {
- type = CppSource.Type.HEADER;
- } else if (isClifInputProto) {
+ if (isClifInputProto) {
type = CppSource.Type.CLIF_INPUT_PROTO;
} else {
type = CppSource.Type.SOURCE;