2017-09-21 03:59:05 +08:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2017-11-15 05:11:23 +08:00
|
|
|
"strings"
|
|
|
|
|
2017-09-21 03:59:05 +08:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.HostBinToolVariable("protocCmd", "aprotoc")
|
2018-05-18 01:11:17 +08:00
|
|
|
pctx.HostBinToolVariable("depFixCmd", "dep_fixer")
|
2017-09-21 03:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
proto = pctx.AndroidStaticRule("protoc",
|
|
|
|
blueprint.RuleParams{
|
2018-02-15 05:58:34 +08:00
|
|
|
Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
|
2018-02-21 18:10:29 +08:00
|
|
|
`$protocCmd $protoOut=$protoOutParams:$out.tmp --dependency_out=$out.d -I $protoBase $protoFlags $in && ` +
|
2018-05-18 01:11:17 +08:00
|
|
|
`$depFixCmd $out.d && ` +
|
2018-02-15 05:58:34 +08:00
|
|
|
`${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
|
2017-10-17 09:07:29 +08:00
|
|
|
CommandDeps: []string{
|
|
|
|
"$protocCmd",
|
2018-05-18 01:11:17 +08:00
|
|
|
"$depFixCmd",
|
2017-10-17 09:07:29 +08:00
|
|
|
"${config.SoongZipCmd}",
|
|
|
|
},
|
2018-02-21 18:10:29 +08:00
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2018-02-15 05:58:34 +08:00
|
|
|
}, "protoBase", "protoFlags", "protoOut", "protoOutParams")
|
2017-09-21 03:59:05 +08:00
|
|
|
)
|
|
|
|
|
2018-02-15 05:58:34 +08:00
|
|
|
func genProto(ctx android.ModuleContext, protoFile android.Path, flags javaBuilderFlags) android.Path {
|
|
|
|
srcJarFile := android.GenPathWithExt(ctx, "proto", protoFile, "srcjar")
|
|
|
|
|
|
|
|
var protoBase string
|
|
|
|
if flags.protoRoot {
|
|
|
|
protoBase = "."
|
|
|
|
} else {
|
|
|
|
protoBase = strings.TrimSuffix(protoFile.String(), protoFile.Rel())
|
|
|
|
}
|
2017-09-21 03:59:05 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-09-21 03:59:05 +08:00
|
|
|
Rule: proto,
|
2018-02-15 05:58:34 +08:00
|
|
|
Description: "protoc " + protoFile.Rel(),
|
|
|
|
Output: srcJarFile,
|
|
|
|
Input: protoFile,
|
2017-09-21 03:59:05 +08:00
|
|
|
Args: map[string]string{
|
2018-02-15 05:58:34 +08:00
|
|
|
"protoBase": protoBase,
|
|
|
|
"protoOut": flags.protoOutTypeFlag,
|
|
|
|
"protoOutParams": flags.protoOutParams,
|
|
|
|
"protoFlags": strings.Join(flags.protoFlags, " "),
|
2017-09-21 03:59:05 +08:00
|
|
|
},
|
|
|
|
})
|
2018-02-15 05:58:34 +08:00
|
|
|
|
|
|
|
return srcJarFile
|
2017-09-21 03:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func protoDeps(ctx android.BottomUpMutatorContext, p *android.ProtoProperties) {
|
2018-04-11 07:15:18 +08:00
|
|
|
switch String(p.Proto.Type) {
|
2017-09-21 03:59:05 +08:00
|
|
|
case "micro":
|
|
|
|
ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-micro")
|
|
|
|
case "nano":
|
|
|
|
ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-nano")
|
|
|
|
case "lite", "":
|
|
|
|
ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-lite")
|
|
|
|
case "full":
|
|
|
|
if ctx.Host() {
|
|
|
|
ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-full")
|
|
|
|
} else {
|
|
|
|
ctx.PropertyErrorf("proto.type", "full java protos only supported on the host")
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("proto.type", "unknown proto type %q",
|
2018-04-11 07:15:18 +08:00
|
|
|
String(p.Proto.Type))
|
2017-09-21 03:59:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 07:22:43 +08:00
|
|
|
func protoFlags(ctx android.ModuleContext, j *CompilerProperties, p *android.ProtoProperties,
|
|
|
|
flags javaBuilderFlags) javaBuilderFlags {
|
|
|
|
|
2018-04-11 07:15:18 +08:00
|
|
|
switch String(p.Proto.Type) {
|
2017-09-21 03:59:05 +08:00
|
|
|
case "micro":
|
2017-11-19 10:23:14 +08:00
|
|
|
flags.protoOutTypeFlag = "--javamicro_out"
|
2017-09-21 03:59:05 +08:00
|
|
|
case "nano":
|
2017-11-19 10:23:14 +08:00
|
|
|
flags.protoOutTypeFlag = "--javanano_out"
|
|
|
|
case "lite":
|
|
|
|
flags.protoOutTypeFlag = "--java_out"
|
|
|
|
flags.protoOutParams = "lite"
|
|
|
|
case "full", "":
|
|
|
|
flags.protoOutTypeFlag = "--java_out"
|
2017-09-21 03:59:05 +08:00
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("proto.type", "unknown proto type %q",
|
2018-04-11 07:15:18 +08:00
|
|
|
String(p.Proto.Type))
|
2017-09-21 03:59:05 +08:00
|
|
|
}
|
2017-11-15 05:11:23 +08:00
|
|
|
|
2017-12-15 07:22:43 +08:00
|
|
|
if len(j.Proto.Output_params) > 0 {
|
|
|
|
if flags.protoOutParams != "" {
|
|
|
|
flags.protoOutParams += ","
|
|
|
|
}
|
|
|
|
flags.protoOutParams += strings.Join(j.Proto.Output_params, ",")
|
|
|
|
}
|
|
|
|
|
2017-11-15 05:11:23 +08:00
|
|
|
flags.protoFlags = android.ProtoFlags(ctx, p)
|
2018-02-15 05:58:34 +08:00
|
|
|
flags.protoRoot = android.ProtoCanonicalPathFromRoot(ctx, p)
|
2017-11-15 05:11:23 +08:00
|
|
|
|
2017-09-21 03:59:05 +08:00
|
|
|
return flags
|
|
|
|
}
|