aboutsummaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2019-04-02 10:31:13 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-04-02 10:31:13 -0700
commit57205f3cb4fda0ca2687e5f881c36f21b6c9c20a (patch)
tree200b4dae87d0763e11e8f03a87aa4446edd0462e /android
parent6a40626601c1acc1d835a96b7a397199eac97399 (diff)
parentc8a3eb9110b249a9910dbb3713f0efbb9bb5d7bb (diff)
downloadbuild_soong-57205f3cb4fda0ca2687e5f881c36f21b6c9c20a.tar.gz
build_soong-57205f3cb4fda0ca2687e5f881c36f21b6c9c20a.tar.bz2
build_soong-57205f3cb4fda0ca2687e5f881c36f21b6c9c20a.zip
Move proto compilation to RuleBuilder am: 19878da6a0 am: 61918685aa
am: c8a3eb9110 Change-Id: If3922ee1900d6f3888c7291997ac49d4a939c065
Diffstat (limited to 'android')
-rw-r--r--android/proto.go65
1 files changed, 46 insertions, 19 deletions
diff --git a/android/proto.go b/android/proto.go
index 801837e0..83dc32a9 100644
--- a/android/proto.go
+++ b/android/proto.go
@@ -14,6 +14,12 @@
package android
+import (
+ "strings"
+
+ "github.com/google/blueprint/proptools"
+)
+
// TODO(ccross): protos are often used to communicate between multiple modules. If the only
// way to convert a proto to source is to reference it as a source file, and external modules cannot
// reference source files in other modules, then every module that owns a proto file will need to
@@ -22,9 +28,17 @@ package android
// and then external modules could depend on the proto module but use their own settings to
// generate the source.
-func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string {
- protoFlags := []string{}
+type ProtoFlags struct {
+ Flags []string
+ CanonicalPathFromRoot bool
+ Dir ModuleGenPath
+ SubDir ModuleGenPath
+ OutTypeFlag string
+ OutParams []string
+}
+func GetProtoFlags(ctx ModuleContext, p *ProtoProperties) ProtoFlags {
+ var protoFlags []string
if len(p.Proto.Local_include_dirs) > 0 {
localProtoIncludeDirs := PathsForModuleSrc(ctx, p.Proto.Local_include_dirs)
protoFlags = append(protoFlags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I"))
@@ -34,24 +48,12 @@ func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string {
protoFlags = append(protoFlags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I"))
}
- return protoFlags
-}
-
-func ProtoCanonicalPathFromRoot(ctx ModuleContext, p *ProtoProperties) bool {
- if p.Proto.Canonical_path_from_root == nil {
- return true
+ return ProtoFlags{
+ Flags: protoFlags,
+ CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, true),
+ Dir: PathForModuleGen(ctx, "proto"),
+ SubDir: PathForModuleGen(ctx, "proto", ctx.ModuleDir()),
}
- return *p.Proto.Canonical_path_from_root
-}
-
-// ProtoDir returns the module's "gen/proto" directory
-func ProtoDir(ctx ModuleContext) ModuleGenPath {
- return PathForModuleGen(ctx, "proto")
-}
-
-// ProtoSubDir returns the module's "gen/proto/path/to/module" directory
-func ProtoSubDir(ctx ModuleContext) ModuleGenPath {
- return PathForModuleGen(ctx, "proto", ctx.ModuleDir())
}
type ProtoProperties struct {
@@ -76,3 +78,28 @@ type ProtoProperties struct {
Canonical_path_from_root *bool
} `android:"arch_variant"`
}
+
+func ProtoRule(ctx ModuleContext, rule *RuleBuilder, protoFile Path, flags ProtoFlags, deps Paths,
+ outDir WritablePath, depFile WritablePath, outputs WritablePaths) {
+
+ var protoBase string
+ if flags.CanonicalPathFromRoot {
+ protoBase = "."
+ } else {
+ rel := protoFile.Rel()
+ protoBase = strings.TrimSuffix(protoFile.String(), rel)
+ }
+
+ rule.Command().
+ Tool(ctx.Config().HostToolPath(ctx, "aprotoc")).
+ FlagWithArg(flags.OutTypeFlag+"=", strings.Join(flags.OutParams, ",")+":"+outDir.String()).
+ FlagWithDepFile("--dependency_out=", depFile).
+ FlagWithArg("-I ", protoBase).
+ Flags(flags.Flags).
+ Input(protoFile).
+ Implicits(deps).
+ ImplicitOutputs(outputs)
+
+ rule.Command().
+ Tool(ctx.Config().HostToolPath(ctx, "dep_fixer")).Flag(depFile.String())
+}