From ab9f4268c01390b9d049c746e399b53a0f2c6dce Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 14 Feb 2018 13:58:34 -0800 Subject: Add proto.canonical_path_from_root Historically, we've always passed '-I .' as the first argument to protoc, essentially treating all proto file package names as their full path in the android source tree. This would make sense in a monorepo world, but it makes less sense when we're pulling in external projects with established package names. So keep the same default (for now), but allow individual builds to opt into using local paths as the default names with 'canonical_path_from_root: false'. A cleanup effort and/or large scale change in the future could change the default to false. As part of this, run protoc once per input proto file, since the flags may need to change per-file. We'll also need this in order to specify --dependency_out in the future. Bug: 70704330 Test: aosp/master build-aosp_arm.ninja is identical Test: aosp/master soong/build.ninja has expected changes Test: m Test: Build protobuf test Change-Id: I9d6de9fd630326bbcced1c62a4a7e9546429b0ce --- java/proto.go | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'java/proto.go') diff --git a/java/proto.go b/java/proto.go index 226fac08..2991ad98 100644 --- a/java/proto.go +++ b/java/proto.go @@ -30,31 +30,40 @@ func init() { var ( proto = pctx.AndroidStaticRule("protoc", blueprint.RuleParams{ - Command: `rm -rf $outDir && mkdir -p $outDir && ` + - `$protocCmd $protoOut=$protoOutParams:$outDir $protoFlags $in && ` + - `${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`, + Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` + + `$protocCmd $protoOut=$protoOutParams:$out.tmp -I $protoBase $protoFlags $in && ` + + `${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`, CommandDeps: []string{ "$protocCmd", "${config.SoongZipCmd}", }, - }, "protoFlags", "protoOut", "protoOutParams", "outDir") + }, "protoBase", "protoFlags", "protoOut", "protoOutParams") ) -func genProto(ctx android.ModuleContext, outputSrcJar android.WritablePath, - protoFiles android.Paths, protoFlags []string, protoOut, protoOutParams string) { +func genProto(ctx android.ModuleContext, protoFile android.Path, flags javaBuilderFlags) android.Path { + srcJarFile := android.GenPathWithExt(ctx, "proto", protoFile, "srcjar") + + var protoBase string + if flags.protoRoot { + protoBase = "." + } else { + protoBase = strings.TrimSuffix(protoFile.String(), protoFile.Rel()) + } ctx.Build(pctx, android.BuildParams{ Rule: proto, - Description: "protoc " + protoFiles[0].Rel(), - Output: outputSrcJar, - Inputs: protoFiles, + Description: "protoc " + protoFile.Rel(), + Output: srcJarFile, + Input: protoFile, Args: map[string]string{ - "outDir": android.ProtoDir(ctx).String(), - "protoOut": protoOut, - "protoOutParams": protoOutParams, - "protoFlags": strings.Join(protoFlags, " "), + "protoBase": protoBase, + "protoOut": flags.protoOutTypeFlag, + "protoOutParams": flags.protoOutParams, + "protoFlags": strings.Join(flags.protoFlags, " "), }, }) + + return srcJarFile } func protoDeps(ctx android.BottomUpMutatorContext, p *android.ProtoProperties) { @@ -103,6 +112,7 @@ func protoFlags(ctx android.ModuleContext, j *CompilerProperties, p *android.Pro } flags.protoFlags = android.ProtoFlags(ctx, p) + flags.protoRoot = android.ProtoCanonicalPathFromRoot(ctx, p) return flags } -- cgit v1.2.3