blob: 42987fab98a6f3170a965349db3957d9b0c109db [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 Zhangb8fa1972017-12-22 16:12:00 -080033 `$parCmd -o $out -P $pkgPath -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
34 CommandDeps: []string{
35 "$protocCmd",
36 "$parCmd",
37 },
Dan Willemsen43398532018-02-21 02:10:29 -080038 Depfile: "${out}.d",
39 Deps: blueprint.DepsGCC,
Nan Zhangb8fa1972017-12-22 16:12:00 -080040 }, "protoBase", "protoFlags", "pkgPath")
41)
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
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}