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 | |
| 17 | // This file generates the final rules for compiling all C/C++. All properties related to |
| 18 | // compiling should have been translated into builderFlags or another argument to the Transform* |
| 19 | // functions. |
| 20 | |
| 21 | import ( |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 23 | |
| 24 | "android/soong/common" |
| 25 | ) |
| 26 | |
| 27 | func init() { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 28 | pctx.HostBinToolVariable("aidlCmd", "aidl") |
| 29 | pctx.SourcePathVariable("logtagsCmd", "build/tools/java-event-log-tags.py") |
| 30 | pctx.SourcePathVariable("mergeLogtagsCmd", "build/tools/merge-event-log-tags.py") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 31 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 32 | pctx.IntermediatesPathVariable("allLogtagsFile", "all-event-log-tags.txt") |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | var ( |
| 36 | aidl = pctx.StaticRule("aidl", |
| 37 | blueprint.RuleParams{ |
| 38 | Command: "$aidlCmd -d$depFile $aidlFlags $in $out", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 39 | CommandDeps: []string{"$aidlCmd"}, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 40 | Description: "aidl $out", |
| 41 | }, |
| 42 | "depFile", "aidlFlags") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 43 | |
| 44 | logtags = pctx.StaticRule("logtags", |
| 45 | blueprint.RuleParams{ |
| 46 | Command: "$logtagsCmd -o $out $in $allLogtagsFile", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 47 | CommandDeps: []string{"$logtagsCmd"}, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 48 | Description: "logtags $out", |
| 49 | }) |
| 50 | |
| 51 | mergeLogtags = pctx.StaticRule("mergeLogtags", |
| 52 | blueprint.RuleParams{ |
| 53 | Command: "$mergeLogtagsCmd -o $out $in", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 54 | CommandDeps: []string{"$mergeLogtagsCmd"}, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 55 | Description: "merge logtags $out", |
| 56 | }) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 57 | ) |
| 58 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 59 | func genAidl(ctx common.AndroidModuleContext, aidlFile common.Path, aidlFlags string) common.Path { |
| 60 | javaFile := common.GenPathWithExt(ctx, aidlFile, "java") |
| 61 | depFile := javaFile.String() + ".d" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 62 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 63 | ctx.ModuleBuild(pctx, common.ModuleBuildParams{ |
| 64 | Rule: aidl, |
| 65 | Output: javaFile, |
| 66 | Input: aidlFile, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 67 | Args: map[string]string{ |
| 68 | "depFile": depFile, |
| 69 | "aidlFlags": aidlFlags, |
| 70 | }, |
| 71 | }) |
| 72 | |
| 73 | return javaFile |
| 74 | } |
| 75 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 76 | func genLogtags(ctx common.AndroidModuleContext, logtagsFile common.Path) common.Path { |
| 77 | javaFile := common.GenPathWithExt(ctx, logtagsFile, "java") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 78 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 79 | ctx.ModuleBuild(pctx, common.ModuleBuildParams{ |
| 80 | Rule: logtags, |
| 81 | Output: javaFile, |
| 82 | Input: logtagsFile, |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 83 | }) |
| 84 | |
| 85 | return javaFile |
| 86 | } |
| 87 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 88 | func (j *javaBase) genSources(ctx common.AndroidModuleContext, srcFiles common.Paths, |
| 89 | flags javaBuilderFlags) common.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 90 | |
| 91 | for i, srcFile := range srcFiles { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 92 | switch srcFile.Ext() { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 93 | case ".aidl": |
| 94 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags) |
| 95 | srcFiles[i] = javaFile |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 96 | case ".logtags": |
| 97 | j.logtagsSrcs = append(j.logtagsSrcs, srcFile) |
| 98 | javaFile := genLogtags(ctx, srcFile) |
| 99 | srcFiles[i] = javaFile |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | return srcFiles |
| 104 | } |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 105 | |
| 106 | func LogtagsSingleton() blueprint.Singleton { |
| 107 | return &logtagsSingleton{} |
| 108 | } |
| 109 | |
| 110 | type logtagsProducer interface { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 111 | logtags() common.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | type logtagsSingleton struct{} |
| 115 | |
| 116 | func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 117 | var allLogtags common.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 118 | ctx.VisitAllModules(func(module blueprint.Module) { |
| 119 | if logtags, ok := module.(logtagsProducer); ok { |
| 120 | allLogtags = append(allLogtags, logtags.logtags()...) |
| 121 | } |
| 122 | }) |
| 123 | |
| 124 | ctx.Build(pctx, blueprint.BuildParams{ |
| 125 | Rule: mergeLogtags, |
| 126 | Outputs: []string{"$allLogtagsFile"}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 127 | Inputs: allLogtags.Strings(), |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 128 | }) |
| 129 | } |