diff options
author | Dan Willemsen <dwillemsen@google.com> | 2018-02-14 13:58:34 -0800 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2018-02-22 16:48:35 -0800 |
commit | ab9f4268c01390b9d049c746e399b53a0f2c6dce (patch) | |
tree | 618eee4fd52d9e93ff04b1ae46a98765a9e65940 /java/proto.go | |
parent | 336ad7a6676515ec1f2a432ca176af62ff180155 (diff) | |
download | build_soong-ab9f4268c01390b9d049c746e399b53a0f2c6dce.tar.gz build_soong-ab9f4268c01390b9d049c746e399b53a0f2c6dce.tar.bz2 build_soong-ab9f4268c01390b9d049c746e399b53a0f2c6dce.zip |
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
Diffstat (limited to 'java/proto.go')
-rw-r--r-- | java/proto.go | 36 |
1 files changed, 23 insertions, 13 deletions
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 } |