| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [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 python | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 | "strings" | 
|  | 20 |  | 
|  | 21 | "github.com/google/blueprint" | 
|  | 22 | ) | 
|  | 23 |  | 
|  | 24 | func init() { | 
|  | 25 | pctx.HostBinToolVariable("protocCmd", "aprotoc") | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | var ( | 
|  | 29 | proto = pctx.AndroidStaticRule("protoc", | 
|  | 30 | blueprint.RuleParams{ | 
|  | 31 | Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` + | 
| Dan Willemsen | 4339853 | 2018-02-21 02:10:29 -0800 | [diff] [blame] | 32 | `$protocCmd --python_out=$out.tmp --dependency_out=$out.d -I $protoBase $protoFlags $in && ` + | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 33 | `$parCmd -o $out -P $pkgPath -C $out.tmp -D $out.tmp && rm -rf $out.tmp`, | 
|  | 34 | CommandDeps: []string{ | 
|  | 35 | "$protocCmd", | 
|  | 36 | "$parCmd", | 
|  | 37 | }, | 
| Dan Willemsen | 4339853 | 2018-02-21 02:10:29 -0800 | [diff] [blame] | 38 | Depfile: "${out}.d", | 
|  | 39 | Deps:    blueprint.DepsGCC, | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 40 | }, "protoBase", "protoFlags", "pkgPath") | 
|  | 41 | ) | 
|  | 42 |  | 
|  | 43 | func genProto(ctx android.ModuleContext, p *android.ProtoProperties, | 
|  | 44 | protoFile android.Path, protoFlags []string, pkgPath string) android.Path { | 
|  | 45 | srcJarFile := android.PathForModuleGen(ctx, protoFile.Base()+".srcszip") | 
|  | 46 |  | 
|  | 47 | protoRoot := android.ProtoCanonicalPathFromRoot(ctx, p) | 
|  | 48 |  | 
|  | 49 | var protoBase string | 
|  | 50 | if protoRoot { | 
|  | 51 | protoBase = "." | 
|  | 52 | } else { | 
|  | 53 | protoBase = strings.TrimSuffix(protoFile.String(), protoFile.Rel()) | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | ctx.Build(pctx, android.BuildParams{ | 
|  | 57 | Rule:        proto, | 
|  | 58 | Description: "protoc " + protoFile.Rel(), | 
|  | 59 | Output:      srcJarFile, | 
|  | 60 | Input:       protoFile, | 
|  | 61 | Args: map[string]string{ | 
|  | 62 | "protoBase":  protoBase, | 
|  | 63 | "protoFlags": strings.Join(protoFlags, " "), | 
|  | 64 | "pkgPath":    pkgPath, | 
|  | 65 | }, | 
|  | 66 | }) | 
|  | 67 |  | 
|  | 68 | return srcJarFile | 
|  | 69 | } |