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

Commit 1fd19230 authored by Jiyong Park's avatar Jiyong Park Committed by Gerrit Code Review
Browse files

Merge changes from topic "apex_available"

* changes:
  shared_lib dependency from a static lib crosses the APEX boundary
  apex_available tracks static dependencies
parents 3beeb1eb d7536ba5
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -180,20 +180,20 @@ func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Module {
	if len(m.apexVariations) > 0 {
		m.checkApexAvailableProperty(mctx)

		sort.Strings(m.apexVariations)
		variations := []string{}
		availableForPlatform := mctx.Module().(ApexModule).AvailableFor(AvailableToPlatform) || mctx.Host()
		if availableForPlatform {
		variations = append(variations, "") // Original variation for platform
		}
		variations = append(variations, m.apexVariations...)

		defaultVariation := ""
		mctx.SetDefaultDependencyVariation(&defaultVariation)

		modules := mctx.CreateVariations(variations...)
		for i, m := range modules {
			if availableForPlatform && i == 0 {
				continue
			platformVariation := i == 0
			if platformVariation && !mctx.Host() && !m.(ApexModule).AvailableFor(AvailableToPlatform) {
				m.SkipInstall()
			}
			m.(ApexModule).setApexName(variations[i])
		}
+794 −51

File changed.

Preview size limit exceeded, changes collapsed.

+28 −10
Original line number Diff line number Diff line
@@ -469,6 +469,11 @@ func TestBasicApex(t *testing.T) {
			sdk_version: "none",
			system_modules: "none",
			compile_dex: true,
			// TODO: remove //apex_available:platform
			apex_available: [
				"//apex_available:platform",
				"myapex",
			],
		}

		java_library {
@@ -760,7 +765,7 @@ func TestApexWithStubs(t *testing.T) {
	ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")

	// Ensure that stubs libs are built without -include flags
	mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
	mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
	ensureNotContains(t, mylib2Cflags, "-include ")

	// Ensure that genstub is invoked with --apex
@@ -886,6 +891,7 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) {
			stubs: {
				versions: ["10", "20", "30"],
			},
			apex_available: [ "myapex" ],
		}

		cc_library {
@@ -1573,6 +1579,7 @@ func TestHeaderLibsDependency(t *testing.T) {
			export_include_dirs: ["my_include"],
			system_shared_libs: [],
			stl: "none",
			apex_available: [ "myapex" ],
		}

		cc_library {
@@ -3026,6 +3033,7 @@ func TestApexWithApps(t *testing.T) {
			srcs: ["mylib.cpp"],
			stl: "none",
			system_shared_libs: [],
			apex_available: [ "myapex" ],
		}
	`)

@@ -3281,10 +3289,15 @@ func TestApexAvailable(t *testing.T) {
	}`)

	// check that libfoo and libbar are created only for myapex, but not for the platform
	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
	ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
	ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
	ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
	// TODO(jiyong) the checks for the platform variant are removed because we now create
	// the platform variant regardless of the apex_availability. Instead, we will make sure that
	// the platform variants are not used from other platform modules. When that is done,
	// these checks will be replaced by expecting a specific error message that will be
	// emitted when the platform variant is used.
	//	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
	//	ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
	//	ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
	//	ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")

	ctx, _ = testApex(t, `
	apex {
@@ -3333,11 +3346,16 @@ func TestApexAvailable(t *testing.T) {
	}`)

	// shared variant of libfoo is only available to myapex
	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
	ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
	// but the static variant is available to both myapex and the platform
	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
	// TODO(jiyong) the checks for the platform variant are removed because we now create
	// the platform variant regardless of the apex_availability. Instead, we will make sure that
	// the platform variants are not used from other platform modules. When that is done,
	// these checks will be replaced by expecting a specific error message that will be
	// emitted when the platform variant is used.
	//	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
	//	ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
	//	// but the static variant is available to both myapex and the platform
	//	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
	//	ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
}

func TestOverrideApex(t *testing.T) {
+15 −4
Original line number Diff line number Diff line
@@ -1780,6 +1780,9 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {

	for _, lib := range deps.SharedLibs {
		depTag := SharedDepTag
		if c.static() {
			depTag = SharedFromStaticDepTag
		}
		if inList(lib, deps.ReexportSharedLibHeaders) {
			depTag = sharedExportDepTag
		}
@@ -2197,7 +2200,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
		depFile := android.OptionalPath{}

		switch depTag {
		case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
		case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
			ptr = &depPaths.SharedLibs
			depPtr = &depPaths.SharedLibsDeps
			depFile = ccDep.Toc()
@@ -2550,10 +2553,18 @@ func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Write

func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
	if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
		if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
		if cc, ok := dep.(*Module); ok {
			if cc.HasStubsVariants() && depTag.Shared && depTag.Library {
				// dynamic dep to a stubs lib crosses APEX boundary
				return false
			}
			if depTag.FromStatic {
				// shared_lib dependency from a static lib is considered as crossing
				// the APEX boundary because the dependency doesn't actually is
				// linked; the dependency is used only during the compilation phase.
				return false
			}
		}
	}
	return true
}
+5 −0
Original line number Diff line number Diff line
@@ -67,12 +67,17 @@ type DependencyTag struct {
	ReexportFlags bool

	ExplicitlyVersioned bool

	FromStatic bool
}

var (
	SharedDepTag = DependencyTag{Name: "shared", Library: true, Shared: true}
	StaticDepTag = DependencyTag{Name: "static", Library: true}

	// Same as SharedDepTag, but from a static lib
	SharedFromStaticDepTag = DependencyTag{Name: "shared from static", Library: true, Shared: true, FromStatic: true}

	CrtBeginDepTag = DependencyTag{Name: "crtbegin"}
	CrtEndDepTag   = DependencyTag{Name: "crtend"}
)
Loading