blob: 82ee3cb0db3f4f8f578afc3449bdf2e2b93d31c7 [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 && ` +
32 `$protocCmd --python_out=$out.tmp -I $protoBase $protoFlags $in && ` +
33 `$parCmd -o $out -P $pkgPath -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
34 CommandDeps: []string{
35 "$protocCmd",
36 "$parCmd",
37 },
38 }, "protoBase", "protoFlags", "pkgPath")
39)
40
41func genProto(ctx android.ModuleContext, p *android.ProtoProperties,
42 protoFile android.Path, protoFlags []string, pkgPath string) android.Path {
43 srcJarFile := android.PathForModuleGen(ctx, protoFile.Base()+".srcszip")
44
45 protoRoot := android.ProtoCanonicalPathFromRoot(ctx, p)
46
47 var protoBase string
48 if protoRoot {
49 protoBase = "."
50 } else {
51 protoBase = strings.TrimSuffix(protoFile.String(), protoFile.Rel())
52 }
53
54 ctx.Build(pctx, android.BuildParams{
55 Rule: proto,
56 Description: "protoc " + protoFile.Rel(),
57 Output: srcJarFile,
58 Input: protoFile,
59 Args: map[string]string{
60 "protoBase": protoBase,
61 "protoFlags": strings.Join(protoFlags, " "),
62 "pkgPath": pkgPath,
63 },
64 })
65
66 return srcJarFile
67}