aboutsummaryrefslogtreecommitdiffstats
path: root/cc/proto.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-09-07 10:53:07 -0700
committerColin Cross <ccross@android.com>2017-09-11 12:41:58 -0700
commit38f794ee496764f1b429c1786cf84758ba6f00a8 (patch)
tree74c774238209c16d7325e882d7cbd9123df76a3b /cc/proto.go
parentffe58feb76fbb1ba1a9aa36d79bc90164ebef009 (diff)
downloadbuild_soong-38f794ee496764f1b429c1786cf84758ba6f00a8.tar.gz
build_soong-38f794ee496764f1b429c1786cf84758ba6f00a8.tar.bz2
build_soong-38f794ee496764f1b429c1786cf84758ba6f00a8.zip
Refactor proto in preparation for java proto support
Test: m -j checkbuild Change-Id: Idf00ea0bacb2777458f9af2c7eb47e1e1854eeba
Diffstat (limited to 'cc/proto.go')
-rw-r--r--cc/proto.go90
1 files changed, 5 insertions, 85 deletions
diff --git a/cc/proto.go b/cc/proto.go
index 6c1789ab..6049d44a 100644
--- a/cc/proto.go
+++ b/cc/proto.go
@@ -15,81 +15,13 @@
package cc
import (
- "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
"android/soong/android"
)
-func init() {
- pctx.HostBinToolVariable("protocCmd", "aprotoc")
-}
-
-var (
- proto = pctx.AndroidStaticRule("protoc",
- blueprint.RuleParams{
- Command: "$protocCmd --cpp_out=$outDir $protoFlags $in",
- CommandDeps: []string{"$protocCmd"},
- }, "protoFlags", "outDir")
-)
-
-// 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
-// export a library for every type of external user (lite vs. full, c vs. c++ vs. java). It would
-// be better to support a proto module type that exported a proto file along with some include dirs,
-// and then external modules could depend on the proto module but use their own settings to
-// generate the source.
-
-func genProto(ctx android.ModuleContext, protoFile android.Path,
- protoFlags string) (android.ModuleGenPath, android.ModuleGenPath) {
-
- outFile := android.GenPathWithExt(ctx, "proto", protoFile, "pb.cc")
- headerFile := android.GenPathWithExt(ctx, "proto", protoFile, "pb.h")
- ctx.ModuleBuild(pctx, android.ModuleBuildParams{
- Rule: proto,
- Description: "protoc " + protoFile.Rel(),
- Outputs: android.WritablePaths{outFile, headerFile},
- Input: protoFile,
- Args: map[string]string{
- "outDir": protoDir(ctx).String(),
- "protoFlags": protoFlags,
- },
- })
-
- return outFile, headerFile
-}
-
-// protoDir returns the module's "gen/proto" directory
-func protoDir(ctx android.ModuleContext) android.ModuleGenPath {
- return android.PathForModuleGen(ctx, "proto")
-}
-
-// protoSubDir returns the module's "gen/proto/path/to/module" directory
-func protoSubDir(ctx android.ModuleContext) android.ModuleGenPath {
- return android.PathForModuleGen(ctx, "proto", ctx.ModuleDir())
-}
-
-type ProtoProperties struct {
- Proto struct {
- // Proto generator type (full, lite)
- Type *string `android:"arch_variant"`
-
- // Link statically against the protobuf runtime
- Static bool `android:"arch_variant"`
-
- // list of directories that will be added to the protoc include paths.
- Include_dirs []string
-
- // list of directories relative to the Android.bp file that will
- // be added to the protoc include paths.
- Local_include_dirs []string
- } `android:"arch_variant"`
-}
-
-func protoDeps(ctx BaseModuleContext, deps Deps, p *ProtoProperties) Deps {
+func protoDeps(ctx BaseModuleContext, deps Deps, p *android.ProtoProperties, static bool) Deps {
var lib string
- var static bool
switch proptools.String(p.Proto.Type) {
case "full":
@@ -105,9 +37,6 @@ func protoDeps(ctx BaseModuleContext, deps Deps, p *ProtoProperties) Deps {
static = true
} else {
lib = "libprotobuf-cpp-lite"
- if p.Proto.Static {
- static = true
- }
}
default:
ctx.PropertyErrorf("proto.type", "unknown proto type %q",
@@ -125,23 +54,14 @@ func protoDeps(ctx BaseModuleContext, deps Deps, p *ProtoProperties) Deps {
return deps
}
-func protoFlags(ctx ModuleContext, flags Flags, p *ProtoProperties) Flags {
+func protoFlags(ctx ModuleContext, flags Flags, p *android.ProtoProperties) Flags {
flags.CFlags = append(flags.CFlags, "-DGOOGLE_PROTOBUF_NO_RTTI")
flags.GlobalFlags = append(flags.GlobalFlags,
- "-I"+protoSubDir(ctx).String(),
- "-I"+protoDir(ctx).String(),
+ "-I"+android.ProtoSubDir(ctx).String(),
+ "-I"+android.ProtoDir(ctx).String(),
)
- if len(p.Proto.Local_include_dirs) > 0 {
- localProtoIncludeDirs := android.PathsForModuleSrc(ctx, p.Proto.Local_include_dirs)
- flags.protoFlags = append(flags.protoFlags, includeDirsToFlags(localProtoIncludeDirs))
- }
- if len(p.Proto.Include_dirs) > 0 {
- rootProtoIncludeDirs := android.PathsForSource(ctx, p.Proto.Include_dirs)
- flags.protoFlags = append(flags.protoFlags, includeDirsToFlags(rootProtoIncludeDirs))
- }
-
- flags.protoFlags = append(flags.protoFlags, "-I .")
+ flags.protoFlags = android.ProtoFlags(ctx, p)
return flags
}