aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2019-03-28 14:45:07 -0700
committerColin Cross <ccross@android.com>2019-04-02 16:38:47 +0000
commit19878da6a062ef474a1c905f48b1efb986862050 (patch)
tree389a8ac830a6bc2cee797f0daa70677450b98957 /python
parent6e1c3faed54db8db15ad46cbcb220f334fdff5f2 (diff)
downloadbuild_soong-19878da6a062ef474a1c905f48b1efb986862050.tar.gz
build_soong-19878da6a062ef474a1c905f48b1efb986862050.tar.bz2
build_soong-19878da6a062ef474a1c905f48b1efb986862050.zip
Move proto compilation to RuleBuilder
Using blueprint.Rule for protoc commands was causing code duplication because there was no good way to run the same protoc for cc, java and python but then run custom source packaging steps for java and python. Move most of the code into a common function that returns a RuleBuilder, and then let java and python add their own commands at the end of the rule. Bug: 70706119 Test: All Soong tests Test: m checkbuild Change-Id: Ic692136775d273bcc4f4de99620ab4878667c83a
Diffstat (limited to 'python')
-rw-r--r--python/proto.go65
-rw-r--r--python/python.go6
2 files changed, 25 insertions, 46 deletions
diff --git a/python/proto.go b/python/proto.go
index 2370cd26..813e91dd 100644
--- a/python/proto.go
+++ b/python/proto.go
@@ -16,58 +16,35 @@ package python
import (
"android/soong/android"
- "strings"
-
- "github.com/google/blueprint"
)
-func init() {
- pctx.HostBinToolVariable("protocCmd", "aprotoc")
-}
+func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.ProtoFlags, pkgPath string) android.Path {
+ srcsZipFile := android.PathForModuleGen(ctx, protoFile.Base()+".srcszip")
-var (
- proto = pctx.AndroidStaticRule("protoc",
- blueprint.RuleParams{
- Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
- `$protocCmd --python_out=$out.tmp --dependency_out=$out.d -I $protoBase $protoFlags $in && ` +
- `$parCmd -o $out $pkgPathArgs -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
- CommandDeps: []string{
- "$protocCmd",
- "$parCmd",
- },
- Depfile: "${out}.d",
- Deps: blueprint.DepsGCC,
- }, "protoBase", "protoFlags", "pkgPathArgs")
-)
+ outDir := srcsZipFile.ReplaceExtension(ctx, "tmp")
+ depFile := srcsZipFile.ReplaceExtension(ctx, "srcszip.d")
-func genProto(ctx android.ModuleContext, p *android.ProtoProperties,
- protoFile android.Path, protoFlags []string, pkgPath string) android.Path {
- srcJarFile := android.PathForModuleGen(ctx, protoFile.Base()+".srcszip")
+ rule := android.NewRuleBuilder()
- protoRoot := android.ProtoCanonicalPathFromRoot(ctx, p)
+ rule.Command().Text("rm -rf").Flag(outDir.String())
+ rule.Command().Text("mkdir -p").Flag(outDir.String())
- var protoBase string
- if protoRoot {
- protoBase = "."
- } else {
- protoBase = strings.TrimSuffix(protoFile.String(), protoFile.Rel())
- }
+ android.ProtoRule(ctx, rule, protoFile, flags, nil, outDir, depFile, nil)
- var pkgPathArgs string
+ // Proto generated python files have an unknown package name in the path, so package the entire output directory
+ // into a srcszip.
+ zipCmd := rule.Command().
+ Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
+ FlagWithOutput("-o ", srcsZipFile).
+ FlagWithArg("-C ", outDir.String()).
+ FlagWithArg("-D ", outDir.String())
if pkgPath != "" {
- pkgPathArgs = "-P " + pkgPath
+ zipCmd.FlagWithArg("-P ", pkgPath)
}
- ctx.Build(pctx, android.BuildParams{
- Rule: proto,
- Description: "protoc " + protoFile.Rel(),
- Output: srcJarFile,
- Input: protoFile,
- Args: map[string]string{
- "protoBase": protoBase,
- "protoFlags": strings.Join(protoFlags, " "),
- "pkgPathArgs": pkgPathArgs,
- },
- })
- return srcJarFile
+ rule.Command().Text("rm -rf").Flag(outDir.String())
+
+ rule.Build(pctx, ctx, "protoc_"+protoFile.Rel(), "protoc "+protoFile.Rel())
+
+ return srcsZipFile
}
diff --git a/python/python.go b/python/python.go
index 6eb9b6ef..3c3c396a 100644
--- a/python/python.go
+++ b/python/python.go
@@ -516,9 +516,11 @@ func (p *Module) createSrcsZip(ctx android.ModuleContext, pkgPath string) androi
}
var zips android.Paths
if len(protoSrcs) > 0 {
+ protoFlags := android.GetProtoFlags(ctx, &p.protoProperties)
+ protoFlags.OutTypeFlag = "--python_out"
+
for _, srcFile := range protoSrcs {
- zip := genProto(ctx, &p.protoProperties, srcFile,
- android.ProtoFlags(ctx, &p.protoProperties), pkgPath)
+ zip := genProto(ctx, srcFile, protoFlags, pkgPath)
zips = append(zips, zip)
}
}