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