blob: 7c57a46aea6818cd4b8518720776f5ca61244ef8 [file] [log] [blame]
Colin Crossc0b06f12015-04-08 13:03:43 -07001// Copyright 2015 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 java
16
Colin Crossc0b06f12015-04-08 13:03:43 -070017import (
Colin Crossc0b06f12015-04-08 13:03:43 -070018 "github.com/google/blueprint"
Colin Crossc0b06f12015-04-08 13:03:43 -070019
Colin Cross635c3b02016-05-18 15:37:25 -070020 "android/soong/android"
Colin Crossc0b06f12015-04-08 13:03:43 -070021)
22
23func init() {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070024 pctx.HostBinToolVariable("aidlCmd", "aidl")
Inseob Kim108be542018-10-04 19:39:35 +090025 pctx.HostBinToolVariable("syspropCmd", "sysprop_java")
Dan Willemsenaad19602019-04-07 09:44:35 -070026 pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py")
27 pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py")
28 pctx.SourcePathVariable("logtagsLib", "build/make/tools/event_log_tags.py")
Colin Crossc0b06f12015-04-08 13:03:43 -070029}
30
31var (
Colin Cross9d45bb72016-08-29 16:14:13 -070032 aidl = pctx.AndroidStaticRule("aidl",
Colin Crossc0b06f12015-04-08 13:03:43 -070033 blueprint.RuleParams{
34 Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080035 CommandDeps: []string{"$aidlCmd"},
Colin Crossc0b06f12015-04-08 13:03:43 -070036 },
37 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070038
Colin Cross9d45bb72016-08-29 16:14:13 -070039 logtags = pctx.AndroidStaticRule("logtags",
Colin Crossf05fe972015-04-10 17:45:20 -070040 blueprint.RuleParams{
Colin Crossb1bd1aa2017-11-15 22:47:16 -080041 Command: "$logtagsCmd -o $out $in",
Dan Willemsenaad19602019-04-07 09:44:35 -070042 CommandDeps: []string{"$logtagsCmd", "$logtagsLib"},
Colin Crossf05fe972015-04-10 17:45:20 -070043 })
44
Colin Cross9d45bb72016-08-29 16:14:13 -070045 mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
Colin Crossf05fe972015-04-10 17:45:20 -070046 blueprint.RuleParams{
47 Command: "$mergeLogtagsCmd -o $out $in",
Dan Willemsenaad19602019-04-07 09:44:35 -070048 CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"},
Colin Crossf05fe972015-04-10 17:45:20 -070049 })
Inseob Kim108be542018-10-04 19:39:35 +090050
51 sysprop = pctx.AndroidStaticRule("sysprop",
52 blueprint.RuleParams{
53 Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
54 `$syspropCmd --java-output-dir $out.tmp $in && ` +
55 `${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
56 CommandDeps: []string{
57 "$syspropCmd",
58 "${config.SoongZipCmd}",
59 },
60 })
Colin Crossc0b06f12015-04-08 13:03:43 -070061)
62
Colin Cross635c3b02016-05-18 15:37:25 -070063func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070064 javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070065 depFile := javaFile.String() + ".d"
Colin Crossc0b06f12015-04-08 13:03:43 -070066
Colin Crossae887032017-10-23 17:16:14 -070067 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070068 Rule: aidl,
69 Description: "aidl " + aidlFile.Rel(),
70 Output: javaFile,
71 Input: aidlFile,
Colin Crossc0b06f12015-04-08 13:03:43 -070072 Args: map[string]string{
73 "depFile": depFile,
74 "aidlFlags": aidlFlags,
75 },
76 })
77
78 return javaFile
79}
80
Colin Cross635c3b02016-05-18 15:37:25 -070081func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070082 javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
Colin Crossf05fe972015-04-10 17:45:20 -070083
Colin Crossae887032017-10-23 17:16:14 -070084 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070085 Rule: logtags,
86 Description: "logtags " + logtagsFile.Rel(),
87 Output: javaFile,
88 Input: logtagsFile,
Colin Crossf05fe972015-04-10 17:45:20 -070089 })
90
91 return javaFile
92}
93
Inseob Kim108be542018-10-04 19:39:35 +090094func genSysprop(ctx android.ModuleContext, syspropFile android.Path) android.Path {
95 srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
96
97 ctx.Build(pctx, android.BuildParams{
98 Rule: sysprop,
99 Description: "sysprop_java " + syspropFile.Rel(),
100 Output: srcJarFile,
101 Input: syspropFile,
102 })
103
104 return srcJarFile
105}
106
Colin Cross46c9b8b2017-06-22 16:51:17 -0700107func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Colin Crossaf050172017-11-15 23:01:59 -0800108 flags javaBuilderFlags) android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700109
Colin Cross6af17aa2017-09-20 12:59:05 -0700110 outSrcFiles := make(android.Paths, 0, len(srcFiles))
111
112 for _, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700113 switch srcFile.Ext() {
Colin Crossc0b06f12015-04-08 13:03:43 -0700114 case ".aidl":
115 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700116 outSrcFiles = append(outSrcFiles, javaFile)
Colin Crossf05fe972015-04-10 17:45:20 -0700117 case ".logtags":
118 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
119 javaFile := genLogtags(ctx, srcFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700120 outSrcFiles = append(outSrcFiles, javaFile)
121 case ".proto":
Colin Crossfe17f6f2019-03-28 19:30:56 -0700122 srcJarFile := genProto(ctx, srcFile, flags.proto)
Dan Willemsenab9f4262018-02-14 13:58:34 -0800123 outSrcFiles = append(outSrcFiles, srcJarFile)
Inseob Kim108be542018-10-04 19:39:35 +0900124 case ".sysprop":
125 srcJarFile := genSysprop(ctx, srcFile)
126 outSrcFiles = append(outSrcFiles, srcJarFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700127 default:
128 outSrcFiles = append(outSrcFiles, srcFile)
Colin Crossc0b06f12015-04-08 13:03:43 -0700129 }
130 }
131
Colin Crossaf050172017-11-15 23:01:59 -0800132 return outSrcFiles
Colin Crossc0b06f12015-04-08 13:03:43 -0700133}
Colin Crossf05fe972015-04-10 17:45:20 -0700134
Colin Cross0875c522017-11-28 17:34:01 -0800135func LogtagsSingleton() android.Singleton {
Colin Crossf05fe972015-04-10 17:45:20 -0700136 return &logtagsSingleton{}
137}
138
139type logtagsProducer interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700140 logtags() android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700141}
142
143type logtagsSingleton struct{}
144
Colin Cross0875c522017-11-28 17:34:01 -0800145func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700146 var allLogtags android.Paths
Colin Cross0875c522017-11-28 17:34:01 -0800147 ctx.VisitAllModules(func(module android.Module) {
Colin Crossf05fe972015-04-10 17:45:20 -0700148 if logtags, ok := module.(logtagsProducer); ok {
149 allLogtags = append(allLogtags, logtags.logtags()...)
150 }
151 })
152
Colin Cross0875c522017-11-28 17:34:01 -0800153 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700154 Rule: mergeLogtags,
155 Description: "merge logtags",
Colin Cross0875c522017-11-28 17:34:01 -0800156 Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
157 Inputs: allLogtags,
Colin Crossf05fe972015-04-10 17:45:20 -0700158 })
159}