From 6a3f6fb331b2937d4ec9fbd81877a3fee110b3fa Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 22 Jun 2022 03:56:29 -0700 Subject: [PATCH] Automated rollback of commit cae05a97e07da74566844629958270ed09642163. *** Reason for rollback *** Not needed for j2objc Starlarkification. *** Original change description *** Change j2objc aspect generation to genfiles. This is a partial rollback of https://github.com/bazelbuild/bazel/commit/4710ef82ce34572878e07c52e83a0144d707f140. It could make migrations to Starlark rules easier. PiperOrigin-RevId: 456477281 Change-Id: I49e97db5605052079ac96a1f87e25cecf95459a5 --- .../build/lib/rules/objc/J2ObjcAspect.java | 36 +++++-------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java index 2116b9e7f3e85e..5c80237b5b381d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java @@ -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; @@ -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; @@ -642,11 +640,11 @@ private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions( ImmutableList outputHeaderMappingFiles = filteredProtoSources.isEmpty() ? ImmutableList.of() - : getGeneratedOutputs(ruleContext, base, ".j2objc.mapping"); + : ProtoCommon.declareGeneratedFiles(ruleContext, base, ".j2objc.mapping"); ImmutableList outputClassMappingFiles = filteredProtoSources.isEmpty() ? ImmutableList.of() - : getGeneratedOutputs(ruleContext, base, ".clsmap.properties"); + : ProtoCommon.declareGeneratedFiles(ruleContext, base, ".clsmap.properties"); ImmutableList outputs = ImmutableList.builder() .addAll(j2ObjcSource.getObjcSrcs()) @@ -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( @@ -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, @@ -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)); } @@ -901,22 +899,4 @@ private static ObjcCommon common( .setIntermediateArtifacts(intermediateArtifacts) .build(); } - - public static ImmutableList getGeneratedOutputs( - RuleContext ruleContext, ConfiguredTarget target, String extension) { - ImmutableList.Builder 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(); - } }