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

Commit af60f411 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Revert "Flag to control if generated SDK prebuilts are preferred.""

parents a56be7d7 7e9ddbe8
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -93,10 +93,6 @@ type sdkProperties struct {
	//   dropped. Adding a rule to members that have //visibility:private will
	//   cause the //visibility:private to be discarded.
	Prebuilt_visibility []string

	// Specifying whether the generated prebuilt SDK build rule should have the
	// prefer flag set or not.
	Prebuilts_prefer *bool // default: false
}

// Contains information about the sdk properties that list sdk members, e.g.
@@ -296,10 +292,6 @@ func (s *sdk) snapshot() bool {
	return s.properties.Snapshot
}

func (s *sdk) PreferPrebuilts() bool {
	return proptools.BoolDefault(s.properties.Prebuilts_prefer, false)
}

func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	if s.snapshot() {
		// We don't need to create a snapshot out of sdk_snapshot.
+0 −65
Original line number Diff line number Diff line
@@ -662,68 +662,3 @@ sdk_snapshot {
		)
	})
}

// Ensure that sdk prebuilt_prefer works correctly.
func TestSnapshot_PrebuiltPreferTrue(t *testing.T) {
	bp := `
		sdk {
			name: "mysdk",
			java_header_libs: ["myjavalib"],
			prebuilts_prefer: true,
		}

		java_library {
			name: "myjavalib",
			srcs: ["Test.java"],
			system_modules: "none",
			sdk_version: "none",
			compile_dex: true,
			host_supported: true,
		}
	`
	preparer := android.GroupFixturePreparers(
		prepareForSdkTestWithJava,
		android.FixtureWithRootAndroidBp(bp),
	)

	checkZipFile := func(t *testing.T, result *android.TestResult, expected string) {
		zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles")
		android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String())
	}

	t.Run("prefer=true", func(t *testing.T) {
		result := android.GroupFixturePreparers(
			preparer,
		).RunTest(t)

		checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")

		CheckSnapshot(t, result, "mysdk", "",
			checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.

java_import {
    name: "mysdk_myjavalib@current",
    sdk_member_name: "myjavalib",
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    jars: ["java/myjavalib.jar"],
}

java_import {
    name: "myjavalib",
    prefer: true,
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    jars: ["java/myjavalib.jar"],
}

sdk_snapshot {
    name: "mysdk@current",
    visibility: ["//visibility:public"],
    java_header_libs: ["mysdk_myjavalib@current"],
}
			`),
		)
	})
}
+5 −6
Original line number Diff line number Diff line
@@ -32,9 +32,8 @@ import (
// ========================================================
//
// SOONG_SDK_SNAPSHOT_PREFER
//     By default every unversioned module in the generated snapshot has prefer set by the
//     sdk.prebuilts_prefer property. Building it with SOONG_SDK_SNAPSHOT_PREFER=true will force
//     them to use prefer: true.
//     By default every unversioned module in the generated snapshot has prefer: false. Building it
//     with SOONG_SDK_SNAPSHOT_PREFER=true will force them to use prefer: true.
//
// SOONG_SDK_SNAPSHOT_VERSION
//     This provides control over the version of the generated snapshot.
@@ -1624,11 +1623,11 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu

	// Do not add the prefer property if the member snapshot module is a source module type.
	if !memberType.UsesSourceModuleTypeInSnapshot() {
		// Set the prefer based on the environment variable if present, else the sdk.prefer_prebuilts
		// value.
		// Set the prefer based on the environment variable. This is a temporary work around to allow a
		// snapshot to be created that sets prefer: true.
		// TODO(b/174997203): Remove once the ability to select the modules to prefer can be done
		//  dynamically at build time not at snapshot generation time.
		prefer := ctx.sdkMemberContext.Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER") || s.PreferPrebuilts()
		prefer := ctx.sdkMemberContext.Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER")

		// Set prefer. Setting this to false is not strictly required as that is the default but it does
		// provide a convenient hook to post-process the generated Android.bp file, e.g. in tests to