| Colin Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package android | 
|  | 16 |  | 
| Colin Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 17 | // 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 Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 25 | func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string { | 
| Dan Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 26 | protoFlags := []string{} | 
| Colin Cross | a3b2500 | 2017-12-15 13:41:30 -0800 | [diff] [blame] | 27 |  | 
| Colin Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 28 | 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 Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 37 | return protoFlags | 
|  | 38 | } | 
|  | 39 |  | 
| Dan Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 40 | func 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 Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 47 | // ProtoDir returns the module's "gen/proto" directory | 
|  | 48 | func ProtoDir(ctx ModuleContext) ModuleGenPath { | 
|  | 49 | return PathForModuleGen(ctx, "proto") | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | // ProtoSubDir returns the module's "gen/proto/path/to/module" directory | 
|  | 53 | func ProtoSubDir(ctx ModuleContext) ModuleGenPath { | 
|  | 54 | return PathForModuleGen(ctx, "proto", ctx.ModuleDir()) | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | type 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 Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 68 |  | 
|  | 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 Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 77 | } `android:"arch_variant"` | 
|  | 78 | } |