Ensure that sdk/module_exports depends on source members am: cee7e66b07
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1359444 Change-Id: Ie52a110e30e646a0fdf9479039bb58ee6a722078
This commit is contained in:
commit
e371a18acc
4 changed files with 84 additions and 21 deletions
|
@ -266,6 +266,9 @@ type SdkMemberTypeDependencyTag interface {
|
|||
SdkMemberType() SdkMemberType
|
||||
}
|
||||
|
||||
var _ SdkMemberTypeDependencyTag = (*sdkMemberDependencyTag)(nil)
|
||||
var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil)
|
||||
|
||||
type sdkMemberDependencyTag struct {
|
||||
blueprint.BaseDependencyTag
|
||||
memberType SdkMemberType
|
||||
|
@ -275,6 +278,12 @@ func (t *sdkMemberDependencyTag) SdkMemberType() SdkMemberType {
|
|||
return t.memberType
|
||||
}
|
||||
|
||||
// Prevent dependencies from the sdk/module_exports onto their members from being
|
||||
// replaced with a preferred prebuilt.
|
||||
func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func DependencyTagForSdkMemberType(memberType SdkMemberType) SdkMemberTypeDependencyTag {
|
||||
return &sdkMemberDependencyTag{memberType: memberType}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
|
@ -173,20 +172,6 @@ func moduleToPath(name string) string {
|
|||
}
|
||||
}
|
||||
|
||||
func checkModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
|
||||
t.Helper()
|
||||
module := ctx.ModuleForTests(name, variant).Module()
|
||||
deps := []string{}
|
||||
ctx.VisitDirectDeps(module, func(m blueprint.Module) {
|
||||
deps = append(deps, m.Name())
|
||||
})
|
||||
sort.Strings(deps)
|
||||
|
||||
if actual := deps; !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("expected %#q, found %#q", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJavaLinkType(t *testing.T) {
|
||||
testJava(t, `
|
||||
java_library {
|
||||
|
@ -647,7 +632,7 @@ func TestJavaSdkLibraryImport(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
CheckModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
`prebuilt_sdklib.stubs`,
|
||||
`prebuilt_sdklib.stubs.source.test`,
|
||||
`prebuilt_sdklib.stubs.system`,
|
||||
|
@ -675,7 +660,7 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) {
|
|||
}
|
||||
`)
|
||||
|
||||
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
CheckModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
`dex2oatd`,
|
||||
`prebuilt_sdklib`,
|
||||
`sdklib.impl`,
|
||||
|
@ -684,7 +669,7 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) {
|
|||
`sdklib.xml`,
|
||||
})
|
||||
|
||||
checkModuleDependencies(t, ctx, "prebuilt_sdklib", "android_common", []string{
|
||||
CheckModuleDependencies(t, ctx, "prebuilt_sdklib", "android_common", []string{
|
||||
`prebuilt_sdklib.stubs`,
|
||||
`sdklib.impl`,
|
||||
// This should be prebuilt_sdklib.stubs but is set to sdklib.stubs because the
|
||||
|
@ -715,7 +700,7 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
|
|||
}
|
||||
`)
|
||||
|
||||
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
CheckModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
`dex2oatd`,
|
||||
`prebuilt_sdklib`,
|
||||
`sdklib.impl`,
|
||||
|
@ -724,7 +709,7 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
|
|||
`sdklib.xml`,
|
||||
})
|
||||
|
||||
checkModuleDependencies(t, ctx, "prebuilt_sdklib", "android_common", []string{
|
||||
CheckModuleDependencies(t, ctx, "prebuilt_sdklib", "android_common", []string{
|
||||
`prebuilt_sdklib.stubs`,
|
||||
`sdklib.impl`,
|
||||
`sdklib.xml`,
|
||||
|
@ -1491,7 +1476,7 @@ func TestJavaSdkLibrary_Deps(t *testing.T) {
|
|||
}
|
||||
`)
|
||||
|
||||
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
CheckModuleDependencies(t, ctx, "sdklib", "android_common", []string{
|
||||
`dex2oatd`,
|
||||
`sdklib.impl`,
|
||||
`sdklib.stubs`,
|
||||
|
|
|
@ -16,9 +16,13 @@ package java
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) android.Config {
|
||||
|
@ -216,3 +220,17 @@ func GatherRequiredDepsForTest() string {
|
|||
|
||||
return bp
|
||||
}
|
||||
|
||||
func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
|
||||
t.Helper()
|
||||
module := ctx.ModuleForTests(name, variant).Module()
|
||||
deps := []string{}
|
||||
ctx.VisitDirectDeps(module, func(m blueprint.Module) {
|
||||
deps = append(deps, m.Name())
|
||||
})
|
||||
sort.Strings(deps)
|
||||
|
||||
if actual := deps; !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("expected %#q, found %#q", expected, actual)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ package sdk
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func testSdkWithJava(t *testing.T, bp string) *testSdkResult {
|
||||
|
@ -26,6 +28,9 @@ func testSdkWithJava(t *testing.T, bp string) *testSdkResult {
|
|||
"resource.test": nil,
|
||||
"aidl/foo/bar/Test.aidl": nil,
|
||||
|
||||
// For java_import
|
||||
"prebuilt.jar": nil,
|
||||
|
||||
// For java_sdk_library
|
||||
"api/current.txt": nil,
|
||||
"api/removed.txt": nil,
|
||||
|
@ -85,6 +90,52 @@ java_import {
|
|||
|
||||
// Contains tests for SDK members provided by the java package.
|
||||
|
||||
func TestSdkDependsOnSourceEvenWhenPrebuiltPreferred(t *testing.T) {
|
||||
result := testSdkWithJava(t, `
|
||||
sdk {
|
||||
name: "mysdk",
|
||||
java_header_libs: ["sdkmember"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "sdkmember",
|
||||
srcs: ["Test.java"],
|
||||
system_modules: "none",
|
||||
sdk_version: "none",
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "sdkmember",
|
||||
prefer: true,
|
||||
jars: ["prebuilt.jar"],
|
||||
}
|
||||
`)
|
||||
|
||||
// Make sure that the mysdk module depends on "sdkmember" and not "prebuilt_sdkmember".
|
||||
java.CheckModuleDependencies(t, result.ctx, "mysdk", "android_common", []string{"sdkmember"})
|
||||
|
||||
result.CheckSnapshot("mysdk", "",
|
||||
checkAndroidBpContents(`// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
java_import {
|
||||
name: "mysdk_sdkmember@current",
|
||||
sdk_member_name: "sdkmember",
|
||||
jars: ["java/sdkmember.jar"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "sdkmember",
|
||||
prefer: false,
|
||||
jars: ["java/sdkmember.jar"],
|
||||
}
|
||||
|
||||
sdk_snapshot {
|
||||
name: "mysdk@current",
|
||||
java_header_libs: ["mysdk_sdkmember@current"],
|
||||
}
|
||||
`))
|
||||
}
|
||||
|
||||
func TestBasicSdkWithJavaLibrary(t *testing.T) {
|
||||
result := testSdkWithJava(t, `
|
||||
sdk {
|
||||
|
|
Loading…
Reference in a new issue