Skip to content

Commit

Permalink
Changes cc_library to consume headers specified in the "hdrs" attribu…
Browse files Browse the repository at this point in the history
…te of an

objc_library that it depends on.

See #3352

PiperOrigin-RevId: 185371993
  • Loading branch information
calpeyser authored and Copybara-Service committed Feb 12, 2018
1 parent a92cde1 commit db61b31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
public final class ObjcCommon {

/** Filters fileset artifacts out of a group of artifacts. */
public static Iterable<Artifact> filterFileset(Iterable<Artifact> artifacts) {
public static ImmutableList<Artifact> filterFileset(Iterable<Artifact> artifacts) {
ImmutableList.Builder<Artifact> inputs = ImmutableList.<Artifact>builder();
for (Artifact artifact : artifacts) {
if (!artifact.isFileset()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes;
import com.google.devtools.build.lib.syntax.Type;
import java.util.Map;
Expand Down Expand Up @@ -87,9 +88,15 @@ public ConfiguredTarget create(RuleContext ruleContext)
J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder()
.addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET,
J2ObjcEntryClassProvider.class)).build();
CppCompilationContext cppCompilationContext =
new CppCompilationContext.Builder(ruleContext)
.addDeclaredIncludeSrcs(CompilationAttributes.Builder
.fromRuleContext(ruleContext).build().hdrs().toCollection())
.build();

return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build())
.addNativeDeclaredProvider(common.getObjcProvider())
.addProvider(CppCompilationContext.class, cppCompilationContext)
.addProvider(J2ObjcEntryClassProvider.class, j2ObjcEntryClassProvider)
.addProvider(J2ObjcMappingFileProvider.class, j2ObjcMappingFileProvider)
.addProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1971,4 +1971,16 @@ public void testObjcSourcesFeatureObjc() throws Exception {
public void testObjcSourcesFeatureObjcPlusPlus() throws Exception {
assertThat(containsObjcFeature("c.mm")).isTrue();
}

@Test
public void testHeaderPassedToCcLib() throws Exception {
createLibraryTargetWriter("//objc:lib").setList("hdrs", "objc_hdr.h").write();
ScratchAttributeWriter.fromLabelString(this, "cc_library", "//cc:lib")
.setList("srcs", "a.cc")
.setList("deps", "//objc:lib")
.write();
CommandAction compileAction = compileAction("//cc:lib", "a.o");
assertThat(Artifact.toRootRelativePaths(compileAction.getPossibleInputsForTesting()))
.contains("objc/objc_hdr.h");
}
}

0 comments on commit db61b31

Please sign in to comment.