Skip to content

Commit

Permalink
Automated rollback of commit cae05a9.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Not needed for j2objc Starlarkification.

*** Original change description ***

Change j2objc aspect generation to genfiles.

This is a partial rollback of 4710ef8. It could make migrations to Starlark rules easier.

PiperOrigin-RevId: 456477281
Change-Id: I49e97db5605052079ac96a1f87e25cecf95459a5
  • Loading branch information
comius authored and copybara-github committed Jun 22, 2022
1 parent 5aafdef commit 6a3f6fb
Showing 1 changed file with 8 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.actions.ParamFileInfo;
import com.google.devtools.build.lib.actions.ParameterFile;
Expand Down Expand Up @@ -79,7 +78,6 @@
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -642,11 +640,11 @@ private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions(
ImmutableList<Artifact> outputHeaderMappingFiles =
filteredProtoSources.isEmpty()
? ImmutableList.of()
: getGeneratedOutputs(ruleContext, base, ".j2objc.mapping");
: ProtoCommon.declareGeneratedFiles(ruleContext, base, ".j2objc.mapping");
ImmutableList<Artifact> outputClassMappingFiles =
filteredProtoSources.isEmpty()
? ImmutableList.of()
: getGeneratedOutputs(ruleContext, base, ".clsmap.properties");
: ProtoCommon.declareGeneratedFiles(ruleContext, base, ".clsmap.properties");
ImmutableList<Artifact> outputs =
ImmutableList.<Artifact>builder()
.addAll(j2ObjcSource.getObjcSrcs())
Expand All @@ -655,14 +653,14 @@ private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions(
.addAll(outputClassMappingFiles)
.build();

String gendirPath = getProtoOutputRoot(ruleContext).getPathString();
String bindirPath = getProtoOutputRoot(ruleContext).getPathString();

ProtoCommon.compile(
ruleContext,
base,
checkNotNull(protoToolchain),
outputs,
gendirPath,
bindirPath,
"Generating j2objc proto_library %{label}");

return new J2ObjcMappingFileProvider(
Expand Down Expand Up @@ -782,10 +780,10 @@ private static J2ObjcSource protoJ2ObjcSource(
ruleContext.getTarget().getLabel(),
protoSources.isEmpty()
? ImmutableList.of()
: getGeneratedOutputs(ruleContext, protoTarget, ".j2objc.pb.m"),
: ProtoCommon.declareGeneratedFiles(ruleContext, protoTarget, ".j2objc.pb.m"),
protoSources.isEmpty()
? ImmutableList.of()
: getGeneratedOutputs(ruleContext, protoTarget, ".j2objc.pb.h"),
: ProtoCommon.declareGeneratedFiles(ruleContext, protoTarget, ".j2objc.pb.h"),
objcFileRootExecPath,
SourceType.PROTO,
headerSearchPaths,
Expand All @@ -794,10 +792,10 @@ private static J2ObjcSource protoJ2ObjcSource(

private static PathFragment getProtoOutputRoot(RuleContext ruleContext) {
if (ruleContext.getConfiguration().isSiblingRepositoryLayout()) {
return ruleContext.getGenfilesFragment();
return ruleContext.getBinFragment();
}
return ruleContext
.getGenfilesFragment()
.getBinFragment()
.getRelative(ruleContext.getLabel().getRepository().getExecPath(false));
}

Expand Down Expand Up @@ -901,22 +899,4 @@ private static ObjcCommon common(
.setIntermediateArtifacts(intermediateArtifacts)
.build();
}

public static ImmutableList<Artifact> getGeneratedOutputs(
RuleContext ruleContext, ConfiguredTarget target, String extension) {
ImmutableList.Builder<Artifact> outputsBuilder = new ImmutableList.Builder<>();
ArtifactRoot genfiles = ruleContext.getGenfilesDirectory();
for (Artifact src : target.get(ProtoInfo.PROVIDER).getDirectProtoSources()) {
PathFragment srcPath =
src.getOutputDirRelativePath(ruleContext.getConfiguration().isSiblingRepositoryLayout());

// Note that two proto_library rules can have the same source file, so this is actually a
// shared action. NB: This can probably result in action conflicts if the proto_library rules
// are not the same.
outputsBuilder.add(
ruleContext.getShareableArtifact(
FileSystemUtils.replaceExtension(srcPath, extension), genfiles));
}
return outputsBuilder.build();
}
}

0 comments on commit 6a3f6fb

Please sign in to comment.