diff --git a/android/Android.bp b/android/Android.bp index f130d3aee..f0be44b5b 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -60,6 +60,7 @@ bootstrap_go_package { "license_metadata.go", "license_sdk_member.go", "licenses.go", + "logtags.go", "makevars.go", "metrics.go", "module.go", diff --git a/android/logtags.go b/android/logtags.go new file mode 100644 index 000000000..d11cccf4f --- /dev/null +++ b/android/logtags.go @@ -0,0 +1,56 @@ +// Copyright 2024 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package android + +import "github.com/google/blueprint" + +func init() { + RegisterParallelSingletonType("logtags", LogtagsSingleton) +} + +type LogtagsInfo struct { + Logtags Paths +} + +var LogtagsProviderKey = blueprint.NewProvider[*LogtagsInfo]() + +func LogtagsSingleton() Singleton { + return &logtagsSingleton{} +} + +type logtagsSingleton struct{} + +func MergedLogtagsPath(ctx PathContext) OutputPath { + return PathForIntermediates(ctx, "all-event-log-tags.txt") +} + +func (l *logtagsSingleton) GenerateBuildActions(ctx SingletonContext) { + var allLogtags Paths + ctx.VisitAllModules(func(module Module) { + if !module.ExportedToMake() { + return + } + if logtagsInfo, ok := SingletonModuleProvider(ctx, module, LogtagsProviderKey); ok { + allLogtags = append(allLogtags, logtagsInfo.Logtags...) + } + }) + + builder := NewRuleBuilder(pctx, ctx) + builder.Command(). + BuiltTool("merge-event-log-tags"). + FlagWithOutput("-o ", MergedLogtagsPath(ctx)). + Inputs(SortedUniquePaths(allLogtags)) + builder.Build("all-event-log-tags.txt", "merge logtags") +} diff --git a/androidmk/androidmk/android.go b/androidmk/androidmk/android.go index 9d61e1cf9..8a8bb2eaa 100644 --- a/androidmk/androidmk/android.go +++ b/androidmk/androidmk/android.go @@ -151,7 +151,7 @@ func init() { "LOCAL_CLANG_CFLAGS": "clang_cflags", "LOCAL_YACCFLAGS": "yacc.flags", "LOCAL_SANITIZE_RECOVER": "sanitize.recover", - "LOCAL_LOGTAGS_FILES": "logtags", + "LOCAL_SOONG_LOGTAGS_FILES": "logtags", "LOCAL_EXPORT_HEADER_LIBRARY_HEADERS": "export_header_lib_headers", "LOCAL_EXPORT_SHARED_LIBRARY_HEADERS": "export_shared_lib_headers", "LOCAL_EXPORT_STATIC_LIBRARY_HEADERS": "export_static_lib_headers", diff --git a/cc/androidmk.go b/cc/androidmk.go index ef2636625..071d829bf 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -88,7 +88,7 @@ func (c *Module) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { if len(c.Properties.Logtags) > 0 { - entries.AddStrings("LOCAL_LOGTAGS_FILES", c.Properties.Logtags...) + entries.AddStrings("LOCAL_SOONG_LOGTAGS_FILES", c.logtagsPaths.Strings()...) } // Note: Pass the exact value of AndroidMkSystemSharedLibs to the Make // world, even if it is an empty list. In the Make world, diff --git a/cc/cc.go b/cc/cc.go index e3954d7a8..e4f50f959 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -319,7 +319,7 @@ type BaseProperties struct { // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags // file - Logtags []string + Logtags []string `android:"path"` // Make this module available when building for ramdisk. // On device without a dedicated recovery partition, the module is only @@ -908,6 +908,8 @@ type Module struct { // Aconfig files for all transitive deps. Also exposed via TransitiveDeclarationsInfo mergedAconfigFiles map[string]android.Paths + + logtagsPaths android.Paths } func (c *Module) AddJSONData(d *map[string]interface{}) { @@ -1997,6 +1999,11 @@ func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { ctx := moduleContextFromAndroidModuleContext(actx, c) + c.logtagsPaths = android.PathsForModuleSrc(actx, c.Properties.Logtags) + android.SetProvider(ctx, android.LogtagsProviderKey, &android.LogtagsInfo{ + Logtags: c.logtagsPaths, + }) + // If Test_only is set on a module in bp file, respect the setting, otherwise // see if is a known test module type. testOnly := c.testModule || c.testLibrary() diff --git a/java/androidmk.go b/java/androidmk.go index a52d43965..ab5e456a4 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -92,11 +92,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { if len(library.logtagsSrcs) > 0 { - var logtags []string - for _, l := range library.logtagsSrcs { - logtags = append(logtags, l.Rel()) - } - entries.AddStrings("LOCAL_LOGTAGS_FILES", logtags...) + entries.AddStrings("LOCAL_SOONG_LOGTAGS_FILES", library.logtagsSrcs.Strings()...) } if library.installFile == nil { diff --git a/java/gen.go b/java/gen.go index 68a9b53fe..1b4f4c7dc 100644 --- a/java/gen.go +++ b/java/gen.go @@ -27,7 +27,6 @@ import ( func init() { pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py") - pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py") pctx.SourcePathVariable("logtagsLib", "build/make/tools/event_log_tags.py") } @@ -37,12 +36,6 @@ var ( Command: "$logtagsCmd -o $out $in", CommandDeps: []string{"$logtagsCmd", "$logtagsLib"}, }) - - mergeLogtags = pctx.AndroidStaticRule("mergeLogtags", - blueprint.RuleParams{ - Command: "$mergeLogtagsCmd -o $out $in", - CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"}, - }) ) func genAidl(ctx android.ModuleContext, aidlFiles android.Paths, aidlGlobalFlags string, aidlIndividualFlags map[string]string, deps android.Paths) android.Paths { @@ -178,37 +171,9 @@ func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, outSrcFiles = append(outSrcFiles, srcJarFiles...) } + android.SetProvider(ctx, android.LogtagsProviderKey, &android.LogtagsInfo{ + Logtags: j.logtagsSrcs, + }) + return outSrcFiles } - -func LogtagsSingleton() android.Singleton { - return &logtagsSingleton{} -} - -type logtagsProducer interface { - logtags() android.Paths -} - -func (j *Module) logtags() android.Paths { - return j.logtagsSrcs -} - -var _ logtagsProducer = (*Module)(nil) - -type logtagsSingleton struct{} - -func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) { - var allLogtags android.Paths - ctx.VisitAllModules(func(module android.Module) { - if logtags, ok := module.(logtagsProducer); ok { - allLogtags = append(allLogtags, logtags.logtags()...) - } - }) - - ctx.Build(pctx, android.BuildParams{ - Rule: mergeLogtags, - Description: "merge logtags", - Output: android.PathForIntermediates(ctx, "all-event-log-tags.txt"), - Inputs: allLogtags, - }) -} diff --git a/java/java.go b/java/java.go index 725e25abe..30581f265 100644 --- a/java/java.go +++ b/java/java.go @@ -75,7 +75,6 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) { ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel() }) - ctx.RegisterParallelSingletonType("logtags", LogtagsSingleton) ctx.RegisterParallelSingletonType("kythe_java_extract", kytheExtractJavaFactory) }