Add test for hiddenAPI index file generation am: 01289a2407
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1575169 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ia3bf986b4419a0f66cc0f1adf9995c4327a93a4f
This commit is contained in:
@@ -22,9 +22,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
android.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory)
|
RegisterHiddenApiSingletonComponents(android.InitRegistrationContext)
|
||||||
android.RegisterSingletonType("hiddenapi_index", hiddenAPIIndexSingletonFactory)
|
}
|
||||||
android.RegisterModuleType("hiddenapi_flags", hiddenAPIFlagsFactory)
|
|
||||||
|
func RegisterHiddenApiSingletonComponents(ctx android.RegistrationContext) {
|
||||||
|
ctx.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory)
|
||||||
|
ctx.RegisterSingletonType("hiddenapi_index", hiddenAPIIndexSingletonFactory)
|
||||||
|
ctx.RegisterModuleType("hiddenapi_flags", hiddenAPIFlagsFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type hiddenAPISingletonPathsStruct struct {
|
type hiddenAPISingletonPathsStruct struct {
|
||||||
|
@@ -15,11 +15,12 @@
|
|||||||
package java
|
package java
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
|
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ func testConfigWithBootJars(bp string, bootJars []string, prebuiltHiddenApiDir *
|
|||||||
|
|
||||||
func testContextWithHiddenAPI(config android.Config) *android.TestContext {
|
func testContextWithHiddenAPI(config android.Config) *android.TestContext {
|
||||||
ctx := testContext(config)
|
ctx := testContext(config)
|
||||||
ctx.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory)
|
RegisterHiddenApiSingletonComponents(ctx)
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ func TestHiddenAPISingleton(t *testing.T) {
|
|||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
compile_dex: true,
|
compile_dex: true,
|
||||||
}
|
}
|
||||||
`, []string{"platform:foo"}, nil)
|
`, []string{"platform:foo"}, nil)
|
||||||
|
|
||||||
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
||||||
@@ -75,6 +76,47 @@ func TestHiddenAPISingleton(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkRuleInputs(t *testing.T, expected string, hiddenAPIRule android.TestingBuildParams) {
|
||||||
|
actual := strings.TrimSpace(strings.Join(android.NormalizePathsForTesting(hiddenAPIRule.Implicits), "\n"))
|
||||||
|
expected = strings.TrimSpace(expected)
|
||||||
|
if actual != expected {
|
||||||
|
t.Errorf("Expected hiddenapi rule inputs:\n%s\nactual inputs:\n%s", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHiddenAPIIndexSingleton(t *testing.T) {
|
||||||
|
ctx, _ := testHiddenAPIBootJars(t, `
|
||||||
|
java_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
compile_dex: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
java_import {
|
||||||
|
name: "foo",
|
||||||
|
jars: ["a.jar"],
|
||||||
|
compile_dex: true,
|
||||||
|
prefer: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
java_sdk_library {
|
||||||
|
name: "bar",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
compile_dex: true,
|
||||||
|
}
|
||||||
|
`, []string{"platform:foo", "platform:bar"}, nil)
|
||||||
|
|
||||||
|
hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index")
|
||||||
|
indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index")
|
||||||
|
checkRuleInputs(t, `
|
||||||
|
.intermediates/bar.impl/android_common/hiddenapi/index.csv
|
||||||
|
.intermediates/bar/android_common/hiddenapi/index.csv
|
||||||
|
.intermediates/foo/android_common/hiddenapi/index.csv
|
||||||
|
.intermediates/prebuilt_foo/android_common/hiddenapi/index.csv
|
||||||
|
`,
|
||||||
|
indexRule)
|
||||||
|
}
|
||||||
|
|
||||||
func TestHiddenAPISingletonWithPrebuilt(t *testing.T) {
|
func TestHiddenAPISingletonWithPrebuilt(t *testing.T) {
|
||||||
ctx, _ := testHiddenAPIBootJars(t, `
|
ctx, _ := testHiddenAPIBootJars(t, `
|
||||||
java_import {
|
java_import {
|
||||||
@@ -98,14 +140,14 @@ func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) {
|
|||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
compile_dex: true,
|
compile_dex: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
java_import {
|
java_import {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
jars: ["a.jar"],
|
jars: ["a.jar"],
|
||||||
compile_dex: true,
|
compile_dex: true,
|
||||||
prefer: false,
|
prefer: false,
|
||||||
}
|
}
|
||||||
`, []string{"platform:foo"}, nil)
|
`, []string{"platform:foo"}, nil)
|
||||||
|
|
||||||
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
||||||
@@ -127,14 +169,14 @@ func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) {
|
|||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
compile_dex: true,
|
compile_dex: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
java_import {
|
java_import {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
jars: ["a.jar"],
|
jars: ["a.jar"],
|
||||||
compile_dex: true,
|
compile_dex: true,
|
||||||
prefer: true,
|
prefer: true,
|
||||||
}
|
}
|
||||||
`, []string{"platform:foo"}, nil)
|
`, []string{"platform:foo"}, nil)
|
||||||
|
|
||||||
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
||||||
|
Reference in New Issue
Block a user