diff options
author | 2016-04-14 22:23:36 +0000 | |
---|---|---|
committer | 2016-04-15 07:37:28 +0000 | |
commit | df82ad922e5e4fb3eb7664339a288f421b3b6d96 (patch) | |
tree | 94c8d515e2d9edefd8ee257a3067e2bf0e7e5ac1 | |
parent | 00d0938f61c0698d0c30a76d1838e2514c9b19f8 (diff) |
Allows CcLibraryHelper's acceptance of objc source to be paramaterized. For cc_* targets, CcLibraryHelper will not process objc source files, which may have been provided accidentally though a filegroup.
Note: This is note intended to prevent illegal sources for cc_* targets - that will be implemented in a different CL. This will involve making changes to filtering occuring in CcCommon, which for now will permit objc source.
--
MOS_MIGRATED_REVID=119897621
3 files changed, 72 insertions, 13 deletions
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 979c64599a..f9a935a9eb 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 @@ -13,6 +13,8 @@ // limitations under the License. package com.google.devtools.build.lib.rules.cpp; +import static com.google.devtools.build.lib.rules.cpp.CcLibraryHelper.SourceCategory; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -207,7 +209,7 @@ public final class CcCommon { Label oldLabel = map.put(artifact, provider.getLabel()); boolean isHeader = CppFileTypes.CPP_HEADER.matches(artifact.getExecPath()); if (!isHeader - && CcLibraryHelper.SOURCE_TYPES.matches(artifact.getExecPathString()) + && SourceCategory.CC_AND_OBJC.getSourceTypes().matches(artifact.getExecPathString()) && oldLabel != null && !oldLabel.equals(provider.getLabel())) { ruleContext.attributeError("srcs", String.format( @@ -459,7 +461,8 @@ public final class CcCommon { for (FileProvider provider : ruleContext.getPrerequisites("srcs", Mode.TARGET, FileProvider.class)) { prerequisites.addAll( - FileType.filter(provider.getFilesToBuild(), CcLibraryHelper.SOURCE_TYPES)); + FileType.filter( + provider.getFilesToBuild(), SourceCategory.CC_AND_OBJC.getSourceTypes())); } } prerequisites.addTransitive(context.getDeclaredIncludeSrcs()); 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 1ec2c57387..3b969b8d1a 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 @@ -69,13 +69,42 @@ import javax.annotation.Nullable; * methods. */ public final class CcLibraryHelper { - static final FileTypeSet SOURCE_TYPES = - FileTypeSet.of( - CppFileTypes.CPP_SOURCE, - CppFileTypes.CPP_HEADER, - CppFileTypes.C_SOURCE, - CppFileTypes.ASSEMBLER, - CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR); + + /** + * A group of source file types for builds controlled by CcLibraryHelper. Determines what + * file types CcLibraryHelper considers sources. + */ + public static enum SourceCategory { + CC( + FileTypeSet.of( + CppFileTypes.CPP_SOURCE, + CppFileTypes.CPP_HEADER, + CppFileTypes.C_SOURCE, + CppFileTypes.ASSEMBLER, + CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR)), + CC_AND_OBJC( + FileTypeSet.of( + CppFileTypes.CPP_SOURCE, + CppFileTypes.CPP_HEADER, + CppFileTypes.OBJC_SOURCE, + CppFileTypes.OBJCPP_SOURCE, + CppFileTypes.C_SOURCE, + CppFileTypes.ASSEMBLER, + CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR)); + + private final FileTypeSet sourceTypeSet; + + private SourceCategory(FileTypeSet sourceTypeSet) { + this.sourceTypeSet = sourceTypeSet; + } + + /** + * Returns the set of file types that are valid for this catagory. + */ + public FileTypeSet getSourceTypes() { + return sourceTypeSet; + } + } /** Function for extracting module maps from CppCompilationDependencies. */ public static final Function<TransitiveInfoCollection, CppModuleMap> CPP_DEPS_TO_MODULES = @@ -195,18 +224,43 @@ public final class CcLibraryHelper { private boolean emitDynamicLibrary = true; private boolean checkDepsGenerateCpp = true; private boolean emitCompileProviders; + private SourceCategory sourceCatagory; private final FeatureConfiguration featureConfiguration; - public CcLibraryHelper(RuleContext ruleContext, CppSemantics semantics, - FeatureConfiguration featureConfiguration) { + /** + * Creates a CcLibraryHelper. + * + * @param ruleContext the RuleContext for the rule being built + * @param semantics CppSemantics for the build + * @param featureConfiguration activated features and action configs for the build + * @param sourceCatagory the candidate source types for the build + */ + public CcLibraryHelper( + RuleContext ruleContext, + CppSemantics semantics, + FeatureConfiguration featureConfiguration, + SourceCategory sourceCatagory) { this.ruleContext = Preconditions.checkNotNull(ruleContext); this.configuration = ruleContext.getConfiguration(); this.semantics = Preconditions.checkNotNull(semantics); this.featureConfiguration = Preconditions.checkNotNull(featureConfiguration); + this.sourceCatagory = Preconditions.checkNotNull(sourceCatagory); } /** + * Creates a CcLibraryHelper for cpp source files. + * + * @param ruleContext the RuleContext for the rule being built + * @param semantics CppSemantics for the build + * @param featureConfiguration activated features and action configs for the build + */ + public CcLibraryHelper( + RuleContext ruleContext, CppSemantics semantics, FeatureConfiguration featureConfiguration) { + this(ruleContext, semantics, featureConfiguration, SourceCategory.CC); + } + + /** * Sets fields that overlap for cc_library and cc_binary rules. */ public CcLibraryHelper fromCommon(CcCommon common) { @@ -330,7 +384,7 @@ public final class CcLibraryHelper { private void addSource(Artifact source, Label label) { boolean isHeader = CppFileTypes.CPP_HEADER.matches(source.getExecPath()); boolean isTextualInclude = CppFileTypes.CPP_TEXTUAL_INCLUDE.matches(source.getExecPath()); - boolean isCompiledSource = SOURCE_TYPES.matches(source.getExecPathString()); + boolean isCompiledSource = sourceCatagory.getSourceTypes().matches(source.getExecPathString()); if (isHeader || isTextualInclude) { privateHeaders.add(source); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java index 478759ab34..d97dbb9931 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java @@ -26,7 +26,9 @@ import java.util.regex.Pattern; public final class CppFileTypes { public static final FileType CPP_SOURCE = FileType.of(".cc", ".cpp", ".cxx", ".c++", ".C"); public static final FileType C_SOURCE = FileType.of(".c"); - + public static final FileType OBJC_SOURCE = FileType.of(".m"); + public static final FileType OBJCPP_SOURCE = FileType.of(".mm"); + // Filetypes that generate LLVM bitcode when -flto is specified. public static final FileTypeSet LTO_SOURCE = FileTypeSet.of(CppFileTypes.CPP_SOURCE, CppFileTypes.C_SOURCE); |