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 | 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{ |
Colin Cross | bdf9514 | 2019-08-08 12:56:34 -0700 | [diff] [blame] | 34 | Command: "${config.AidlCmd} -d$depFile $aidlFlags $in $out", |
| 35 | CommandDeps: []string{"${config.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 | }) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 50 | ) |
| 51 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 52 | 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] | 53 | javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 54 | depFile := javaFile.String() + ".d" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 55 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 56 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 57 | Rule: aidl, |
| 58 | Description: "aidl " + aidlFile.Rel(), |
| 59 | Output: javaFile, |
| 60 | Input: aidlFile, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 61 | Implicits: deps, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 62 | Args: map[string]string{ |
| 63 | "depFile": depFile, |
| 64 | "aidlFlags": aidlFlags, |
| 65 | }, |
| 66 | }) |
| 67 | |
| 68 | return javaFile |
| 69 | } |
| 70 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 71 | func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 72 | javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 73 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 74 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 75 | Rule: logtags, |
| 76 | Description: "logtags " + logtagsFile.Rel(), |
| 77 | Output: javaFile, |
| 78 | Input: logtagsFile, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 79 | }) |
| 80 | |
| 81 | return javaFile |
| 82 | } |
| 83 | |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 84 | func genAidlIncludeFlags(srcFiles android.Paths) string { |
| 85 | var baseDirs []string |
| 86 | for _, srcFile := range srcFiles { |
| 87 | if srcFile.Ext() == ".aidl" { |
| 88 | baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel()) |
| 89 | if baseDir != "" && !android.InList(baseDir, baseDirs) { |
| 90 | baseDirs = append(baseDirs, baseDir) |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return android.JoinWithPrefix(baseDirs, " -I") |
| 95 | } |
| 96 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 97 | func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 98 | flags javaBuilderFlags) android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 99 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 100 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
Colin Cross | 9516a6c | 2019-06-14 18:51:12 -0700 | [diff] [blame^] | 101 | var protoSrcs android.Paths |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 102 | |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 103 | aidlIncludeFlags := genAidlIncludeFlags(srcFiles) |
| 104 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 105 | for _, srcFile := range srcFiles { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 106 | switch srcFile.Ext() { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 107 | case ".aidl": |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 108 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 109 | outSrcFiles = append(outSrcFiles, javaFile) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 110 | case ".logtags": |
| 111 | j.logtagsSrcs = append(j.logtagsSrcs, srcFile) |
| 112 | javaFile := genLogtags(ctx, srcFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 113 | outSrcFiles = append(outSrcFiles, javaFile) |
| 114 | case ".proto": |
Colin Cross | 9516a6c | 2019-06-14 18:51:12 -0700 | [diff] [blame^] | 115 | protoSrcs = append(protoSrcs, srcFile) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 116 | default: |
| 117 | outSrcFiles = append(outSrcFiles, srcFile) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Colin Cross | 9516a6c | 2019-06-14 18:51:12 -0700 | [diff] [blame^] | 121 | // Process all proto files together to support sharding them into one or more rules that produce srcjars. |
| 122 | if len(protoSrcs) > 0 { |
| 123 | srcJarFiles := genProto(ctx, protoSrcs, flags.proto) |
| 124 | outSrcFiles = append(outSrcFiles, srcJarFiles...) |
| 125 | } |
| 126 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 127 | return outSrcFiles |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 128 | } |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 129 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 130 | func LogtagsSingleton() android.Singleton { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 131 | return &logtagsSingleton{} |
| 132 | } |
| 133 | |
| 134 | type logtagsProducer interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 135 | logtags() android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | type logtagsSingleton struct{} |
| 139 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 140 | func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 141 | var allLogtags android.Paths |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 142 | ctx.VisitAllModules(func(module android.Module) { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 143 | if logtags, ok := module.(logtagsProducer); ok { |
| 144 | allLogtags = append(allLogtags, logtags.logtags()...) |
| 145 | } |
| 146 | }) |
| 147 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 148 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 149 | Rule: mergeLogtags, |
| 150 | Description: "merge logtags", |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 151 | Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"), |
| 152 | Inputs: allLogtags, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 153 | }) |
| 154 | } |