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

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

use version mutator for CRT

Move the CRT objects into the version mutator and retire the
ndk_api mutator.

Test: no change to build.ninja or Android-${TARGET_PRODUCT}.mk
Change-Id: Ibbbde323e3e0e8e4702dda4f3828a49786280118
parent 5ec407b5
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
		ctx.BottomUp("sdk", sdkMutator).Parallel()
		ctx.BottomUp("vndk", VndkMutator).Parallel()
		ctx.BottomUp("link", LinkageMutator).Parallel()
		ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
		ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
		ctx.BottomUp("version_selector", versionSelectorMutator).Parallel()
		ctx.BottomUp("version", versionMutator).Parallel()
@@ -1688,7 +1687,7 @@ func GetCrtVariations(ctx android.BottomUpMutatorContext,
	if m.UseSdk() {
		return []blueprint.Variation{
			{Mutator: "sdk", Variation: "sdk"},
			{Mutator: "ndk_api", Variation: m.SdkVersion()},
			{Mutator: "version", Variation: m.SdkVersion()},
		}
	}
	return []blueprint.Variation{
@@ -1954,11 +1953,10 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
		actx.AddDependency(c, depTag, gen)
	}

	actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)

	vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())

	crtVariations := GetCrtVariations(ctx, c)
	actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
	if deps.CrtBegin != "" {
		actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
			rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
+42 −1
Original line number Diff line number Diff line
@@ -1611,6 +1611,21 @@ func createVersionVariations(mctx android.BottomUpMutatorContext, versions []str
	mctx.CreateAliasVariation("latest", latestVersion)
}

func createPerApiVersionVariations(mctx android.BottomUpMutatorContext, minSdkVersion string) {
	from, err := nativeApiLevelFromUser(mctx, minSdkVersion)
	if err != nil {
		mctx.PropertyErrorf("min_sdk_version", err.Error())
		return
	}

	versionStrs := ndkLibraryVersions(mctx, from)
	modules := mctx.CreateLocalVariations(versionStrs...)

	for i, module := range modules {
		module.(*Module).Properties.Sdk_version = StringPtr(versionStrs[i])
	}
}

func CanBeOrLinkAgainstVersionVariants(module interface {
	Host() bool
	InRamdisk() bool
@@ -1646,6 +1661,23 @@ func versionSelectorMutator(mctx android.BottomUpMutatorContext) {
				}
				return
			}

			if compiler, ok := c.linker.(*stubDecorator); ok {
				if mctx.Os() != android.Android {
					// These modules are always android.DeviceEnabled only, but
					// those include Fuchsia devices, which we don't support.
					mctx.Module().Disable()
					return
				}
				firstVersion, err := nativeApiLevelFromUser(mctx,
					String(compiler.properties.First_version))
				if err != nil {
					mctx.PropertyErrorf("first_version", err.Error())
					return
				}
				c.SetAllStubsVersions(ndkLibraryVersions(mctx, firstVersion))
				return
			}
		}

		if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 && !library.UseSdk() {
@@ -1659,7 +1691,6 @@ func versionSelectorMutator(mctx android.BottomUpMutatorContext) {
			library.SetAllStubsVersions(versions)
			return
		}

	}
}

@@ -1668,6 +1699,16 @@ func versionSelectorMutator(mctx android.BottomUpMutatorContext) {
func versionMutator(mctx android.BottomUpMutatorContext) {
	if library, ok := mctx.Module().(LinkableInterface); ok && CanBeVersionVariant(library) {
		createVersionVariations(mctx, library.AllStubsVersions())
		return
	}

	if m, ok := mctx.Module().(*Module); ok {
		if m.SplitPerApiLevel() && m.IsSdkVariant() {
			if mctx.Os() != android.Android {
				return
			}
			createPerApiVersionVariations(mctx, m.MinSdkVersion())
		}
	}
}

+0 −47
Original line number Diff line number Diff line
@@ -118,53 +118,6 @@ func ndkLibraryVersions(ctx android.BottomUpMutatorContext, from android.ApiLeve
	return versionStrs
}

func generatePerApiVariants(ctx android.BottomUpMutatorContext,
	from android.ApiLevel, perSplit func(*Module, android.ApiLevel)) {

	versionStrs := ndkLibraryVersions(ctx, from)
	modules := ctx.CreateVariations(versionStrs...)

	for i, module := range modules {
		perSplit(module.(*Module), android.ApiLevelOrPanic(ctx, versionStrs[i]))

	}
}

func NdkApiMutator(ctx android.BottomUpMutatorContext) {
	if m, ok := ctx.Module().(*Module); ok {
		if m.Enabled() {
			if compiler, ok := m.compiler.(*stubDecorator); ok {
				if ctx.Os() != android.Android {
					// These modules are always android.DeviceEnabled only, but
					// those include Fuchsia devices, which we don't support.
					ctx.Module().Disable()
					return
				}
				firstVersion, err := nativeApiLevelFromUser(ctx,
					String(compiler.properties.First_version))
				if err != nil {
					ctx.PropertyErrorf("first_version", err.Error())
					return
				}
				m.SetAllStubsVersions(ndkLibraryVersions(ctx, firstVersion))
			} else if m.SplitPerApiLevel() && m.IsSdkVariant() {
				if ctx.Os() != android.Android {
					return
				}
				from, err := nativeApiLevelFromUser(ctx, m.MinSdkVersion())
				if err != nil {
					ctx.PropertyErrorf("min_sdk_version", err.Error())
					return
				}
				generatePerApiVariants(ctx, from,
					func(m *Module, version android.ApiLevel) {
						m.Properties.Sdk_version = StringPtr(version.String())
					})
			}
		}
	}
}

func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool {
	this.apiLevel = nativeApiLevelOrPanic(ctx, this.stubsVersion())