blob: 801837e0136545efca5f71a69ae7850659d64bd3 [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 {
Dan Willemsenab9f4262018-02-14 13:58:34 -080026 protoFlags := []string{}
Colin Crossa3b25002017-12-15 13:41:30 -080027
Colin Cross38f794e2017-09-07 10:53:07 -070028 if len(p.Proto.Local_include_dirs) > 0 {
29 localProtoIncludeDirs := PathsForModuleSrc(ctx, p.Proto.Local_include_dirs)
30 protoFlags = append(protoFlags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I"))
31 }
32 if len(p.Proto.Include_dirs) > 0 {
33 rootProtoIncludeDirs := PathsForSource(ctx, p.Proto.Include_dirs)
34 protoFlags = append(protoFlags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I"))
35 }
36
Colin Cross38f794e2017-09-07 10:53:07 -070037 return protoFlags
38}
39
Dan Willemsenab9f4262018-02-14 13:58:34 -080040func ProtoCanonicalPathFromRoot(ctx ModuleContext, p *ProtoProperties) bool {
41 if p.Proto.Canonical_path_from_root == nil {
42 return true
43 }
44 return *p.Proto.Canonical_path_from_root
45}
46
Colin Cross38f794e2017-09-07 10:53:07 -070047// ProtoDir returns the module's "gen/proto" directory
48func ProtoDir(ctx ModuleContext) ModuleGenPath {
49 return PathForModuleGen(ctx, "proto")
50}
51
52// ProtoSubDir returns the module's "gen/proto/path/to/module" directory
53func ProtoSubDir(ctx ModuleContext) ModuleGenPath {
54 return PathForModuleGen(ctx, "proto", ctx.ModuleDir())
55}
56
57type ProtoProperties struct {
58 Proto struct {
59 // Proto generator type. C++: full or lite. Java: micro, nano, stream, or lite.
60 Type *string `android:"arch_variant"`
61
62 // list of directories that will be added to the protoc include paths.
63 Include_dirs []string
64
65 // list of directories relative to the bp file that will
66 // be added to the protoc include paths.
67 Local_include_dirs []string
Dan Willemsenab9f4262018-02-14 13:58:34 -080068
69 // whether to identify the proto files from the root of the
70 // source tree (the original method in Android, useful for
71 // android-specific protos), or relative from where they were
72 // specified (useful for external/third party protos).
73 //
74 // This defaults to true today, but is expected to default to
75 // false in the future.
76 Canonical_path_from_root *bool
Colin Cross38f794e2017-09-07 10:53:07 -070077 } `android:"arch_variant"`
78}