diff options
| author | Colin Cross <ccross@android.com> | 2019-04-02 10:31:28 -0700 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2019-04-02 10:31:28 -0700 |
| commit | 32762a08eb75ce6c666e84a6462388d73bba99fa (patch) | |
| tree | 10f84259616d130b096bcd6f3fc3539ed17a1b76 /android | |
| parent | 57205f3cb4fda0ca2687e5f881c36f21b6c9c20a (diff) | |
| parent | 7299e418df78f1919b2c9d5344ddc0be20aee691 (diff) | |
| download | build_soong-32762a08eb75ce6c666e84a6462388d73bba99fa.tar.gz build_soong-32762a08eb75ce6c666e84a6462388d73bba99fa.tar.bz2 build_soong-32762a08eb75ce6c666e84a6462388d73bba99fa.zip | |
Add support for protoc plugins am: fe17f6f0e8 am: 91c063cfdc
am: 7299e418df
Change-Id: I30e57f6678343f57233831775b62afa1f043a450
Diffstat (limited to 'android')
| -rw-r--r-- | android/module.go | 4 | ||||
| -rw-r--r-- | android/proto.go | 52 |
2 files changed, 52 insertions, 4 deletions
diff --git a/android/module.go b/android/module.go index abf2cae4..201c27a8 100644 --- a/android/module.go +++ b/android/module.go @@ -1425,6 +1425,10 @@ type SourceFileProducer interface { Srcs() Paths } +type HostToolProvider interface { + HostToolPath() OptionalPath +} + // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must // be tagged with `android:"path" to support automatic source module dependency resolution. // diff --git a/android/proto.go b/android/proto.go index 83dc32a9..5247c68d 100644 --- a/android/proto.go +++ b/android/proto.go @@ -17,6 +17,7 @@ package android import ( "strings" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -35,21 +36,61 @@ type ProtoFlags struct { SubDir ModuleGenPath OutTypeFlag string OutParams []string + Deps Paths +} + +type protoDependencyTag struct { + blueprint.BaseDependencyTag + name string +} + +var ProtoPluginDepTag = protoDependencyTag{name: "plugin"} + +func ProtoDeps(ctx BottomUpMutatorContext, p *ProtoProperties) { + if String(p.Proto.Plugin) != "" && String(p.Proto.Type) != "" { + ctx.ModuleErrorf("only one of proto.type and proto.plugin can be specified.") + } + + if plugin := String(p.Proto.Plugin); plugin != "" { + ctx.AddFarVariationDependencies([]blueprint.Variation{ + {Mutator: "arch", Variation: ctx.Config().BuildOsVariant}, + }, ProtoPluginDepTag, "protoc-gen-"+plugin) + } } func GetProtoFlags(ctx ModuleContext, p *ProtoProperties) ProtoFlags { - var protoFlags []string + var flags []string + var deps Paths + if len(p.Proto.Local_include_dirs) > 0 { localProtoIncludeDirs := PathsForModuleSrc(ctx, p.Proto.Local_include_dirs) - protoFlags = append(protoFlags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I")) + flags = append(flags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I")) } if len(p.Proto.Include_dirs) > 0 { rootProtoIncludeDirs := PathsForSource(ctx, p.Proto.Include_dirs) - protoFlags = append(protoFlags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I")) + flags = append(flags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I")) + } + + ctx.VisitDirectDepsWithTag(ProtoPluginDepTag, func(dep Module) { + if hostTool, ok := dep.(HostToolProvider); !ok || !hostTool.HostToolPath().Valid() { + ctx.PropertyErrorf("proto.plugin", "module %q is not a host tool provider", + ctx.OtherModuleName(dep)) + } else { + plugin := String(p.Proto.Plugin) + deps = append(deps, hostTool.HostToolPath().Path()) + flags = append(flags, "--plugin=protoc-gen-"+plugin+"="+hostTool.HostToolPath().String()) + } + }) + + var protoOutFlag string + if plugin := String(p.Proto.Plugin); plugin != "" { + protoOutFlag = "--" + plugin + "_out" } return ProtoFlags{ - Flags: protoFlags, + Flags: flags, + Deps: deps, + OutTypeFlag: protoOutFlag, CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, true), Dir: PathForModuleGen(ctx, "proto"), SubDir: PathForModuleGen(ctx, "proto", ctx.ModuleDir()), @@ -61,6 +102,9 @@ type ProtoProperties struct { // Proto generator type. C++: full or lite. Java: micro, nano, stream, or lite. Type *string `android:"arch_variant"` + // Proto plugin to use as the generator. Must be a cc_binary_host module. + Plugin *string `android:"arch_variant"` + // list of directories that will be added to the protoc include paths. Include_dirs []string |
