Skip to content

Commit

Permalink
Use ProtoCommon.declareGeneratedFiles in j2objc aspect.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 441098152
  • Loading branch information
comius authored and copybara-github committed Apr 12, 2022
1 parent 8864578 commit 4710ef8
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private ConfiguredAspect proto(ConfiguredTarget base, RuleContext ruleContext)
ImmutableList<Artifact> 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()) {
Expand Down Expand Up @@ -643,9 +643,13 @@ private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions(
J2ObjcSource j2ObjcSource)
throws RuleErrorException, InterruptedException {
ImmutableList<Artifact> outputHeaderMappingFiles =
ProtoCommon.getGeneratedOutputs(ruleContext, filteredProtoSources, ".j2objc.mapping");
filteredProtoSources.isEmpty()
? ImmutableList.of()
: ProtoCommon.declareGeneratedFiles(ruleContext, base, ".j2objc.mapping");
ImmutableList<Artifact> outputClassMappingFiles =
ProtoCommon.getGeneratedOutputs(ruleContext, filteredProtoSources, ".clsmap.properties");
filteredProtoSources.isEmpty()
? ImmutableList.of()
: ProtoCommon.declareGeneratedFiles(ruleContext, base, ".clsmap.properties");
ImmutableList<Artifact> outputs =
ImmutableList.<Artifact>builder()
.addAll(j2ObjcSource.getObjcSrcs())
Expand All @@ -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(
Expand Down Expand Up @@ -770,16 +774,21 @@ private static J2ObjcSource javaJ2ObjcSource(
}

private static J2ObjcSource protoJ2ObjcSource(
RuleContext ruleContext, ImmutableList<Artifact> protoSources) {
RuleContext ruleContext, ConfiguredTarget protoTarget, ImmutableList<Artifact> protoSources)
throws RuleErrorException, InterruptedException {
PathFragment objcFileRootExecPath = getProtoOutputRoot(ruleContext);

List<PathFragment> headerSearchPaths =
j2objcSourceHeaderSearchPaths(ruleContext, objcFileRootExecPath, protoSources);

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,
Expand All @@ -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));
}

Expand Down

0 comments on commit 4710ef8

Please sign in to comment.