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

Commit 83843ab4 authored by Yu Liu's avatar Yu Liu Committed by Automerger Merge Worker
Browse files

Convert CmakeSnapshot to use ModuleProxy. am: 323d77ad am: 4de532d3

parents 83eac45b 4de532d3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ func (e *earlyModuleContext) Namespace() *Namespace {
}

func (e *earlyModuleContext) OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) {
	e.EarlyModuleContext.OtherModulePropertyErrorf(module, property, fmt, args...)
	e.EarlyModuleContext.OtherModulePropertyErrorf(getWrappedModule(module), property, fmt, args...)
}

func (e *earlyModuleContext) HasMutatorFinished(mutatorName string) bool {
+96 −4
Original line number Diff line number Diff line
@@ -53,9 +53,58 @@ type CcObjectInfo struct {

var CcObjectInfoProvider = blueprint.NewProvider[CcObjectInfo]()

type AidlInterfaceInfo struct {
	// list of aidl_interface sources
	Sources []string
	// root directory of AIDL sources
	AidlRoot string
	// AIDL backend language (e.g. "cpp", "ndk")
	Lang string
	// list of flags passed to AIDL generator
	Flags []string
}

type CompilerInfo struct {
	Srcs android.Paths
	// list of module-specific flags that will be used for C and C++ compiles.
	Cflags               proptools.Configurable[[]string]
	AidlInterfaceInfo    AidlInterfaceInfo
	LibraryDecoratorInfo *LibraryDecoratorInfo
}

type LinkerInfo struct {
	Whole_static_libs proptools.Configurable[[]string]
	// list of modules that should be statically linked into this module.
	Static_libs proptools.Configurable[[]string]
	// list of modules that should be dynamically linked into this module.
	Shared_libs proptools.Configurable[[]string]
	// list of modules that should only provide headers for this module.
	Header_libs proptools.Configurable[[]string]

	BinaryDecoratorInfo    *BinaryDecoratorInfo
	LibraryDecoratorInfo   *LibraryDecoratorInfo
	TestBinaryInfo         *TestBinaryInfo
	BenchmarkDecoratorInfo *BenchmarkDecoratorInfo
	ObjectLinkerInfo       *ObjectLinkerInfo
}

type BinaryDecoratorInfo struct{}
type LibraryDecoratorInfo struct {
	Export_include_dirs proptools.Configurable[[]string]
}
type TestBinaryInfo struct {
	Gtest bool
}
type BenchmarkDecoratorInfo struct{}
type ObjectLinkerInfo struct{}

// Common info about the cc module.
type CcInfo struct {
	HasStubsVariants       bool
	IsPrebuilt             bool
	CmakeSnapshotSupported bool
	CompilerInfo           *CompilerInfo
	LinkerInfo             *LinkerInfo
}

var CcInfoProvider = blueprint.NewProvider[CcInfo]()
@@ -2131,9 +2180,52 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
		StaticExecutable: c.StaticExecutable(),
	})

	android.SetProvider(ctx, CcInfoProvider, CcInfo{
	ccInfo := CcInfo{
		HasStubsVariants:       c.HasStubsVariants(),
	})
		IsPrebuilt:             c.IsPrebuilt(),
		CmakeSnapshotSupported: proptools.Bool(c.Properties.Cmake_snapshot_supported),
	}
	if c.compiler != nil {
		ccInfo.CompilerInfo = &CompilerInfo{
			Srcs:   c.compiler.(CompiledInterface).Srcs(),
			Cflags: c.compiler.baseCompilerProps().Cflags,
			AidlInterfaceInfo: AidlInterfaceInfo{
				Sources:  c.compiler.baseCompilerProps().AidlInterface.Sources,
				AidlRoot: c.compiler.baseCompilerProps().AidlInterface.AidlRoot,
				Lang:     c.compiler.baseCompilerProps().AidlInterface.Lang,
				Flags:    c.compiler.baseCompilerProps().AidlInterface.Flags,
			},
		}
		switch decorator := c.compiler.(type) {
		case *libraryDecorator:
			ccInfo.CompilerInfo.LibraryDecoratorInfo = &LibraryDecoratorInfo{
				Export_include_dirs: decorator.flagExporter.Properties.Export_include_dirs,
			}
		}
	}
	if c.linker != nil {
		ccInfo.LinkerInfo = &LinkerInfo{
			Whole_static_libs: c.linker.baseLinkerProps().Whole_static_libs,
			Static_libs:       c.linker.baseLinkerProps().Static_libs,
			Shared_libs:       c.linker.baseLinkerProps().Shared_libs,
			Header_libs:       c.linker.baseLinkerProps().Header_libs,
		}
		switch decorator := c.linker.(type) {
		case *binaryDecorator:
			ccInfo.LinkerInfo.BinaryDecoratorInfo = &BinaryDecoratorInfo{}
		case *libraryDecorator:
			ccInfo.LinkerInfo.LibraryDecoratorInfo = &LibraryDecoratorInfo{}
		case *testBinary:
			ccInfo.LinkerInfo.TestBinaryInfo = &TestBinaryInfo{
				Gtest: decorator.testDecorator.gtest(),
			}
		case *benchmarkDecorator:
			ccInfo.LinkerInfo.BenchmarkDecoratorInfo = &BenchmarkDecoratorInfo{}
		case *objectLinker:
			ccInfo.LinkerInfo.ObjectLinkerInfo = &ObjectLinkerInfo{}
		}
	}
	android.SetProvider(ctx, CcInfoProvider, ccInfo)

	c.setOutputFiles(ctx)

+4 −4
Original line number Diff line number Diff line
# <<.M.Name>>

<<setList .M.Name "_SRCS" "" (getAidlSources .M)>>
<<setList .M.Name "_SRCS" "" (getAidlSources .CcInfo)>>

<<setList .M.Name "_AIDLFLAGS" "" (getCompilerProperties .M).AidlInterface.Flags>>
<<setList .M.Name "_AIDLFLAGS" "" (getAidlInterface .CcInfo).Flags>>

add_aidl_library(<<.M.Name>> <<(getCompilerProperties .M).AidlInterface.Lang>>
    "${ANDROID_BUILD_TOP}/<<.Ctx.OtherModuleDir .M>>/<<(getCompilerProperties .M).AidlInterface.AidlRoot>>"
add_aidl_library(<<.M.Name>> <<(getAidlInterface .CcInfo).Lang>>
    "${ANDROID_BUILD_TOP}/<<.Ctx.OtherModuleDir .M>>/<<(getAidlInterface .CcInfo).AidlRoot>>"
    "${<<.M.Name>>_SRCS}"
    "${<<.M.Name>>_AIDLFLAGS}")
add_library(android::<<.M.Name>> ALIAS <<.M.Name>>)
+9 −9
Original line number Diff line number Diff line
<<$srcs := getSources .M>>
<<$includeDirs := getIncludeDirs .Ctx .M>>
<<$cflags := getCflagsProperty .Ctx .M>>
<<$srcs := getSources .Ctx .CcInfo>>
<<$includeDirs := getIncludeDirs .Ctx .M .CcInfo>>
<<$cflags := getCflagsProperty .Ctx .CcInfo>>
<<$deps := mapLibraries .Ctx .M (concat5
(getWholeStaticLibsProperty .Ctx .M)
(getStaticLibsProperty .Ctx .M)
(getSharedLibsProperty .Ctx .M)
(getHeaderLibsProperty .Ctx .M)
(getExtraLibs .M)
(getWholeStaticLibsProperty .Ctx .CcInfo)
(getStaticLibsProperty .Ctx .CcInfo)
(getSharedLibsProperty .Ctx .CcInfo)
(getHeaderLibsProperty .Ctx .CcInfo)
(getExtraLibs .CcInfo)
) .Pprop.LibraryMapping>>
<<$moduleType := getModuleType .M>>
<<$moduleType := getModuleType .CcInfo>>
<<$moduleTypeCmake := "executable">>
<<if eq $moduleType "library">>
<<$moduleTypeCmake = "library">>
+43 −49
Original line number Diff line number Diff line
@@ -196,39 +196,36 @@ func parseTemplate(templateContents string) *template.Template {

			return list.String()
		},
		"getSources": func(m *Module) android.Paths {
			return m.compiler.(CompiledInterface).Srcs()
		"getSources": func(ctx android.ModuleContext, info *CcInfo) android.Paths {
			return info.CompilerInfo.Srcs
		},
		"getModuleType": getModuleType,
		"getCompilerProperties": func(m *Module) BaseCompilerProperties {
			return m.compiler.baseCompilerProps()
		"getAidlInterface": func(info *CcInfo) AidlInterfaceInfo {
			return info.CompilerInfo.AidlInterfaceInfo
		},
		"getCflagsProperty": func(ctx android.ModuleContext, m *Module) []string {
			prop := m.compiler.baseCompilerProps().Cflags
		"getCflagsProperty": func(ctx android.ModuleContext, info *CcInfo) []string {
			prop := info.CompilerInfo.Cflags
			return prop.GetOrDefault(ctx, nil)
		},
		"getLinkerProperties": func(m *Module) BaseLinkerProperties {
			return m.linker.baseLinkerProps()
		},
		"getWholeStaticLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
			prop := m.linker.baseLinkerProps().Whole_static_libs
		"getWholeStaticLibsProperty": func(ctx android.ModuleContext, info *CcInfo) []string {
			prop := info.LinkerInfo.Whole_static_libs
			return prop.GetOrDefault(ctx, nil)
		},
		"getStaticLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
			prop := m.linker.baseLinkerProps().Static_libs
		"getStaticLibsProperty": func(ctx android.ModuleContext, info *CcInfo) []string {
			prop := info.LinkerInfo.Static_libs
			return prop.GetOrDefault(ctx, nil)
		},
		"getSharedLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
			prop := m.linker.baseLinkerProps().Shared_libs
		"getSharedLibsProperty": func(ctx android.ModuleContext, info *CcInfo) []string {
			prop := info.LinkerInfo.Shared_libs
			return prop.GetOrDefault(ctx, nil)
		},
		"getHeaderLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
			prop := m.linker.baseLinkerProps().Header_libs
		"getHeaderLibsProperty": func(ctx android.ModuleContext, info *CcInfo) []string {
			prop := info.LinkerInfo.Header_libs
			return prop.GetOrDefault(ctx, nil)
		},
		"getExtraLibs":   getExtraLibs,
		"getIncludeDirs": getIncludeDirs,
		"mapLibraries": func(ctx android.ModuleContext, m *Module, libs []string, mapping map[string]LibraryMappingProperty) []string {
		"mapLibraries": func(ctx android.ModuleContext, m android.ModuleProxy, libs []string, mapping map[string]LibraryMappingProperty) []string {
			var mappedLibs []string
			for _, lib := range libs {
				mappedLib, exists := mapping[lib]
@@ -249,8 +246,8 @@ func parseTemplate(templateContents string) *template.Template {
			mappedLibs = slices.Compact(mappedLibs)
			return mappedLibs
		},
		"getAidlSources": func(m *Module) []string {
			aidlInterface := m.compiler.baseCompilerProps().AidlInterface
		"getAidlSources": func(info *CcInfo) []string {
			aidlInterface := info.CompilerInfo.AidlInterfaceInfo
			aidlRoot := aidlInterface.AidlRoot + string(filepath.Separator)
			if aidlInterface.AidlRoot == "" {
				aidlRoot = ""
@@ -340,14 +337,14 @@ func (m *CmakeSnapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	moduleDirs := map[string][]string{}
	sourceFiles := map[string]android.Path{}
	visitedModules := map[string]bool{}
	var pregeneratedModules []*Module
	ctx.WalkDeps(func(dep_a android.Module, parent android.Module) bool {
		moduleName := ctx.OtherModuleName(dep_a)
	var pregeneratedModules []android.ModuleProxy
	ctx.WalkDepsProxy(func(dep, parent android.ModuleProxy) bool {
		moduleName := ctx.OtherModuleName(dep)
		if visited := visitedModules[moduleName]; visited {
			return false // visit only once
		}
		visitedModules[moduleName] = true
		dep, ok := dep_a.(*Module)
		ccInfo, ok := android.OtherModuleProvider(ctx, dep, CcInfoProvider)
		if !ok {
			return false // not a cc module
		}
@@ -363,15 +360,15 @@ func (m *CmakeSnapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		if slices.Contains(ignoredSystemLibs, moduleName) {
			return false // system libs built in-tree for Android
		}
		if dep.IsPrebuilt() {
		if ccInfo.IsPrebuilt {
			return false // prebuilts are not supported
		}
		if dep.compiler == nil {
		if ccInfo.CompilerInfo == nil {
			return false // unsupported module type
		}
		isAidlModule := dep.compiler.baseCompilerProps().AidlInterface.Lang != ""
		isAidlModule := ccInfo.CompilerInfo.AidlInterfaceInfo.Lang != ""

		if !proptools.Bool(dep.Properties.Cmake_snapshot_supported) {
		if !ccInfo.CmakeSnapshotSupported {
			ctx.OtherModulePropertyErrorf(dep, "cmake_snapshot_supported",
				"CMake snapshots not supported, despite being a dependency for %s",
				ctx.OtherModuleName(parent))
@@ -389,12 +386,14 @@ func (m *CmakeSnapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		}
		moduleFragment := executeTemplate(templateToUse, &templateBuffer, struct {
			Ctx      *android.ModuleContext
			M        *Module
			M        android.ModuleProxy
			CcInfo   *CcInfo
			Snapshot *CmakeSnapshot
			Pprop    *cmakeProcessedProperties
		}{
			&ctx,
			dep,
			&ccInfo,
			m,
			&pprop,
		})
@@ -415,7 +414,7 @@ func (m *CmakeSnapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	// Enumerate sources for pregenerated modules
	if m.Properties.Include_sources {
		for _, dep := range pregeneratedModules {
			if !proptools.Bool(dep.Properties.Cmake_snapshot_supported) {
			if !android.OtherModuleProviderOrDefault(ctx, dep, CcInfoProvider).CmakeSnapshotSupported {
				ctx.OtherModulePropertyErrorf(dep, "cmake_snapshot_supported",
					"Pregenerated CMake snapshots not supported, despite being requested for %s",
					ctx.ModuleName())
@@ -491,7 +490,7 @@ func (m *CmakeSnapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	if len(m.Properties.Prebuilts) > 0 {
		var prebuiltsList android.Paths

		ctx.VisitDirectDepsWithTag(cmakeSnapshotPrebuiltTag, func(dep android.Module) {
		ctx.VisitDirectDepsProxyWithTag(cmakeSnapshotPrebuiltTag, func(dep android.ModuleProxy) {
			for _, file := range android.OtherModuleProviderOrDefault(
				ctx, dep, android.InstallFilesProvider).InstallFiles {
				prebuiltsList = append(prebuiltsList, file)
@@ -523,42 +522,37 @@ func (m *CmakeSnapshot) AndroidMkEntries() []android.AndroidMkEntries {
	}}
}

func getModuleType(m *Module) string {
	switch m.linker.(type) {
	case *binaryDecorator:
func getModuleType(info *CcInfo) string {
	if info.LinkerInfo.BinaryDecoratorInfo != nil {
		return "executable"
	case *libraryDecorator:
	} else if info.LinkerInfo.LibraryDecoratorInfo != nil {
		return "library"
	case *testBinary:
		return "test"
	case *benchmarkDecorator:
	} else if info.LinkerInfo.TestBinaryInfo != nil || info.LinkerInfo.BenchmarkDecoratorInfo != nil {
		return "test"
	case *objectLinker:
	} else if info.LinkerInfo.ObjectLinkerInfo != nil {
		return "object"
	}
	panic(fmt.Sprintf("Unexpected module type: %T", m.linker))
	panic(fmt.Sprintf("Unexpected module type for LinkerInfo"))
}

func getExtraLibs(m *Module) []string {
	switch decorator := m.linker.(type) {
	case *testBinary:
		if decorator.testDecorator.gtest() {
func getExtraLibs(info *CcInfo) []string {
	if info.LinkerInfo.TestBinaryInfo != nil {
		if info.LinkerInfo.TestBinaryInfo.Gtest {
			return []string{
				"libgtest",
				"libgtest_main",
			}
		}
	case *benchmarkDecorator:
	} else if info.LinkerInfo.BenchmarkDecoratorInfo != nil {
		return []string{"libgoogle-benchmark"}
	}
	return nil
}

func getIncludeDirs(ctx android.ModuleContext, m *Module) []string {
func getIncludeDirs(ctx android.ModuleContext, m android.ModuleProxy, info *CcInfo) []string {
	moduleDir := ctx.OtherModuleDir(m) + string(filepath.Separator)
	switch decorator := m.compiler.(type) {
	case *libraryDecorator:
		return sliceWithPrefix(moduleDir, decorator.flagExporter.Properties.Export_include_dirs.GetOrDefault(ctx, nil))
	if info.CompilerInfo.LibraryDecoratorInfo != nil {
		return sliceWithPrefix(moduleDir, info.CompilerInfo.LibraryDecoratorInfo.Export_include_dirs.GetOrDefault(ctx, nil))
	}
	return nil
}