Loading java/hiddenapi.go +12 −1 Original line number Diff line number Diff line Loading @@ -148,7 +148,18 @@ func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext, configurationNa primary = configurationName == ctx.ModuleName() // A source module that has been replaced by a prebuilt can never be the primary module. primary = primary && !module.IsReplacedByPrebuilt() if module.IsReplacedByPrebuilt() { ctx.VisitDirectDepsWithTag(android.PrebuiltDepTag, func(prebuilt android.Module) { if h, ok := prebuilt.(hiddenAPIIntf); ok && h.bootDexJar() != nil { primary = false } else { ctx.ModuleErrorf( "hiddenapi has determined that the source module %q should be ignored as it has been"+ " replaced by the prebuilt module %q but unfortunately it does not provide a"+ " suitable boot dex jar", ctx.ModuleName(), ctx.OtherModuleName(prebuilt)) } }) } } h.primary = primary } Loading java/hiddenapi_singleton_test.go +23 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,29 @@ func TestHiddenAPIIndexSingleton(t *testing.T) { `, indexParams) } func TestHiddenAPISingletonWithSourceAndPrebuiltPreferredButNoDex(t *testing.T) { config := testConfigWithBootJars(` java_library { name: "foo", srcs: ["a.java"], compile_dex: true, } java_import { name: "foo", jars: ["a.jar"], prefer: true, } `, []string{"platform:foo"}, nil) ctx := testContextWithHiddenAPI(config) runWithErrors(t, ctx, config, "hiddenapi has determined that the source module \"foo\" should be ignored as it has been"+ " replaced by the prebuilt module \"prebuilt_foo\" but unfortunately it does not provide a"+ " suitable boot dex jar") } func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { ctx, _ := testHiddenAPIBootJars(t, ` java_import { Loading java/java_test.go +9 −3 Original line number Diff line number Diff line Loading @@ -114,20 +114,26 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config pathCtx := android.PathContextForTesting(config) dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) runWithErrors(t, ctx, config, pattern) return ctx, config } func runWithErrors(t *testing.T, ctx *android.TestContext, config android.Config, pattern string) { ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Android.bp") if len(errs) > 0 { android.FailIfNoMatchingErrors(t, pattern, errs) return ctx, config return } _, errs = ctx.PrepareBuildActions(config) if len(errs) > 0 { android.FailIfNoMatchingErrors(t, pattern, errs) return ctx, config return } t.Fatalf("missing expected error %q (0 errors are returned)", pattern) return ctx, config return } func testJavaWithFS(t *testing.T, bp string, fs map[string][]byte) (*android.TestContext, android.Config) { Loading Loading
java/hiddenapi.go +12 −1 Original line number Diff line number Diff line Loading @@ -148,7 +148,18 @@ func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext, configurationNa primary = configurationName == ctx.ModuleName() // A source module that has been replaced by a prebuilt can never be the primary module. primary = primary && !module.IsReplacedByPrebuilt() if module.IsReplacedByPrebuilt() { ctx.VisitDirectDepsWithTag(android.PrebuiltDepTag, func(prebuilt android.Module) { if h, ok := prebuilt.(hiddenAPIIntf); ok && h.bootDexJar() != nil { primary = false } else { ctx.ModuleErrorf( "hiddenapi has determined that the source module %q should be ignored as it has been"+ " replaced by the prebuilt module %q but unfortunately it does not provide a"+ " suitable boot dex jar", ctx.ModuleName(), ctx.OtherModuleName(prebuilt)) } }) } } h.primary = primary } Loading
java/hiddenapi_singleton_test.go +23 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,29 @@ func TestHiddenAPIIndexSingleton(t *testing.T) { `, indexParams) } func TestHiddenAPISingletonWithSourceAndPrebuiltPreferredButNoDex(t *testing.T) { config := testConfigWithBootJars(` java_library { name: "foo", srcs: ["a.java"], compile_dex: true, } java_import { name: "foo", jars: ["a.jar"], prefer: true, } `, []string{"platform:foo"}, nil) ctx := testContextWithHiddenAPI(config) runWithErrors(t, ctx, config, "hiddenapi has determined that the source module \"foo\" should be ignored as it has been"+ " replaced by the prebuilt module \"prebuilt_foo\" but unfortunately it does not provide a"+ " suitable boot dex jar") } func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { ctx, _ := testHiddenAPIBootJars(t, ` java_import { Loading
java/java_test.go +9 −3 Original line number Diff line number Diff line Loading @@ -114,20 +114,26 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config pathCtx := android.PathContextForTesting(config) dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) runWithErrors(t, ctx, config, pattern) return ctx, config } func runWithErrors(t *testing.T, ctx *android.TestContext, config android.Config, pattern string) { ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Android.bp") if len(errs) > 0 { android.FailIfNoMatchingErrors(t, pattern, errs) return ctx, config return } _, errs = ctx.PrepareBuildActions(config) if len(errs) > 0 { android.FailIfNoMatchingErrors(t, pattern, errs) return ctx, config return } t.Fatalf("missing expected error %q (0 errors are returned)", pattern) return ctx, config return } func testJavaWithFS(t *testing.T, bp string, fs map[string][]byte) (*android.TestContext, android.Config) { Loading