Skip to content

Commit

Permalink
Get rid of J2ObjcCcInfo
Browse files Browse the repository at this point in the history
This was created to avoid conflicting with the CcInfo produced by the
proto_library, but proto_library's CcInfo is gone.

PiperOrigin-RevId: 416284043
  • Loading branch information
googlewalt authored and Copybara-Service committed Dec 14, 2021
1 parent ad663a7 commit 8dcf27e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
Expand Down Expand Up @@ -324,9 +323,8 @@ private ConfiguredAspect buildAspect(
.addNativeDeclaredProvider(
exportedJ2ObjcMappingFileProvider(base, ruleContext, directJ2ObjcMappingFileProvider))
.addNativeDeclaredProvider(common.getObjcProvider())
.addProvider(
J2ObjcCcInfo.build(
CcInfo.builder().setCcCompilationContext(ccCompilationContext).build()))
.addNativeDeclaredProvider(
CcInfo.builder().setCcCompilationContext(ccCompilationContext).build())
.build();
}

Expand Down Expand Up @@ -882,13 +880,8 @@ private static ObjcCommon common(
|| ruleContext.attributes().has(attrName, BuildType.LABEL)) {
ImmutableList.Builder<CcInfo> ccInfoList = new ImmutableList.Builder<>();
for (TransitiveInfoCollection dep : ruleContext.getPrerequisites(attrName)) {
J2ObjcCcInfo j2objcCcInfo = dep.getProvider(J2ObjcCcInfo.class);
CcInfo ccInfo = dep.get(CcInfo.PROVIDER);
// If a dep has both a J2ObjcCcInfo and a CcInfo, skip the CcInfo. This can only happen
// for a proto_library, whose CcInfo we don't use and may have poisoned defines.
if (j2objcCcInfo != null) {
ccInfoList.add(j2objcCcInfo.getCcInfo());
} else if (ccInfo != null) {
if (ccInfo != null) {
ccInfoList.add(ccInfo);
}
}
Expand All @@ -910,24 +903,4 @@ private static ObjcCommon common(
.setIntermediateArtifacts(intermediateArtifacts)
.build();
}

/**
* A wrapper for {@link CcInfo}. The aspect generates this instead of a raw CcInfo, because it may
* visit a proto_library rule which already has a CcInfo.
*/
public static final class J2ObjcCcInfo implements TransitiveInfoProvider {
private final CcInfo ccInfo;

public J2ObjcCcInfo(CcInfo ccInfo) {
this.ccInfo = ccInfo;
}

public CcInfo getCcInfo() {
return ccInfo;
}

public static J2ObjcCcInfo build(CcInfo ccInfo) {
return new J2ObjcCcInfo(ccInfo);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.google.devtools.build.lib.rules.objc;

import static com.google.devtools.build.lib.collect.nestedset.Order.STABLE_ORDER;
import static java.util.stream.Collectors.toList;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.Artifact;
Expand All @@ -30,7 +29,6 @@
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.cpp.CcInfo;
import com.google.devtools.build.lib.rules.cpp.CppSemantics;
import com.google.devtools.build.lib.rules.objc.J2ObjcAspect.J2ObjcCcInfo;
import java.util.List;

/**
Expand All @@ -50,14 +48,12 @@ protected J2ObjcLibrary(CppSemantics cppSemantics) {}
ImmutableList.of("java_import", "java_library", "java_proto_library", "proto_library");

private ObjcCommon common(RuleContext ruleContext) throws InterruptedException {
List<J2ObjcCcInfo> j2objcCcInfos = ruleContext.getPrerequisites("deps", J2ObjcCcInfo.class);
return new ObjcCommon.Builder(ObjcCommon.Purpose.LINK_ONLY, ruleContext)
.setCompilationAttributes(
CompilationAttributes.Builder.fromRuleContext(ruleContext).build())
.addDeps(ruleContext.getPrerequisites("deps"))
.addDeps(ruleContext.getPrerequisites("jre_deps"))
.addDirectCcCompilationContexts(
j2objcCcInfos.stream().map(J2ObjcCcInfo::getCcInfo).collect(toList()))
.addDirectCcCompilationContexts(ruleContext.getPrerequisites("deps", CcInfo.PROVIDER))
.setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import com.google.devtools.build.lib.rules.cpp.CppModuleMapAction;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import com.google.devtools.build.lib.rules.cpp.UmbrellaHeaderAction;
import com.google.devtools.build.lib.rules.objc.J2ObjcAspect.J2ObjcCcInfo;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -120,7 +119,7 @@ public void testJ2ObjCAspectDisablesParseHeaders() throws Exception {
ConfiguredTarget j2objcAspectTarget =
getJ2ObjCAspectConfiguredTarget("//java/com/google/dummy/test:test");
CcCompilationContext ccCompilationContext =
j2objcAspectTarget.getProvider(J2ObjcCcInfo.class).getCcInfo().getCcCompilationContext();
j2objcAspectTarget.get(CcInfo.PROVIDER).getCcCompilationContext();

assertThat(baseArtifactNames(ccCompilationContext.getHeaderTokens().toList()))
.doesNotContain("test.h.processed");
Expand Down Expand Up @@ -311,7 +310,7 @@ public void testJavaProtoLibraryWithProtoLibrary() throws Exception {

ObjcProvider objcProvider = target.get(ObjcProvider.STARLARK_CONSTRUCTOR);
CcCompilationContext ccCompilationContext =
target.getProvider(J2ObjcCcInfo.class).getCcInfo().getCcCompilationContext();
target.get(CcInfo.PROVIDER).getCcCompilationContext();
Artifact headerFile = getGenfilesArtifact("test.j2objc.pb.h", test, getJ2ObjcAspect());
Artifact sourceFile = getGenfilesArtifact("test.j2objc.pb.m", test, getJ2ObjcAspect());
assertThat(ccCompilationContext.getDeclaredIncludeSrcs().toList()).contains(headerFile);
Expand Down Expand Up @@ -361,7 +360,7 @@ public void testJavaProtoLibraryWithProtoLibrary_external() throws Exception {

ObjcProvider objcProvider = target.get(ObjcProvider.STARLARK_CONSTRUCTOR);
CcCompilationContext ccCompilationContext =
target.getProvider(J2ObjcCcInfo.class).getCcInfo().getCcCompilationContext();
target.get(CcInfo.PROVIDER).getCcCompilationContext();

Artifact headerFile =
getGenfilesArtifact("../external/bla/foo/test.j2objc.pb.h", test, getJ2ObjcAspect());
Expand Down Expand Up @@ -461,7 +460,7 @@ public void testTranspilationActionTreeArtifactOutputsFromSourceJar() throws Exc
ConfiguredTarget target = getJ2ObjCAspectConfiguredTarget("//java/com/google/transpile:dummy");
ObjcProvider provider = target.get(ObjcProvider.STARLARK_CONSTRUCTOR);
CcCompilationContext ccCompilationContext =
target.getProvider(J2ObjcCcInfo.class).getCcInfo().getCcCompilationContext();
target.get(CcInfo.PROVIDER).getCcCompilationContext();
Artifact srcJarSources = getFirstArtifactEndingWith(
provider.get(ObjcProvider.SOURCE), "source_files");
Artifact srcJarHeaders =
Expand Down

0 comments on commit 8dcf27e

Please sign in to comment.