Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 17 | import ( |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 18 | "strings" |
| 19 | |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 21 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 22 | "android/soong/android" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func init() { |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 26 | pctx.HostBinToolVariable("syspropCmd", "sysprop_java") |
Dan Willemsen | aad1960 | 2019-04-07 09:44:35 -0700 | [diff] [blame] | 27 | pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py") |
| 28 | pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py") |
| 29 | pctx.SourcePathVariable("logtagsLib", "build/make/tools/event_log_tags.py") |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | var ( |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 33 | aidl = pctx.AndroidStaticRule("aidl", |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 34 | blueprint.RuleParams{ |
Colin Cross | bdf9514 | 2019-08-08 12:56:34 -0700 | [diff] [blame] | 35 | Command: "${config.AidlCmd} -d$depFile $aidlFlags $in $out", |
| 36 | CommandDeps: []string{"${config.AidlCmd}"}, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 37 | }, |
| 38 | "depFile", "aidlFlags") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 39 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 40 | logtags = pctx.AndroidStaticRule("logtags", |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 41 | blueprint.RuleParams{ |
Colin Cross | b1bd1aa | 2017-11-15 22:47:16 -0800 | [diff] [blame] | 42 | Command: "$logtagsCmd -o $out $in", |
Dan Willemsen | aad1960 | 2019-04-07 09:44:35 -0700 | [diff] [blame] | 43 | CommandDeps: []string{"$logtagsCmd", "$logtagsLib"}, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 44 | }) |
| 45 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 46 | mergeLogtags = pctx.AndroidStaticRule("mergeLogtags", |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 47 | blueprint.RuleParams{ |
| 48 | Command: "$mergeLogtagsCmd -o $out $in", |
Dan Willemsen | aad1960 | 2019-04-07 09:44:35 -0700 | [diff] [blame] | 49 | CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"}, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 50 | }) |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 51 | |
| 52 | sysprop = pctx.AndroidStaticRule("sysprop", |
| 53 | blueprint.RuleParams{ |
| 54 | Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` + |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 55 | `$syspropCmd --scope $scope --java-output-dir $out.tmp $in && ` + |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 56 | `${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`, |
| 57 | CommandDeps: []string{ |
| 58 | "$syspropCmd", |
| 59 | "${config.SoongZipCmd}", |
| 60 | }, |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 61 | }, "scope") |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 62 | ) |
| 63 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 64 | func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 65 | javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 66 | depFile := javaFile.String() + ".d" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 67 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 68 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 69 | Rule: aidl, |
| 70 | Description: "aidl " + aidlFile.Rel(), |
| 71 | Output: javaFile, |
| 72 | Input: aidlFile, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 73 | Implicits: deps, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 74 | Args: map[string]string{ |
| 75 | "depFile": depFile, |
| 76 | "aidlFlags": aidlFlags, |
| 77 | }, |
| 78 | }) |
| 79 | |
| 80 | return javaFile |
| 81 | } |
| 82 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 83 | func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 84 | javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 85 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 86 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 87 | Rule: logtags, |
| 88 | Description: "logtags " + logtagsFile.Rel(), |
| 89 | Output: javaFile, |
| 90 | Input: logtagsFile, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 91 | }) |
| 92 | |
| 93 | return javaFile |
| 94 | } |
| 95 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 96 | func genSysprop(ctx android.ModuleContext, syspropFile android.Path, scope string) android.Path { |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 97 | srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar") |
| 98 | |
| 99 | ctx.Build(pctx, android.BuildParams{ |
| 100 | Rule: sysprop, |
| 101 | Description: "sysprop_java " + syspropFile.Rel(), |
| 102 | Output: srcJarFile, |
| 103 | Input: syspropFile, |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 104 | Args: map[string]string{ |
| 105 | "scope": scope, |
| 106 | }, |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 107 | }) |
| 108 | |
| 109 | return srcJarFile |
| 110 | } |
| 111 | |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 112 | func genAidlIncludeFlags(srcFiles android.Paths) string { |
| 113 | var baseDirs []string |
| 114 | for _, srcFile := range srcFiles { |
| 115 | if srcFile.Ext() == ".aidl" { |
| 116 | baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel()) |
| 117 | if baseDir != "" && !android.InList(baseDir, baseDirs) { |
| 118 | baseDirs = append(baseDirs, baseDir) |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | return android.JoinWithPrefix(baseDirs, " -I") |
| 123 | } |
| 124 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 125 | func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 126 | flags javaBuilderFlags) android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 127 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 128 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
| 129 | |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 130 | aidlIncludeFlags := genAidlIncludeFlags(srcFiles) |
| 131 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 132 | for _, srcFile := range srcFiles { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 133 | switch srcFile.Ext() { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 134 | case ".aidl": |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 135 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 136 | outSrcFiles = append(outSrcFiles, javaFile) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 137 | case ".logtags": |
| 138 | j.logtagsSrcs = append(j.logtagsSrcs, srcFile) |
| 139 | javaFile := genLogtags(ctx, srcFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 140 | outSrcFiles = append(outSrcFiles, javaFile) |
| 141 | case ".proto": |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 142 | srcJarFile := genProto(ctx, srcFile, flags.proto) |
Dan Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 143 | outSrcFiles = append(outSrcFiles, srcJarFile) |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 144 | case ".sysprop": |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 145 | // internal scope contains all properties |
| 146 | // public scope only contains public properties |
| 147 | // use public if the owner is different from client |
| 148 | scope := "internal" |
| 149 | if j.properties.Sysprop.Platform != nil { |
| 150 | isProduct := ctx.ProductSpecific() |
| 151 | isVendor := ctx.SocSpecific() |
| 152 | isOwnerPlatform := Bool(j.properties.Sysprop.Platform) |
| 153 | |
| 154 | if isProduct { |
| 155 | // product can't own any sysprop_library now, so product must use public scope |
| 156 | scope = "public" |
| 157 | } else if isVendor && !isOwnerPlatform { |
| 158 | // vendor and odm can't use system's internal property. |
| 159 | scope = "public" |
| 160 | } |
| 161 | |
| 162 | // We don't care about clients under system. |
| 163 | // They can't use sysprop_library owned by other partitions. |
| 164 | } |
| 165 | srcJarFile := genSysprop(ctx, srcFile, scope) |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 166 | outSrcFiles = append(outSrcFiles, srcJarFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 167 | default: |
| 168 | outSrcFiles = append(outSrcFiles, srcFile) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 172 | return outSrcFiles |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 173 | } |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 174 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 175 | func LogtagsSingleton() android.Singleton { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 176 | return &logtagsSingleton{} |
| 177 | } |
| 178 | |
| 179 | type logtagsProducer interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 180 | logtags() android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | type logtagsSingleton struct{} |
| 184 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 185 | func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 186 | var allLogtags android.Paths |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 187 | ctx.VisitAllModules(func(module android.Module) { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 188 | if logtags, ok := module.(logtagsProducer); ok { |
| 189 | allLogtags = append(allLogtags, logtags.logtags()...) |
| 190 | } |
| 191 | }) |
| 192 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 193 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 194 | Rule: mergeLogtags, |
| 195 | Description: "merge logtags", |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 196 | Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"), |
| 197 | Inputs: allLogtags, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 198 | }) |
| 199 | } |