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 ( |
| 22 | "path/filepath" |
| 23 | "strings" |
| 24 | |
| 25 | "github.com/google/blueprint" |
| 26 | "github.com/google/blueprint/pathtools" |
| 27 | |
| 28 | "android/soong/common" |
| 29 | ) |
| 30 | |
| 31 | func init() { |
| 32 | pctx.VariableFunc("aidlCmd", func(c interface{}) (string, error) { |
| 33 | return c.(common.Config).HostBinTool("aidl") |
| 34 | }) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 35 | pctx.StaticVariable("logtagsCmd", "${srcDir}/build/tools/java-event-log-tags.py") |
| 36 | pctx.StaticVariable("mergeLogtagsCmd", "${srcDir}/build/tools/merge-event-log-tags.py") |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 37 | pctx.VariableConfigMethod("srcDir", common.Config.SrcDir) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 38 | |
| 39 | pctx.VariableFunc("allLogtagsFile", func(c interface{}) (string, error) { |
| 40 | return filepath.Join(c.(common.Config).IntermediatesDir(), "all-event-log-tags.txt"), nil |
| 41 | }) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | var ( |
| 45 | aidl = pctx.StaticRule("aidl", |
| 46 | blueprint.RuleParams{ |
| 47 | Command: "$aidlCmd -d$depFile $aidlFlags $in $out", |
| 48 | Description: "aidl $out", |
| 49 | }, |
| 50 | "depFile", "aidlFlags") |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 51 | |
| 52 | logtags = pctx.StaticRule("logtags", |
| 53 | blueprint.RuleParams{ |
| 54 | Command: "$logtagsCmd -o $out $in $allLogtagsFile", |
| 55 | Description: "logtags $out", |
| 56 | }) |
| 57 | |
| 58 | mergeLogtags = pctx.StaticRule("mergeLogtags", |
| 59 | blueprint.RuleParams{ |
| 60 | Command: "$mergeLogtagsCmd -o $out $in", |
| 61 | Description: "merge logtags $out", |
| 62 | }) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 63 | ) |
| 64 | |
| 65 | func genAidl(ctx common.AndroidModuleContext, aidlFile, aidlFlags string) string { |
| 66 | javaFile := strings.TrimPrefix(aidlFile, common.ModuleSrcDir(ctx)) |
| 67 | javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile) |
| 68 | javaFile = pathtools.ReplaceExtension(javaFile, "java") |
| 69 | depFile := javaFile + ".d" |
| 70 | |
| 71 | ctx.Build(pctx, blueprint.BuildParams{ |
| 72 | Rule: aidl, |
| 73 | Outputs: []string{javaFile}, |
| 74 | Inputs: []string{aidlFile}, |
| 75 | Implicits: []string{"$aidlCmd"}, |
| 76 | Args: map[string]string{ |
| 77 | "depFile": depFile, |
| 78 | "aidlFlags": aidlFlags, |
| 79 | }, |
| 80 | }) |
| 81 | |
| 82 | return javaFile |
| 83 | } |
| 84 | |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 85 | func genLogtags(ctx common.AndroidModuleContext, logtagsFile string) string { |
| 86 | javaFile := strings.TrimPrefix(logtagsFile, common.ModuleSrcDir(ctx)) |
| 87 | javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile) |
| 88 | javaFile = pathtools.ReplaceExtension(javaFile, "java") |
| 89 | |
| 90 | ctx.Build(pctx, blueprint.BuildParams{ |
| 91 | Rule: logtags, |
| 92 | Outputs: []string{javaFile}, |
| 93 | Inputs: []string{logtagsFile}, |
| 94 | Implicits: []string{"$logtagsCmd"}, |
| 95 | }) |
| 96 | |
| 97 | return javaFile |
| 98 | } |
| 99 | |
| 100 | func (j *javaBase) genSources(ctx common.AndroidModuleContext, srcFiles []string, |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 101 | flags javaBuilderFlags) []string { |
| 102 | |
| 103 | for i, srcFile := range srcFiles { |
| 104 | switch filepath.Ext(srcFile) { |
| 105 | case ".aidl": |
| 106 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags) |
| 107 | srcFiles[i] = javaFile |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 108 | case ".logtags": |
| 109 | j.logtagsSrcs = append(j.logtagsSrcs, srcFile) |
| 110 | javaFile := genLogtags(ctx, srcFile) |
| 111 | srcFiles[i] = javaFile |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | return srcFiles |
| 116 | } |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame^] | 117 | |
| 118 | func LogtagsSingleton() blueprint.Singleton { |
| 119 | return &logtagsSingleton{} |
| 120 | } |
| 121 | |
| 122 | type logtagsProducer interface { |
| 123 | logtags() []string |
| 124 | } |
| 125 | |
| 126 | type logtagsSingleton struct{} |
| 127 | |
| 128 | func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
| 129 | var allLogtags []string |
| 130 | ctx.VisitAllModules(func(module blueprint.Module) { |
| 131 | if logtags, ok := module.(logtagsProducer); ok { |
| 132 | allLogtags = append(allLogtags, logtags.logtags()...) |
| 133 | } |
| 134 | }) |
| 135 | |
| 136 | ctx.Build(pctx, blueprint.BuildParams{ |
| 137 | Rule: mergeLogtags, |
| 138 | Outputs: []string{"$allLogtagsFile"}, |
| 139 | Inputs: allLogtags, |
| 140 | }) |
| 141 | } |