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() { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 26 | pctx.HostBinToolVariable("aidlCmd", "aidl") |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 27 | pctx.HostBinToolVariable("syspropCmd", "sysprop_java") |
Dan Willemsen | aad1960 | 2019-04-07 09:44:35 -0700 | [diff] [blame] | 28 | 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 Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | var ( |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 34 | aidl = pctx.AndroidStaticRule("aidl", |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 35 | blueprint.RuleParams{ |
| 36 | Command: "$aidlCmd -d$depFile $aidlFlags $in $out", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 37 | CommandDeps: []string{"$aidlCmd"}, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 38 | }, |
| 39 | "depFile", "aidlFlags") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 40 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 41 | logtags = pctx.AndroidStaticRule("logtags", |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 42 | blueprint.RuleParams{ |
Colin Cross | b1bd1aa | 2017-11-15 22:47:16 -0800 | [diff] [blame] | 43 | Command: "$logtagsCmd -o $out $in", |
Dan Willemsen | aad1960 | 2019-04-07 09:44:35 -0700 | [diff] [blame] | 44 | CommandDeps: []string{"$logtagsCmd", "$logtagsLib"}, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 45 | }) |
| 46 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 47 | mergeLogtags = pctx.AndroidStaticRule("mergeLogtags", |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 48 | blueprint.RuleParams{ |
| 49 | Command: "$mergeLogtagsCmd -o $out $in", |
Dan Willemsen | aad1960 | 2019-04-07 09:44:35 -0700 | [diff] [blame] | 50 | CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"}, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 51 | }) |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 52 | |
| 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 Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 63 | ) |
| 64 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 65 | 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] | 66 | javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 67 | depFile := javaFile.String() + ".d" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 68 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 69 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 70 | Rule: aidl, |
| 71 | Description: "aidl " + aidlFile.Rel(), |
| 72 | Output: javaFile, |
| 73 | Input: aidlFile, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 74 | Implicits: deps, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 75 | Args: map[string]string{ |
| 76 | "depFile": depFile, |
| 77 | "aidlFlags": aidlFlags, |
| 78 | }, |
| 79 | }) |
| 80 | |
| 81 | return javaFile |
| 82 | } |
| 83 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 84 | func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 85 | javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 86 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 87 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 88 | Rule: logtags, |
| 89 | Description: "logtags " + logtagsFile.Rel(), |
| 90 | Output: javaFile, |
| 91 | Input: logtagsFile, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 92 | }) |
| 93 | |
| 94 | return javaFile |
| 95 | } |
| 96 | |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 97 | func genSysprop(ctx android.ModuleContext, syspropFile android.Path) android.Path { |
| 98 | srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar") |
| 99 | |
| 100 | ctx.Build(pctx, android.BuildParams{ |
| 101 | Rule: sysprop, |
| 102 | Description: "sysprop_java " + syspropFile.Rel(), |
| 103 | Output: srcJarFile, |
| 104 | Input: syspropFile, |
| 105 | }) |
| 106 | |
| 107 | return srcJarFile |
| 108 | } |
| 109 | |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame^] | 110 | func genAidlIncludeFlags(srcFiles android.Paths) string { |
| 111 | var baseDirs []string |
| 112 | for _, srcFile := range srcFiles { |
| 113 | if srcFile.Ext() == ".aidl" { |
| 114 | baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel()) |
| 115 | if baseDir != "" && !android.InList(baseDir, baseDirs) { |
| 116 | baseDirs = append(baseDirs, baseDir) |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | return android.JoinWithPrefix(baseDirs, " -I") |
| 121 | } |
| 122 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 123 | func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 124 | flags javaBuilderFlags) android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 125 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 126 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
| 127 | |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame^] | 128 | aidlIncludeFlags := genAidlIncludeFlags(srcFiles) |
| 129 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 130 | for _, srcFile := range srcFiles { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 131 | switch srcFile.Ext() { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 132 | case ".aidl": |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame^] | 133 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 134 | outSrcFiles = append(outSrcFiles, javaFile) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 135 | case ".logtags": |
| 136 | j.logtagsSrcs = append(j.logtagsSrcs, srcFile) |
| 137 | javaFile := genLogtags(ctx, srcFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 138 | outSrcFiles = append(outSrcFiles, javaFile) |
| 139 | case ".proto": |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 140 | srcJarFile := genProto(ctx, srcFile, flags.proto) |
Dan Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 141 | outSrcFiles = append(outSrcFiles, srcJarFile) |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 142 | case ".sysprop": |
| 143 | srcJarFile := genSysprop(ctx, srcFile) |
| 144 | outSrcFiles = append(outSrcFiles, srcJarFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 145 | default: |
| 146 | outSrcFiles = append(outSrcFiles, srcFile) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 150 | return outSrcFiles |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 151 | } |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 152 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 153 | func LogtagsSingleton() android.Singleton { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 154 | return &logtagsSingleton{} |
| 155 | } |
| 156 | |
| 157 | type logtagsProducer interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 158 | logtags() android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | type logtagsSingleton struct{} |
| 162 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 163 | func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 164 | var allLogtags android.Paths |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 165 | ctx.VisitAllModules(func(module android.Module) { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 166 | if logtags, ok := module.(logtagsProducer); ok { |
| 167 | allLogtags = append(allLogtags, logtags.logtags()...) |
| 168 | } |
| 169 | }) |
| 170 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 171 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 172 | Rule: mergeLogtags, |
| 173 | Description: "merge logtags", |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 174 | Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"), |
| 175 | Inputs: allLogtags, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 176 | }) |
| 177 | } |