blob: 81fc3417f25b91b6ddbe324d46fb59df507797d6 [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 && ` +
Inseob Kim42882742019-07-30 17:55:33 +090056 `$syspropCmd --scope $scope --java-output-dir $out.tmp $in && ` +
Inseob Kim108be542018-10-04 19:39:35 +090057 `${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
58 CommandDeps: []string{
59 "$syspropCmd",
60 "${config.SoongZipCmd}",
61 },
Inseob Kim42882742019-07-30 17:55:33 +090062 }, "scope")
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 Kim42882742019-07-30 17:55:33 +0900101func genSysprop(ctx android.ModuleContext, syspropFile android.Path, scope string) android.Path {
Inseob Kim108be542018-10-04 19:39:35 +0900102 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,
Inseob Kim42882742019-07-30 17:55:33 +0900109 Args: map[string]string{
110 "scope": scope,
111 },
Inseob Kim108be542018-10-04 19:39:35 +0900112 })
113
114 return srcJarFile
115}
116
Colin Cross46c9b8b2017-06-22 16:51:17 -0700117func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Colin Crossaf050172017-11-15 23:01:59 -0800118 flags javaBuilderFlags) android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -0700119
Colin Cross6af17aa2017-09-20 12:59:05 -0700120 outSrcFiles := make(android.Paths, 0, len(srcFiles))
121
122 for _, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700123 switch srcFile.Ext() {
Colin Crossc0b06f12015-04-08 13:03:43 -0700124 case ".aidl":
Colin Cross3047fa22019-04-18 10:56:44 -0700125 javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
Colin Cross6af17aa2017-09-20 12:59:05 -0700126 outSrcFiles = append(outSrcFiles, javaFile)
Colin Crossf05fe972015-04-10 17:45:20 -0700127 case ".logtags":
128 j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
129 javaFile := genLogtags(ctx, srcFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700130 outSrcFiles = append(outSrcFiles, javaFile)
131 case ".proto":
Colin Crossfe17f6f2019-03-28 19:30:56 -0700132 srcJarFile := genProto(ctx, srcFile, flags.proto)
Dan Willemsenab9f4262018-02-14 13:58:34 -0800133 outSrcFiles = append(outSrcFiles, srcJarFile)
Inseob Kim108be542018-10-04 19:39:35 +0900134 case ".sysprop":
Inseob Kim42882742019-07-30 17:55:33 +0900135 // internal scope contains all properties
136 // public scope only contains public properties
137 // use public if the owner is different from client
138 scope := "internal"
139 if j.properties.Sysprop.Platform != nil {
140 isProduct := ctx.ProductSpecific()
141 isVendor := ctx.SocSpecific()
142 isOwnerPlatform := Bool(j.properties.Sysprop.Platform)
143
144 if isProduct {
145 // product can't own any sysprop_library now, so product must use public scope
146 scope = "public"
147 } else if isVendor && !isOwnerPlatform {
148 // vendor and odm can't use system's internal property.
149 scope = "public"
150 }
151
152 // We don't care about clients under system.
153 // They can't use sysprop_library owned by other partitions.
154 }
155 srcJarFile := genSysprop(ctx, srcFile, scope)
Inseob Kim108be542018-10-04 19:39:35 +0900156 outSrcFiles = append(outSrcFiles, srcJarFile)
Colin Cross6af17aa2017-09-20 12:59:05 -0700157 default:
158 outSrcFiles = append(outSrcFiles, srcFile)
Colin Crossc0b06f12015-04-08 13:03:43 -0700159 }
160 }
161
Colin Crossaf050172017-11-15 23:01:59 -0800162 return outSrcFiles
Colin Crossc0b06f12015-04-08 13:03:43 -0700163}
Colin Crossf05fe972015-04-10 17:45:20 -0700164
Colin Cross0875c522017-11-28 17:34:01 -0800165func LogtagsSingleton() android.Singleton {
Colin Crossf05fe972015-04-10 17:45:20 -0700166 return &logtagsSingleton{}
167}
168
169type logtagsProducer interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700170 logtags() android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700171}
172
173type logtagsSingleton struct{}
174
Colin Cross0875c522017-11-28 17:34:01 -0800175func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700176 var allLogtags android.Paths
Colin Cross0875c522017-11-28 17:34:01 -0800177 ctx.VisitAllModules(func(module android.Module) {
Colin Crossf05fe972015-04-10 17:45:20 -0700178 if logtags, ok := module.(logtagsProducer); ok {
179 allLogtags = append(allLogtags, logtags.logtags()...)
180 }
181 })
182
Colin Cross0875c522017-11-28 17:34:01 -0800183 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700184 Rule: mergeLogtags,
185 Description: "merge logtags",
Colin Cross0875c522017-11-28 17:34:01 -0800186 Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
187 Inputs: allLogtags,
Colin Crossf05fe972015-04-10 17:45:20 -0700188 })
189}