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" |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame^] | 68 | baseDir := strings.TrimSuffix(aidlFile.String(), aidlFile.Rel()) |
| 69 | if baseDir != "" { |
| 70 | aidlFlags += " -I" + baseDir |
| 71 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 72 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 73 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 74 | Rule: aidl, |
| 75 | Description: "aidl " + aidlFile.Rel(), |
| 76 | Output: javaFile, |
| 77 | Input: aidlFile, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 78 | Implicits: deps, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 79 | Args: map[string]string{ |
| 80 | "depFile": depFile, |
| 81 | "aidlFlags": aidlFlags, |
| 82 | }, |
| 83 | }) |
| 84 | |
| 85 | return javaFile |
| 86 | } |
| 87 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 88 | func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 89 | javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 90 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 91 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 92 | Rule: logtags, |
| 93 | Description: "logtags " + logtagsFile.Rel(), |
| 94 | Output: javaFile, |
| 95 | Input: logtagsFile, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 96 | }) |
| 97 | |
| 98 | return javaFile |
| 99 | } |
| 100 | |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 101 | func 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 Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 114 | func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 115 | flags javaBuilderFlags) android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 116 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 117 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
| 118 | |
| 119 | for _, srcFile := range srcFiles { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 120 | switch srcFile.Ext() { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 121 | case ".aidl": |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 122 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 123 | outSrcFiles = append(outSrcFiles, javaFile) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 124 | case ".logtags": |
| 125 | j.logtagsSrcs = append(j.logtagsSrcs, srcFile) |
| 126 | javaFile := genLogtags(ctx, srcFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 127 | outSrcFiles = append(outSrcFiles, javaFile) |
| 128 | case ".proto": |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 129 | srcJarFile := genProto(ctx, srcFile, flags.proto) |
Dan Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 130 | outSrcFiles = append(outSrcFiles, srcJarFile) |
Inseob Kim | 108be54 | 2018-10-04 19:39:35 +0900 | [diff] [blame] | 131 | case ".sysprop": |
| 132 | srcJarFile := genSysprop(ctx, srcFile) |
| 133 | outSrcFiles = append(outSrcFiles, srcJarFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 134 | default: |
| 135 | outSrcFiles = append(outSrcFiles, srcFile) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 139 | return outSrcFiles |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 140 | } |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 141 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 142 | func LogtagsSingleton() android.Singleton { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 143 | return &logtagsSingleton{} |
| 144 | } |
| 145 | |
| 146 | type logtagsProducer interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 147 | logtags() android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | type logtagsSingleton struct{} |
| 151 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 152 | func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 153 | var allLogtags android.Paths |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 154 | ctx.VisitAllModules(func(module android.Module) { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 155 | if logtags, ok := module.(logtagsProducer); ok { |
| 156 | allLogtags = append(allLogtags, logtags.logtags()...) |
| 157 | } |
| 158 | }) |
| 159 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 160 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 161 | Rule: mergeLogtags, |
| 162 | Description: "merge logtags", |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 163 | Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"), |
| 164 | Inputs: allLogtags, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 165 | }) |
| 166 | } |