From 4710ef82ce34572878e07c52e83a0144d707f140 Mon Sep 17 00:00:00 2001 From: ilist Date: Mon, 11 Apr 2022 23:52:49 -0700 Subject: [PATCH] Use ProtoCommon.declareGeneratedFiles in j2objc aspect. PiperOrigin-RevId: 441098152 --- .../build/lib/rules/objc/J2ObjcAspect.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 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 31fedc65aeb3bc..abc15a4f49cb45 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 @@ -394,7 +394,7 @@ private ConfiguredAspect proto(ConfiguredTarget base, RuleContext ruleContext) ImmutableList filteredProtoSources = ImmutableList.copyOf(ProtoCommon.filterSources(ruleContext, base, protoToolchain)); - J2ObjcSource j2ObjcSource = protoJ2ObjcSource(ruleContext, filteredProtoSources); + J2ObjcSource j2ObjcSource = protoJ2ObjcSource(ruleContext, base, filteredProtoSources); J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider; if (j2ObjcSource.getObjcSrcs().isEmpty()) { @@ -643,9 +643,13 @@ private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions( J2ObjcSource j2ObjcSource) throws RuleErrorException, InterruptedException { ImmutableList outputHeaderMappingFiles = - ProtoCommon.getGeneratedOutputs(ruleContext, filteredProtoSources, ".j2objc.mapping"); + filteredProtoSources.isEmpty() + ? ImmutableList.of() + : ProtoCommon.declareGeneratedFiles(ruleContext, base, ".j2objc.mapping"); ImmutableList outputClassMappingFiles = - ProtoCommon.getGeneratedOutputs(ruleContext, filteredProtoSources, ".clsmap.properties"); + filteredProtoSources.isEmpty() + ? ImmutableList.of() + : ProtoCommon.declareGeneratedFiles(ruleContext, base, ".clsmap.properties"); ImmutableList outputs = ImmutableList.builder() .addAll(j2ObjcSource.getObjcSrcs()) @@ -654,14 +658,14 @@ private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions( .addAll(outputClassMappingFiles) .build(); - String genfilesPath = getProtoOutputRoot(ruleContext).getPathString(); + String bindirPath = getProtoOutputRoot(ruleContext).getPathString(); ProtoCommon.compile( ruleContext, base, checkNotNull(protoToolchain), outputs, - genfilesPath, + bindirPath, "Generating j2objc proto_library %{label}"); return new J2ObjcMappingFileProvider( @@ -770,7 +774,8 @@ private static J2ObjcSource javaJ2ObjcSource( } private static J2ObjcSource protoJ2ObjcSource( - RuleContext ruleContext, ImmutableList protoSources) { + RuleContext ruleContext, ConfiguredTarget protoTarget, ImmutableList protoSources) + throws RuleErrorException, InterruptedException { PathFragment objcFileRootExecPath = getProtoOutputRoot(ruleContext); List headerSearchPaths = @@ -778,8 +783,12 @@ private static J2ObjcSource protoJ2ObjcSource( return new J2ObjcSource( ruleContext.getTarget().getLabel(), - ProtoCommon.getGeneratedOutputs(ruleContext, protoSources, ".j2objc.pb.m"), - ProtoCommon.getGeneratedOutputs(ruleContext, protoSources, ".j2objc.pb.h"), + protoSources.isEmpty() + ? ImmutableList.of() + : ProtoCommon.declareGeneratedFiles(ruleContext, protoTarget, ".j2objc.pb.m"), + protoSources.isEmpty() + ? ImmutableList.of() + : ProtoCommon.declareGeneratedFiles(ruleContext, protoTarget, ".j2objc.pb.h"), objcFileRootExecPath, SourceType.PROTO, headerSearchPaths, @@ -788,10 +797,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)); }