blob: 2370cd26d357635386326d9a6ca145e76a22355b [file] [log] [blame]
Nan Zhangb8fa1972017-12-22 16:12:00 -08001// 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 python
16
17import (
18 "android/soong/android"
19 "strings"
20
21 "github.com/google/blueprint"
22)
23
24func init() {
25 pctx.HostBinToolVariable("protocCmd", "aprotoc")
26}
27
28var (
29 proto = pctx.AndroidStaticRule("protoc",
30 blueprint.RuleParams{
31 Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
Dan Willemsen43398532018-02-21 02:10:29 -080032 `$protocCmd --python_out=$out.tmp --dependency_out=$out.d -I $protoBase $protoFlags $in && ` +
Nan Zhangf0c4e432018-05-22 14:50:18 -070033 `$parCmd -o $out $pkgPathArgs -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
Nan Zhangb8fa1972017-12-22 16:12:00 -080034 CommandDeps: []string{
35 "$protocCmd",
36 "$parCmd",
37 },
Dan Willemsen43398532018-02-21 02:10:29 -080038 Depfile: "${out}.d",
39 Deps: blueprint.DepsGCC,
Nan Zhangf0c4e432018-05-22 14:50:18 -070040 }, "protoBase", "protoFlags", "pkgPathArgs")
Nan Zhangb8fa1972017-12-22 16:12:00 -080041)
42
43func 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 Zhangf0c4e432018-05-22 14:50:18 -070056 var pkgPathArgs string
57 if pkgPath != "" {
58 pkgPathArgs = "-P " + pkgPath
59 }
Nan Zhangb8fa1972017-12-22 16:12:00 -080060 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 Zhangf0c4e432018-05-22 14:50:18 -070066 "protoBase": protoBase,
67 "protoFlags": strings.Join(protoFlags, " "),
68 "pkgPathArgs": pkgPathArgs,
Nan Zhangb8fa1972017-12-22 16:12:00 -080069 },
70 })
71
72 return srcJarFile
73}