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 15package 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 21import ( 22 "github.com/google/blueprint" 23 24 "android/soong/android" 25) 26 27func init() { 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") 31 32 pctx.IntermediatesPathVariable("allLogtagsFile", "all-event-log-tags.txt") 33} 34 35var ( 36 aidl = pctx.AndroidStaticRule("aidl", 37 blueprint.RuleParams{ 38 Command: "$aidlCmd -d$depFile $aidlFlags $in $out", 39 CommandDeps: []string{"$aidlCmd"}, 40 }, 41 "depFile", "aidlFlags") 42 43 logtags = pctx.AndroidStaticRule("logtags", 44 blueprint.RuleParams{ 45 Command: "$logtagsCmd -o $out $in $allLogtagsFile", 46 CommandDeps: []string{"$logtagsCmd"}, 47 }) 48 49 mergeLogtags = pctx.AndroidStaticRule("mergeLogtags", 50 blueprint.RuleParams{ 51 Command: "$mergeLogtagsCmd -o $out $in", 52 CommandDeps: []string{"$mergeLogtagsCmd"}, 53 }) 54) 55 56func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) android.Path { 57 javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java") 58 depFile := javaFile.String() + ".d" 59 60 ctx.ModuleBuild(pctx, android.ModuleBuildParams{ 61 Rule: aidl, 62 Description: "aidl " + aidlFile.Rel(), 63 Output: javaFile, 64 Input: aidlFile, 65 Args: map[string]string{ 66 "depFile": depFile, 67 "aidlFlags": aidlFlags, 68 }, 69 }) 70 71 return javaFile 72} 73 74func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path { 75 javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java") 76 77 ctx.ModuleBuild(pctx, android.ModuleBuildParams{ 78 Rule: logtags, 79 Description: "logtags " + logtagsFile.Rel(), 80 Output: javaFile, 81 Input: logtagsFile, 82 }) 83 84 return javaFile 85} 86 87func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, 88 flags javaBuilderFlags) android.Paths { 89 90 for i, srcFile := range srcFiles { 91 switch srcFile.Ext() { 92 case ".aidl": 93 javaFile := genAidl(ctx, srcFile, flags.aidlFlags) 94 srcFiles[i] = javaFile 95 case ".logtags": 96 j.logtagsSrcs = append(j.logtagsSrcs, srcFile) 97 javaFile := genLogtags(ctx, srcFile) 98 srcFiles[i] = javaFile 99 } 100 } 101 102 return srcFiles 103} 104 105func LogtagsSingleton() blueprint.Singleton { 106 return &logtagsSingleton{} 107} 108 109type logtagsProducer interface { 110 logtags() android.Paths 111} 112 113type logtagsSingleton struct{} 114 115func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { 116 var allLogtags android.Paths 117 ctx.VisitAllModules(func(module blueprint.Module) { 118 if logtags, ok := module.(logtagsProducer); ok { 119 allLogtags = append(allLogtags, logtags.logtags()...) 120 } 121 }) 122 123 ctx.Build(pctx, blueprint.BuildParams{ 124 Rule: mergeLogtags, 125 Description: "merge logtags", 126 Outputs: []string{"$allLogtagsFile"}, 127 Inputs: allLogtags.Strings(), 128 }) 129} 130