blob: 69965ecec8877dc32edf3f0b74c4c2336ccb5670 [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 (
Jiyong Park29074592019-07-07 16:27:47 +090018 "strings"
19
Colin Crossc0b06f12015-04-08 13:03:43 -070020 "github.com/google/blueprint"
Colin Crossc0b06f12015-04-08 13:03:43 -070021
Colin Cross635c3b02016-05-18 15:37:25 -070022 "android/soong/android"
Colin Crossc0b06f12015-04-08 13:03:43 -070023)
24
25func init() {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070026 pctx.HostBinToolVariable("aidlCmd", "aidl")
Inseob Kim108be542018-10-04 19:39:35 +090027 pctx.HostBinToolVariable("syspropCmd", "sysprop_java")
Dan Willemsenaad19602019-04-07 09:44:35 -070028 pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py")
29 pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py")
30 pctx.SourcePathVariable("logtagsLib", "build/make/tools/event_log_tags.py")
Colin Crossc0b06f12015-04-08 13:03:43 -070031}
32
33var (
Colin Cross9d45bb72016-08-29 16:14:13 -070034 aidl = pctx.AndroidStaticRule("aidl",
Colin Crossc0b06f12015-04-08 13:03:43 -070035 blueprint.RuleParams{
36 Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080037 CommandDeps: []string{"$aidlCmd"},
Colin Crossc0b06f12015-04-08 13:03:43 -070038 },
39 "depFile", "aidlFlags")
Colin Crossf05fe972015-04-10 17:45:20 -070040
Colin Cross9d45bb72016-08-29 16:14:13 -070041 logtags = pctx.AndroidStaticRule("logtags",
Colin Crossf05fe972015-04-10 17:45:20 -070042 blueprint.RuleParams{
Colin Crossb1bd1aa2017-11-15 22:47:16 -080043 Command: "$logtagsCmd -o $out $in",
Dan Willemsenaad19602019-04-07 09:44:35 -070044 CommandDeps: []string{"$logtagsCmd", "$logtagsLib"},
Colin Crossf05fe972015-04-10 17:45:20 -070045 })
46
Colin Cross9d45bb72016-08-29 16:14:13 -070047 mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
Colin Crossf05fe972015-04-10 17:45:20 -070048 blueprint.RuleParams{
49 Command: "$mergeLogtagsCmd -o $out $in",
Dan Willemsenaad19602019-04-07 09:44:35 -070050 CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"},
Colin Crossf05fe972015-04-10 17:45:20 -070051 })
Inseob Kim108be542018-10-04 19:39:35 +090052
53 sysprop = pctx.AndroidStaticRule("sysprop",
54 blueprint.RuleParams{
55 Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
56 `$syspropCmd --java-output-dir $out.tmp $in && ` +
57 `${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
58 CommandDeps: []string{
59 "$syspropCmd",
60 "${config.SoongZipCmd}",
61 },
62 })
Colin Crossc0b06f12015-04-08 13:03:43 -070063)
64
Colin Cross3047fa22019-04-18 10:56:44 -070065func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070066 javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070067 depFile := javaFile.String() + ".d"
Jiyong Park29074592019-07-07 16:27:47 +090068 baseDir := strings.TrimSuffix(aidlFile.String(), aidlFile.Rel())
69 if baseDir != "" {
70 aidlFlags += " -I" + baseDir
71 }
Colin Crossc0b06f12015-04-08 13:03:43 -070072
Colin Crossae887032017-10-23 17:16:14 -070073 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070074 Rule: aidl,
75 Description: "aidl " + aidlFile.Rel(),
76 Output: javaFile,
77 Input: aidlFile,
Colin Cross3047fa22019-04-18 10:56:44 -070078 Implicits: deps,
Colin Crossc0b06f12015-04-08 13:03:43 -070079 Args: map[string]string{
80 "depFile": depFile,
81 "aidlFlags": aidlFlags,
82 },
83 })
84
85 return javaFile
86}
87
Colin Cross635c3b02016-05-18 15:37:25 -070088func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
Dan Willemsen21ec4902016-11-02 20:43:13 -070089 javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
Colin Crossf05fe972015-04-10 17:45:20 -070090
Colin Crossae887032017-10-23 17:16:14 -070091 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070092 Rule: logtags,
93 Description: "logtags " + logtagsFile.Rel(),
94 Output: javaFile,
95 Input: logtagsFile,
Colin Crossf05fe972015-04-10 17:45:20 -070096 })
97
98 return javaFile
99}
100
Inseob Kim108be542018-10-04 19:39:35 +0900101func genSysprop(ctx android.ModuleContext, syspropFile android.Path) android.Path {
102 srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
103
104 ctx.Build(pctx, android.BuildParams{
105 Rule: sysprop,
106 Description: "sysprop_java " + syspropFile.Rel(),
107 Output: srcJarFile,
108 Input: syspropFile,
109 })
110
111 return srcJarFile
112}
113
Colin Cross46c9b8b2017-06-22 16:51:17 -0700114func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Colin Crossaf050172017-11-15 23:01:59 -0800115 flags javaBuilderFlags) android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700116
Colin Cross6af17aa2017-09-20 12:59:05 -0700117 outSrcFiles := make(android.Paths, 0, len(srcFiles))
118
119 for _, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120 switch srcFile.Ext() {
Colin Crossc0b06f12015-04-08 13:03:43 -0700121 case ".aidl":
Colin Cross3047fa22019-04-18 10:56:44 -0700122 javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
Colin Cross6af17aa2017-09-20 12:59:05 -0700123 outSrcFiles = append(outSrcFiles, javaFile)
Colin Crossf05fe972015-04-10 17:45:20 -0700124 case ".logtags":
125 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
126 javaFile := genLogtags(ctx, srcFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700127 outSrcFiles = append(outSrcFiles, javaFile)
128 case ".proto":
Colin Crossfe17f6f2019-03-28 19:30:56 -0700129 srcJarFile := genProto(ctx, srcFile, flags.proto)
Dan Willemsenab9f4262018-02-14 13:58:34 -0800130 outSrcFiles = append(outSrcFiles, srcJarFile)
Inseob Kim108be542018-10-04 19:39:35 +0900131 case ".sysprop":
132 srcJarFile := genSysprop(ctx, srcFile)
133 outSrcFiles = append(outSrcFiles, srcJarFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700134 default:
135 outSrcFiles = append(outSrcFiles, srcFile)
Colin Crossc0b06f12015-04-08 13:03:43 -0700136 }
137 }
138
Colin Crossaf050172017-11-15 23:01:59 -0800139 return outSrcFiles
Colin Crossc0b06f12015-04-08 13:03:43 -0700140}
Colin Crossf05fe972015-04-10 17:45:20 -0700141
Colin Cross0875c522017-11-28 17:34:01 -0800142func LogtagsSingleton() android.Singleton {
Colin Crossf05fe972015-04-10 17:45:20 -0700143 return &logtagsSingleton{}
144}
145
146type logtagsProducer interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700147 logtags() android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700148}
149
150type logtagsSingleton struct{}
151
Colin Cross0875c522017-11-28 17:34:01 -0800152func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700153 var allLogtags android.Paths
Colin Cross0875c522017-11-28 17:34:01 -0800154 ctx.VisitAllModules(func(module android.Module) {
Colin Crossf05fe972015-04-10 17:45:20 -0700155 if logtags, ok := module.(logtagsProducer); ok {
156 allLogtags = append(allLogtags, logtags.logtags()...)
157 }
158 })
159
Colin Cross0875c522017-11-28 17:34:01 -0800160 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700161 Rule: mergeLogtags,
162 Description: "merge logtags",
Colin Cross0875c522017-11-28 17:34:01 -0800163 Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
164 Inputs: allLogtags,
Colin Crossf05fe972015-04-10 17:45:20 -0700165 })
166}