| 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 | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame] | 33 | 				`$parCmd -o $out $pkgPathArgs -C $out.tmp -D $out.tmp && rm -rf $out.tmp`, | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 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 | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame] | 40 | 		}, "protoBase", "protoFlags", "pkgPathArgs") | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 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 |  | 
| Nan Zhang | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame] | 56 | 	var pkgPathArgs string | 
 | 57 | 	if pkgPath != "" { | 
 | 58 | 		pkgPathArgs = "-P " + pkgPath | 
 | 59 | 	} | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 60 | 	ctx.Build(pctx, android.BuildParams{ | 
 | 61 | 		Rule:        proto, | 
 | 62 | 		Description: "protoc " + protoFile.Rel(), | 
 | 63 | 		Output:      srcJarFile, | 
 | 64 | 		Input:       protoFile, | 
 | 65 | 		Args: map[string]string{ | 
| Nan Zhang | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame] | 66 | 			"protoBase":   protoBase, | 
 | 67 | 			"protoFlags":  strings.Join(protoFlags, " "), | 
 | 68 | 			"pkgPathArgs": pkgPathArgs, | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 69 | 		}, | 
 | 70 | 	}) | 
 | 71 |  | 
 | 72 | 	return srcJarFile | 
 | 73 | } |