Merge "Enforce hidden apis usage in product(soong)"
This commit is contained in:
commit
80df439072
|
@ -1087,6 +1087,10 @@ func (c *config) EnforceSystemCertificateWhitelist() []string {
|
||||||
return c.productVariables.EnforceSystemCertificateWhitelist
|
return c.productVariables.EnforceSystemCertificateWhitelist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *config) EnforceProductPartitionInterface() bool {
|
||||||
|
return Bool(c.productVariables.EnforceProductPartitionInterface)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *config) ProductHiddenAPIStubs() []string {
|
func (c *config) ProductHiddenAPIStubs() []string {
|
||||||
return c.productVariables.ProductHiddenAPIStubs
|
return c.productVariables.ProductHiddenAPIStubs
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,6 +309,8 @@ type productVariables struct {
|
||||||
TargetFSConfigGen []string `json:",omitempty"`
|
TargetFSConfigGen []string `json:",omitempty"`
|
||||||
|
|
||||||
MissingUsesLibraries []string `json:",omitempty"`
|
MissingUsesLibraries []string `json:",omitempty"`
|
||||||
|
|
||||||
|
EnforceProductPartitionInterface *bool `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func boolPtr(v bool) *bool {
|
func boolPtr(v bool) *bool {
|
||||||
|
|
|
@ -520,7 +520,7 @@ type AARImport struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) sdkVersion() string {
|
func (a *AARImport) sdkVersion() string {
|
||||||
return proptools.StringDefault(a.properties.Sdk_version, defaultSdkVersion(a))
|
return String(a.properties.Sdk_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) systemModules() string {
|
func (a *AARImport) systemModules() string {
|
||||||
|
|
|
@ -205,6 +205,7 @@ func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleCon
|
||||||
|
|
||||||
func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
a.checkPlatformAPI(ctx)
|
a.checkPlatformAPI(ctx)
|
||||||
|
a.checkSdkVersion(ctx)
|
||||||
a.generateAndroidBuildActions(ctx)
|
a.generateAndroidBuildActions(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -666,6 +666,44 @@ func TestJNIABI(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppSdkVersionByPartition(t *testing.T) {
|
||||||
|
testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
vendor: true,
|
||||||
|
platform_apis: true,
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
testJava(t, `
|
||||||
|
android_app {
|
||||||
|
name: "bar",
|
||||||
|
srcs: ["b.java"],
|
||||||
|
platform_apis: true,
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
for _, enforce := range []bool{true, false} {
|
||||||
|
|
||||||
|
config := testConfig(nil)
|
||||||
|
config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
|
||||||
|
bp := `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
product_specific: true,
|
||||||
|
platform_apis: true,
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if enforce {
|
||||||
|
testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", bp, config)
|
||||||
|
} else {
|
||||||
|
testJavaWithConfig(t, bp, config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestJNIPackaging(t *testing.T) {
|
func TestJNIPackaging(t *testing.T) {
|
||||||
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
||||||
cc_library {
|
cc_library {
|
||||||
|
|
|
@ -404,7 +404,7 @@ func JavadocHostFactory() android.Module {
|
||||||
var _ android.OutputFileProducer = (*Javadoc)(nil)
|
var _ android.OutputFileProducer = (*Javadoc)(nil)
|
||||||
|
|
||||||
func (j *Javadoc) sdkVersion() string {
|
func (j *Javadoc) sdkVersion() string {
|
||||||
return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j))
|
return String(j.properties.Sdk_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Javadoc) systemModules() string {
|
func (j *Javadoc) systemModules() string {
|
||||||
|
|
29
java/java.go
29
java/java.go
|
@ -54,6 +54,18 @@ func init() {
|
||||||
android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Module) checkSdkVersion(ctx android.ModuleContext) {
|
||||||
|
if j.SocSpecific() || j.DeviceSpecific() ||
|
||||||
|
(j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
|
||||||
|
if sc, ok := ctx.Module().(sdkContext); ok {
|
||||||
|
if sc.sdkVersion() == "" {
|
||||||
|
ctx.PropertyErrorf("sdk_version",
|
||||||
|
"sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
|
func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
|
||||||
if sc, ok := ctx.Module().(sdkContext); ok {
|
if sc, ok := ctx.Module().(sdkContext); ok {
|
||||||
usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
|
usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
|
||||||
|
@ -452,18 +464,6 @@ var (
|
||||||
usesLibTag = dependencyTag{name: "uses-library"}
|
usesLibTag = dependencyTag{name: "uses-library"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultSdkVersion(ctx checkVendorModuleContext) string {
|
|
||||||
if ctx.SocSpecific() || ctx.DeviceSpecific() {
|
|
||||||
return "system_current"
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type checkVendorModuleContext interface {
|
|
||||||
SocSpecific() bool
|
|
||||||
DeviceSpecific() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type sdkDep struct {
|
type sdkDep struct {
|
||||||
useModule, useFiles, useDefaultLibs, invalidVersion bool
|
useModule, useFiles, useDefaultLibs, invalidVersion bool
|
||||||
|
|
||||||
|
@ -510,7 +510,7 @@ func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) sdkVersion() string {
|
func (j *Module) sdkVersion() string {
|
||||||
return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j))
|
return String(j.deviceProperties.Sdk_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) systemModules() string {
|
func (j *Module) systemModules() string {
|
||||||
|
@ -1641,6 +1641,7 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
j.checkSdkVersion(ctx)
|
||||||
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
||||||
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
||||||
j.dexpreopter.isInstallable = Bool(j.properties.Installable)
|
j.dexpreopter.isInstallable = Bool(j.properties.Installable)
|
||||||
|
@ -1984,7 +1985,7 @@ type Import struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) sdkVersion() string {
|
func (j *Import) sdkVersion() string {
|
||||||
return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j))
|
return String(j.properties.Sdk_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) minSdkVersion() string {
|
func (j *Import) minSdkVersion() string {
|
||||||
|
|
|
@ -27,6 +27,8 @@ import (
|
||||||
"android/soong/cc"
|
"android/soong/cc"
|
||||||
"android/soong/dexpreopt"
|
"android/soong/dexpreopt"
|
||||||
"android/soong/genrule"
|
"android/soong/genrule"
|
||||||
|
|
||||||
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
var buildDir string
|
var buildDir string
|
||||||
|
@ -228,9 +230,13 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) {
|
||||||
android.FailIfErrored(t, errs)
|
android.FailIfErrored(t, errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testJavaError(t *testing.T, pattern string, bp string) {
|
func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) {
|
||||||
|
t.Helper()
|
||||||
|
return testJavaErrorWithConfig(t, pattern, bp, testConfig(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testJavaErrorWithConfig(t *testing.T, pattern string, bp string, config android.Config) (*android.TestContext, android.Config) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
config := testConfig(nil)
|
|
||||||
ctx := testContext(bp, nil)
|
ctx := testContext(bp, nil)
|
||||||
|
|
||||||
pathCtx := android.PathContextForTesting(config, nil)
|
pathCtx := android.PathContextForTesting(config, nil)
|
||||||
|
@ -240,20 +246,26 @@ func testJavaError(t *testing.T, pattern string, bp string) {
|
||||||
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
android.FailIfNoMatchingErrors(t, pattern, errs)
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
||||||
return
|
return ctx, config
|
||||||
}
|
}
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
_, errs = ctx.PrepareBuildActions(config)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
android.FailIfNoMatchingErrors(t, pattern, errs)
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
||||||
return
|
return ctx, config
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
||||||
|
|
||||||
|
return ctx, config
|
||||||
}
|
}
|
||||||
|
|
||||||
func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
config := testConfig(nil)
|
return testJavaWithConfig(t, bp, testConfig(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testJavaWithConfig(t *testing.T, bp string, config android.Config) (*android.TestContext, android.Config) {
|
||||||
|
t.Helper()
|
||||||
ctx := testContext(bp, nil)
|
ctx := testContext(bp, nil)
|
||||||
run(t, ctx, config)
|
run(t, ctx, config)
|
||||||
|
|
||||||
|
@ -315,29 +327,38 @@ func TestSimple(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSdkVersion(t *testing.T) {
|
func TestSdkVersionByPartition(t *testing.T) {
|
||||||
ctx, _ := testJava(t, `
|
testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
|
||||||
java_library {
|
java_library {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
vendor: true,
|
vendor: true,
|
||||||
}
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
testJava(t, `
|
||||||
java_library {
|
java_library {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
srcs: ["b.java"],
|
srcs: ["b.java"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
foo := ctx.ModuleForTests("foo", "android_common").Module().(*Library)
|
for _, enforce := range []bool{true, false} {
|
||||||
bar := ctx.ModuleForTests("bar", "android_common").Module().(*Library)
|
|
||||||
|
|
||||||
if foo.sdkVersion() != "system_current" {
|
config := testConfig(nil)
|
||||||
t.Errorf("If sdk version of vendor module is empty, it must change to system_current.")
|
config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
|
||||||
}
|
bp := `
|
||||||
|
java_library {
|
||||||
if bar.sdkVersion() != "" {
|
name: "foo",
|
||||||
t.Errorf("If sdk version of non-vendor module is empty, it keeps empty.")
|
srcs: ["a.java"],
|
||||||
|
product_specific: true,
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if enforce {
|
||||||
|
testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", bp, config)
|
||||||
|
} else {
|
||||||
|
testJavaWithConfig(t, bp, config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue