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

Commit a6182ab2 authored by Colin Cross's avatar Colin Cross
Browse files

Move checkbuild targets of Soong modules into Soong

Pass the name of Soong's checkbuild target for each module to
Make so that it can depend on it from the main checkbuild rule.
This will give better control over which files get built, allowing
checkbuild to skip the jar combining step when transitive classpath
jars are enabled.  The per-module checkbuild targets are passed to
make instead of added directly as a dependency of checkbuild in order
to maintain the existing behavior of only building modules exposed
to make in checkbuild.

Also tweak the existing calls to CheckbuildFile and add
InstallFileWithoutCheckbuild to match the files that are
in the Make-based checkbuild.

Bug: 308016794
Test: m checkbuild
Change-Id: Ic5140819381d58f4d00f23a7a12447950c4cf268
parent c965be6c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -554,6 +554,14 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
		a.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", proptools.Bool(base.commonProperties.No_full_install))
	}

	if info.UncheckedModule {
		a.SetBool("LOCAL_DONT_CHECK_MODULE", true)
	} else if info.CheckbuildTarget != nil {
		a.SetPath("LOCAL_CHECKED_MODULE", info.CheckbuildTarget)
	} else {
		a.SetOptionalPath("LOCAL_CHECKED_MODULE", a.OutputFile)
	}

	if len(info.TestData) > 0 {
		a.AddStrings("LOCAL_TEST_DATA", androidMkDataPaths(info.TestData)...)
	}
+35 −13
Original line number Diff line number Diff line
@@ -1545,26 +1545,43 @@ func (m *ModuleBase) VintfFragmentModuleNames(ctx ConfigAndErrorContext) []strin
	return m.base().commonProperties.Vintf_fragment_modules.GetOrDefault(m.ConfigurableEvaluator(ctx), nil)
}

func (m *ModuleBase) generateVariantTarget(ctx *moduleContext) {
	namespacePrefix := ctx.Namespace().id
	if namespacePrefix != "" {
		namespacePrefix = namespacePrefix + "-"
	}

	if !ctx.uncheckedModule {
		name := namespacePrefix + ctx.ModuleName() + "-" + ctx.ModuleSubDir() + "-checkbuild"
		ctx.Phony(name, ctx.checkbuildFiles...)
		ctx.checkbuildTarget = PathForPhony(ctx, name)
	}

}

func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) {
	var allInstalledFiles InstallPaths
	var allCheckbuildFiles Paths
	var allCheckbuildTargets Paths
	ctx.VisitAllModuleVariants(func(module Module) {
		a := module.base()
		var checkBuilds Paths
		var checkbuildTarget Path
		var uncheckedModule bool
		if a == m {
			allInstalledFiles = append(allInstalledFiles, ctx.installFiles...)
			checkBuilds = ctx.checkbuildFiles
			checkbuildTarget = ctx.checkbuildTarget
			uncheckedModule = ctx.uncheckedModule
		} else {
			info := OtherModuleProviderOrDefault(ctx, module, InstallFilesProvider)
			allInstalledFiles = append(allInstalledFiles, info.InstallFiles...)
			checkBuilds = info.CheckbuildFiles
			checkbuildTarget = info.CheckbuildTarget
			uncheckedModule = info.UncheckedModule
		}
		// A module's -checkbuild phony targets should
		// not be created if the module is not exported to make.
		// Those could depend on the build target and fail to compile
		// for the current build target.
		if !ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(ctx, a) {
			allCheckbuildFiles = append(allCheckbuildFiles, checkBuilds...)
		if (!ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(ctx, a)) && !uncheckedModule && checkbuildTarget != nil {
			allCheckbuildTargets = append(allCheckbuildTargets, checkbuildTarget)
		}
	})

@@ -1585,11 +1602,10 @@ func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) {
		deps = append(deps, info.InstallTarget)
	}

	if len(allCheckbuildFiles) > 0 {
	if len(allCheckbuildTargets) > 0 {
		name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
		ctx.Phony(name, allCheckbuildFiles...)
		info.CheckbuildTarget = PathForPhony(ctx, name)
		deps = append(deps, info.CheckbuildTarget)
		ctx.Phony(name, allCheckbuildTargets...)
		deps = append(deps, PathForPhony(ctx, name))
	}

	if len(deps) > 0 {
@@ -1708,6 +1724,8 @@ func (m *ModuleBase) archModuleContextFactory(ctx archModuleContextFactoryContex
type InstallFilesInfo struct {
	InstallFiles     InstallPaths
	CheckbuildFiles  Paths
	CheckbuildTarget Path
	UncheckedModule  bool
	PackagingSpecs   []PackagingSpec
	// katiInstalls tracks the install rules that were created by Soong but are being exported
	// to Make to convert to ninja rules so that Make can add additional dependencies.
@@ -1945,9 +1963,13 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
			return
		}

		m.generateVariantTarget(ctx)

		installFiles.LicenseMetadataFile = ctx.licenseMetadataFile
		installFiles.InstallFiles = ctx.installFiles
		installFiles.CheckbuildFiles = ctx.checkbuildFiles
		installFiles.CheckbuildTarget = ctx.checkbuildTarget
		installFiles.UncheckedModule = ctx.uncheckedModule
		installFiles.PackagingSpecs = ctx.packagingSpecs
		installFiles.KatiInstalls = ctx.katiInstalls
		installFiles.KatiSymlinks = ctx.katiSymlinks
+40 −15
Original line number Diff line number Diff line
@@ -122,6 +122,16 @@ type ModuleContext interface {
	// dependency tags for which IsInstallDepNeeded returns true.
	InstallFile(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath

	// InstallFileWithoutCheckbuild creates a rule to copy srcPath to name in the installPath directory,
	// with the given additional dependencies, but does not add the file to the list of files to build
	// during `m checkbuild`.
	//
	// The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
	// installed file will be returned by PackagingSpecs() on this module or by
	// TransitivePackagingSpecs() on modules that depend on this module through dependency tags
	// for which IsInstallDepNeeded returns true.
	InstallFileWithoutCheckbuild(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath

	// InstallFileWithExtraFilesZip creates a rule to copy srcPath to name in the installPath
	// directory, and also unzip a zip file containing extra files to install into the same
	// directory.
@@ -168,7 +178,8 @@ type ModuleContext interface {
	// dependency tags for which IsInstallDepNeeded returns true.
	PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec

	CheckbuildFile(srcPath Path)
	CheckbuildFile(srcPaths ...Path)
	UncheckedModule()

	InstallInData() bool
	InstallInTestcases() bool
@@ -240,6 +251,8 @@ type moduleContext struct {
	packagingSpecs   []PackagingSpec
	installFiles     InstallPaths
	checkbuildFiles  Paths
	checkbuildTarget Path
	uncheckedModule  bool
	module           Module
	phonies          map[string]Paths
	// outputFiles stores the output of a module by tag and is used to set
@@ -512,17 +525,22 @@ func (m *moduleContext) requiresFullInstall() bool {

func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
	deps ...InstallPath) InstallPath {
	return m.installFile(installPath, name, srcPath, deps, false, true, nil)
	return m.installFile(installPath, name, srcPath, deps, false, true, true, nil)
}

func (m *moduleContext) InstallFileWithoutCheckbuild(installPath InstallPath, name string, srcPath Path,
	deps ...InstallPath) InstallPath {
	return m.installFile(installPath, name, srcPath, deps, false, true, false, nil)
}

func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
	deps ...InstallPath) InstallPath {
	return m.installFile(installPath, name, srcPath, deps, true, true, nil)
	return m.installFile(installPath, name, srcPath, deps, true, true, true, nil)
}

func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path,
	extraZip Path, deps ...InstallPath) InstallPath {
	return m.installFile(installPath, name, srcPath, deps, false, true, &extraFilesZip{
	return m.installFile(installPath, name, srcPath, deps, false, true, true, &extraFilesZip{
		zip: extraZip,
		dir: installPath,
	})
@@ -559,7 +577,7 @@ func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, e
}

func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []InstallPath,
	executable bool, hooks bool, extraZip *extraFilesZip) InstallPath {
	executable bool, hooks bool, checkbuild bool, extraZip *extraFilesZip) InstallPath {

	fullInstallPath := installPath.Join(m, name)
	if hooks {
@@ -626,7 +644,9 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat

	m.packageFile(fullInstallPath, srcPath, executable)

	if checkbuild {
		m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
	}

	return fullInstallPath
}
@@ -667,7 +687,6 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
		}

		m.installFiles = append(m.installFiles, fullInstallPath)
		m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
	}

	m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
@@ -734,15 +753,21 @@ func (m *moduleContext) InstallTestData(installPath InstallPath, data []DataPath
	ret := make(InstallPaths, 0, len(data))
	for _, d := range data {
		relPath := d.ToRelativeInstallPath()
		installed := m.installFile(installPath, relPath, d.SrcPath, nil, false, false, nil)
		installed := m.installFile(installPath, relPath, d.SrcPath, nil, false, false, true, nil)
		ret = append(ret, installed)
	}

	return ret
}

func (m *moduleContext) CheckbuildFile(srcPath Path) {
	m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
// CheckbuildFile specifies the output files that should be built by checkbuild.
func (m *moduleContext) CheckbuildFile(srcPaths ...Path) {
	m.checkbuildFiles = append(m.checkbuildFiles, srcPaths...)
}

// UncheckedModule marks the current module has having no files that should be built by checkbuild.
func (m *moduleContext) UncheckedModule() {
	m.uncheckedModule = true
}

func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
+5 −0
Original line number Diff line number Diff line
@@ -136,6 +136,11 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, moduleDir st
		fmt.Fprintln(w, "LOCAL_SOONG_INSTALLED_MODULE :=", filepath.Join(modulePath, fi.stem()))
		fmt.Fprintln(w, "LOCAL_SOONG_INSTALL_PAIRS :=", fi.builtFile.String()+":"+filepath.Join(modulePath, fi.stem()))
		fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
		if fi.checkbuildTarget != nil {
			fmt.Fprintln(w, "LOCAL_CHECKED_MODULE :=", fi.checkbuildTarget.String())
		} else {
			fmt.Fprintln(w, "LOCAL_CHECKED_MODULE :=", fi.builtFile.String())
		}
		fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.nameInMake())
		if fi.module != nil {
			// This apexFile's module comes from Soong
+5 −0
Original line number Diff line number Diff line
@@ -577,6 +577,8 @@ type apexFile struct {
	customStem string
	symlinks   []string // additional symlinks

	checkbuildTarget android.Path

	// Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
	// module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
	// suffix>]
@@ -612,6 +614,9 @@ func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidM
		module:              module,
	}
	if module != nil {
		if installFilesInfo, ok := android.OtherModuleProvider(ctx, module, android.InstallFilesProvider); ok {
			ret.checkbuildTarget = installFilesInfo.CheckbuildTarget
		}
		ret.moduleDir = ctx.OtherModuleDir(module)
		ret.partition = module.PartitionTag(ctx.DeviceConfig())
		ret.requiredModuleNames = module.RequiredModuleNames(ctx)
Loading