blob: 1c70656e2ffd1ac3da1ea72051225141c0cf0caf [file] [log] [blame]
Colin Cross38f794e2017-09-07 10:53:07 -07001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package android
16
Colin Cross38f794e2017-09-07 10:53:07 -070017// TODO(ccross): protos are often used to communicate between multiple modules. If the only
18// way to convert a proto to source is to reference it as a source file, and external modules cannot
19// reference source files in other modules, then every module that owns a proto file will need to
20// export a library for every type of external user (lite vs. full, c vs. c++ vs. java). It would
21// be better to support a proto module type that exported a proto file along with some include dirs,
22// and then external modules could depend on the proto module but use their own settings to
23// generate the source.
24
Colin Cross38f794e2017-09-07 10:53:07 -070025func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string {
26 var protoFlags []string
27 if len(p.Proto.Local_include_dirs) > 0 {
28 localProtoIncludeDirs := PathsForModuleSrc(ctx, p.Proto.Local_include_dirs)
29 protoFlags = append(protoFlags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I"))
30 }
31 if len(p.Proto.Include_dirs) > 0 {
32 rootProtoIncludeDirs := PathsForSource(ctx, p.Proto.Include_dirs)
33 protoFlags = append(protoFlags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I"))
34 }
35
36 protoFlags = append(protoFlags, "-I .")
37
38 return protoFlags
39}
40
41// ProtoDir returns the module's "gen/proto" directory
42func ProtoDir(ctx ModuleContext) ModuleGenPath {
43 return PathForModuleGen(ctx, "proto")
44}
45
46// ProtoSubDir returns the module's "gen/proto/path/to/module" directory
47func ProtoSubDir(ctx ModuleContext) ModuleGenPath {
48 return PathForModuleGen(ctx, "proto", ctx.ModuleDir())
49}
50
51type ProtoProperties struct {
52 Proto struct {
53 // Proto generator type. C++: full or lite. Java: micro, nano, stream, or lite.
54 Type *string `android:"arch_variant"`
55
56 // list of directories that will be added to the protoc include paths.
57 Include_dirs []string
58
59 // list of directories relative to the bp file that will
60 // be added to the protoc include paths.
61 Local_include_dirs []string
62 } `android:"arch_variant"`
63}