Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e48cc3c authored by Cole Faust's avatar Cole Faust Committed by Gerrit Code Review
Browse files

Merge "Make soong's event-log-tags file match make" into main

parents 4cfb2ec1 e4506afe
Loading
Loading
Loading
Loading
+47 −1
Original line number Diff line number Diff line
@@ -14,10 +14,56 @@

package android

import "github.com/google/blueprint"
import (
	"strings"

	"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 := OtherModuleProvider(ctx, module, LogtagsProviderKey); ok {
			allLogtags = append(allLogtags, logtagsInfo.Logtags...)
		}
	})
	allLogtags = SortedUniquePaths(allLogtags)
	filteredLogTags := make([]Path, 0, len(allLogtags))
	for _, p := range allLogtags {
		// Logic copied from make:
		// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=987;drc=0585bb1bcf4c89065adaf709f48acc8b869fd3ce
		if !strings.HasPrefix(p.String(), "vendor/") && !strings.HasPrefix(p.String(), "device/") && !strings.HasPrefix(p.String(), "out/") {
			filteredLogTags = append(filteredLogTags, p)
		}
	}

	builder := NewRuleBuilder(pctx, ctx)
	builder.Command().
		BuiltTool("merge-event-log-tags").
		FlagWithOutput("-o ", MergedLogtagsPath(ctx)).
		Inputs(filteredLogTags)
	builder.Build("all-event-log-tags.txt", "merge logtags")
}
+1 −20
Original line number Diff line number Diff line
@@ -872,29 +872,10 @@ func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *a
		return
	}

	logtagsFilePaths := make(map[string]bool)
	ctx.WalkDeps(func(child, parent android.Module) bool {
		if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok {
			for _, path := range logtagsInfo.Logtags {
				logtagsFilePaths[path.String()] = true
			}
		}
		return true
	})

	if len(logtagsFilePaths) == 0 {
		return
	}

	etcPath := rebasedDir.Join(ctx, "etc")
	eventLogtagsPath := etcPath.Join(ctx, "event-log-tags")
	builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String())
	cmd := builder.Command().BuiltTool("merge-event-log-tags").
		FlagWithArg("-o ", eventLogtagsPath.String())

	for _, path := range android.SortedKeys(logtagsFilePaths) {
		cmd.Text(path)
	}
	builder.Command().Text("cp").Input(android.MergedLogtagsPath(ctx)).Text(eventLogtagsPath.String())

	f.appendToEntry(ctx, eventLogtagsPath)
}