2017-09-20 21:59:05 +02: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-14 22:11:23 +01:00
|
|
|
"strings"
|
|
|
|
|
2017-09-20 21:59:05 +02:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.HostBinToolVariable("protocCmd", "aprotoc")
|
2018-05-17 19:11:17 +02:00
|
|
|
pctx.HostBinToolVariable("depFixCmd", "dep_fixer")
|
2017-09-20 21:59:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
proto = pctx.AndroidStaticRule("protoc",
|
|
|
|
blueprint.RuleParams{
|
2018-02-14 22:58:34 +01:00
|
|
|
Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
|
2018-02-21 11:10:29 +01:00
|
|
|
`$protocCmd $protoOut=$protoOutParams:$out.tmp --dependency_out=$out.d -I $protoBase $protoFlags $in && ` +
|
2018-05-17 19:11:17 +02:00
|
|
|
`$depFixCmd $out.d && ` +
|
2018-02-14 22:58:34 +01:00
|
|
|
`${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
|
2017-10-17 03:07:29 +02:00
|
|
|
CommandDeps: []string{
|
|
|
|
"$protocCmd",
|
2018-05-17 19:11:17 +02:00
|
|
|
"$depFixCmd",
|
2017-10-17 03:07:29 +02:00
|
|
|
"${config.SoongZipCmd}",
|
|
|
|
},
|
2018-02-21 11:10:29 +01:00
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2018-02-14 22:58:34 +01:00
|
|
|
}, "protoBase", "protoFlags", "protoOut", "protoOutParams")
|
2017-09-20 21:59:05 +02:00
|
|
|
)
|
|
|
|
|
2018-02-14 22:58:34 +01: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-20 21:59:05 +02:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-09-20 21:59:05 +02:00
|
|
|
Rule: proto,
|
2018-02-14 22:58:34 +01:00
|
|
|
Description: "protoc " + protoFile.Rel(),
|
|
|
|
Output: srcJarFile,
|
|
|
|
Input: protoFile,
|
2017-09-20 21:59:05 +02:00
|
|
|
Args: map[string]string{
|
2018-02-14 22:58:34 +01:00
|
|
|
"protoBase": protoBase,
|
|
|
|
"protoOut": flags.protoOutTypeFlag,
|
|
|
|
"protoOutParams": flags.protoOutParams,
|
|
|
|
"protoFlags": strings.Join(flags.protoFlags, " "),
|
2017-09-20 21:59:05 +02:00
|
|
|
},
|
|
|
|
})
|
2018-02-14 22:58:34 +01:00
|
|
|
|
|
|
|
return srcJarFile
|
2017-09-20 21:59:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func protoDeps(ctx android.BottomUpMutatorContext, p *android.ProtoProperties) {
|
2018-04-11 01:15:18 +02:00
|
|
|
switch String(p.Proto.Type) {
|
2017-09-20 21:59:05 +02:00
|
|
|
case "micro":
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-micro")
|
2017-09-20 21:59:05 +02:00
|
|
|
case "nano":
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-nano")
|
2017-09-20 21:59:05 +02:00
|
|
|
case "lite", "":
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-lite")
|
2017-09-20 21:59:05 +02:00
|
|
|
case "full":
|
|
|
|
if ctx.Host() {
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-full")
|
2017-09-20 21:59:05 +02:00
|
|
|
} 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 01:15:18 +02:00
|
|
|
String(p.Proto.Type))
|
2017-09-20 21:59:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 00:22:43 +01:00
|
|
|
func protoFlags(ctx android.ModuleContext, j *CompilerProperties, p *android.ProtoProperties,
|
|
|
|
flags javaBuilderFlags) javaBuilderFlags {
|
|
|
|
|
2018-04-11 01:15:18 +02:00
|
|
|
switch String(p.Proto.Type) {
|
2017-09-20 21:59:05 +02:00
|
|
|
case "micro":
|
2017-11-19 03:23:14 +01:00
|
|
|
flags.protoOutTypeFlag = "--javamicro_out"
|
2017-09-20 21:59:05 +02:00
|
|
|
case "nano":
|
2017-11-19 03:23:14 +01:00
|
|
|
flags.protoOutTypeFlag = "--javanano_out"
|
|
|
|
case "lite":
|
2018-11-05 02:23:45 +01:00
|
|
|
flags.protoOutTypeFlag = "--java_out"
|
|
|
|
flags.protoOutParams = "lite"
|
2017-11-19 03:23:14 +01:00
|
|
|
case "full", "":
|
|
|
|
flags.protoOutTypeFlag = "--java_out"
|
2017-09-20 21:59:05 +02:00
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("proto.type", "unknown proto type %q",
|
2018-04-11 01:15:18 +02:00
|
|
|
String(p.Proto.Type))
|
2017-09-20 21:59:05 +02:00
|
|
|
}
|
2017-11-14 22:11:23 +01:00
|
|
|
|
2018-11-05 02:23:45 +01:00
|
|
|
if len(j.Proto.Output_params) > 0 {
|
|
|
|
if flags.protoOutParams != "" {
|
|
|
|
flags.protoOutParams += ","
|
|
|
|
}
|
|
|
|
flags.protoOutParams += strings.Join(j.Proto.Output_params, ",")
|
|
|
|
}
|
|
|
|
|
2017-11-14 22:11:23 +01:00
|
|
|
flags.protoFlags = android.ProtoFlags(ctx, p)
|
2018-02-14 22:58:34 +01:00
|
|
|
flags.protoRoot = android.ProtoCanonicalPathFromRoot(ctx, p)
|
2017-11-14 22:11:23 +01:00
|
|
|
|
2017-09-20 21:59:05 +02:00
|
|
|
return flags
|
|
|
|
}
|