aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaewoong Jung2019-05-10 17:16:29 -0500
committerJaewoong Jung2019-05-15 14:11:18 -0500
commitb639a6adb284ad8c9d320127fd205b77990ef146 (patch)
tree6f792947a505e62ae18c5023c6926ba5d1d27788
parentbc975e8b897eaff7e5729fc362c31d35e838526a (diff)
downloadplatform-build-soong-b639a6adb284ad8c9d320127fd205b77990ef146.tar.gz
platform-build-soong-b639a6adb284ad8c9d320127fd205b77990ef146.tar.xz
platform-build-soong-b639a6adb284ad8c9d320127fd205b77990ef146.zip
Fix override_android_app dependency issues.
This change fixes an issue where an android_test could not depened on an override_android_app or an android_app overridden by one by moving all override processing to post-deps and forwarding incoming dependencies on override_android_apps to base android_app modules Fixes: 132447700 Test: app_test.go Change-Id: I4ac593be661f541f5ea9823ef97373bee4b186f9
-rw-r--r--android/mutator.go2
-rw-r--r--android/override_module.go35
-rw-r--r--java/app.go4
-rw-r--r--java/app_test.go57
-rw-r--r--java/java_test.go2
5 files changed, 90 insertions, 10 deletions
diff --git a/android/mutator.go b/android/mutator.go
index 45954d3e..085c055e 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -77,7 +77,6 @@ var preArch = []RegisterMutatorFunc{
77 RegisterNamespaceMutator, 77 RegisterNamespaceMutator,
78 RegisterPrebuiltsPreArchMutators, 78 RegisterPrebuiltsPreArchMutators,
79 RegisterDefaultsPreArchMutators, 79 RegisterDefaultsPreArchMutators,
80 RegisterOverridePreArchMutators,
81 registerVisibilityRuleGatherer, 80 registerVisibilityRuleGatherer,
82} 81}
83 82
@@ -95,6 +94,7 @@ var postDeps = []RegisterMutatorFunc{
95 RegisterPrebuiltsPostDepsMutators, 94 RegisterPrebuiltsPostDepsMutators,
96 registerVisibilityRuleEnforcer, 95 registerVisibilityRuleEnforcer,
97 registerNeverallowMutator, 96 registerNeverallowMutator,
97 RegisterOverridePostDepsMutators,
98} 98}
99 99
100func PreArchMutators(f RegisterMutatorFunc) { 100func PreArchMutators(f RegisterMutatorFunc) {
diff --git a/android/override_module.go b/android/override_module.go
index 119bca1c..5a57c937 100644
--- a/android/override_module.go
+++ b/android/override_module.go
@@ -84,8 +84,13 @@ type OverridableModule interface {
84 getOverrides() []OverrideModule 84 getOverrides() []OverrideModule
85 85
86 override(ctx BaseModuleContext, o OverrideModule) 86 override(ctx BaseModuleContext, o OverrideModule)
87 getOverriddenBy() string
87 88
88 setOverridesProperty(overridesProperties *[]string) 89 setOverridesProperty(overridesProperties *[]string)
90
91 // Due to complications with incoming dependencies, overrides are processed after DepsMutator.
92 // So, overridable properties need to be handled in a separate, dedicated deps mutator.
93 OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext)
89} 94}
90 95
91// Base module struct for overridable module types 96// Base module struct for overridable module types
@@ -106,6 +111,8 @@ type OverridableModuleBase struct {
106 // set this to a pointer to the property through the InitOverridableModule function, so that 111 // set this to a pointer to the property through the InitOverridableModule function, so that
107 // override information is propagated and aggregated correctly. 112 // override information is propagated and aggregated correctly.
108 overridesProperty *[]string 113 overridesProperty *[]string
114
115 overriddenBy string
109} 116}
110 117
111func InitOverridableModule(m OverridableModule, overridesProperty *[]string) { 118func InitOverridableModule(m OverridableModule, overridesProperty *[]string) {
@@ -153,14 +160,23 @@ func (b *OverridableModuleBase) override(ctx BaseModuleContext, o OverrideModule
153 } 160 }
154 } 161 }
155 } 162 }
163 b.overriddenBy = o.Name()
164}
165
166func (b *OverridableModuleBase) getOverriddenBy() string {
167 return b.overriddenBy
168}
169
170func (b *OverridableModuleBase) OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext) {
156} 171}
157 172
158// Mutators for override/overridable modules. All the fun happens in these functions. It is critical 173// Mutators for override/overridable modules. All the fun happens in these functions. It is critical
159// to keep them in this order and not put any order mutators between them. 174// to keep them in this order and not put any order mutators between them.
160func RegisterOverridePreArchMutators(ctx RegisterMutatorsContext) { 175func RegisterOverridePostDepsMutators(ctx RegisterMutatorsContext) {
161 ctx.BottomUp("override_deps", overrideModuleDepsMutator).Parallel() 176 ctx.BottomUp("override_deps", overrideModuleDepsMutator).Parallel()
162 ctx.TopDown("register_override", registerOverrideMutator).Parallel() 177 ctx.TopDown("register_override", registerOverrideMutator).Parallel()
163 ctx.BottomUp("perform_override", performOverrideMutator).Parallel() 178 ctx.BottomUp("perform_override", performOverrideMutator).Parallel()
179 ctx.BottomUp("overridable_deps", overridableModuleDepsMutator).Parallel()
164} 180}
165 181
166type overrideBaseDependencyTag struct { 182type overrideBaseDependencyTag struct {
@@ -207,5 +223,22 @@ func performOverrideMutator(ctx BottomUpMutatorContext) {
207 for i, o := range overrides { 223 for i, o := range overrides {
208 mods[i+1].(OverridableModule).override(ctx, o) 224 mods[i+1].(OverridableModule).override(ctx, o)
209 } 225 }
226 } else if o, ok := ctx.Module().(OverrideModule); ok {
227 // Create a variant of the overriding module with its own name. This matches the above local
228 // variant name rule for overridden modules, and thus allows ReplaceDependencies to match the
229 // two.
230 ctx.CreateLocalVariations(o.Name())
231 }
232}
233
234func overridableModuleDepsMutator(ctx BottomUpMutatorContext) {
235 if b, ok := ctx.Module().(OverridableModule); ok {
236 if o := b.getOverriddenBy(); o != "" {
237 // Redirect dependencies on the overriding module to this overridden module. Overriding
238 // modules are basically pseudo modules, and all build actions are associated to overridden
239 // modules. Therefore, dependencies on overriding modules need to be forwarded there as well.
240 ctx.ReplaceDependencies(o)
241 }
242 b.OverridablePropertiesDepsMutator(ctx)
210 } 243 }
211} 244}
diff --git a/java/app.go b/java/app.go
index db9c5ddf..9f37836a 100644
--- a/java/app.go
+++ b/java/app.go
@@ -163,7 +163,9 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
163 } 163 }
164 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...) 164 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
165 } 165 }
166}
166 167
168func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
167 cert := android.SrcIsModule(a.getCertString(ctx)) 169 cert := android.SrcIsModule(a.getCertString(ctx))
168 if cert != "" { 170 if cert != "" {
169 ctx.AddDependency(ctx.Module(), certificateTag, cert) 171 ctx.AddDependency(ctx.Module(), certificateTag, cert)
@@ -632,7 +634,7 @@ func OverrideAndroidAppModuleFactory() android.Module {
632 m := &OverrideAndroidApp{} 634 m := &OverrideAndroidApp{}
633 m.AddProperties(&overridableAppProperties{}) 635 m.AddProperties(&overridableAppProperties{})
634 636
635 android.InitAndroidModule(m) 637 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
636 android.InitOverrideModule(m) 638 android.InitOverrideModule(m)
637 return m 639 return m
638} 640}
diff --git a/java/app_test.go b/java/app_test.go
index bc35e216..347139e1 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -881,7 +881,7 @@ func TestOverrideAndroidApp(t *testing.T) {
881 name: "foo", 881 name: "foo",
882 srcs: ["a.java"], 882 srcs: ["a.java"],
883 certificate: "expiredkey", 883 certificate: "expiredkey",
884 overrides: ["baz"], 884 overrides: ["qux"],
885 } 885 }
886 886
887 override_android_app { 887 override_android_app {
@@ -903,6 +903,7 @@ func TestOverrideAndroidApp(t *testing.T) {
903 `) 903 `)
904 904
905 expectedVariants := []struct { 905 expectedVariants := []struct {
906 moduleName string
906 variantName string 907 variantName string
907 apkName string 908 apkName string
908 apkPath string 909 apkPath string
@@ -911,24 +912,27 @@ func TestOverrideAndroidApp(t *testing.T) {
911 aaptFlag string 912 aaptFlag string
912 }{ 913 }{
913 { 914 {
915 moduleName: "foo",
914 variantName: "android_common", 916 variantName: "android_common",
915 apkPath: "/target/product/test_device/system/app/foo/foo.apk", 917 apkPath: "/target/product/test_device/system/app/foo/foo.apk",
916 signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", 918 signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
917 overrides: []string{"baz"}, 919 overrides: []string{"qux"},
918 aaptFlag: "", 920 aaptFlag: "",
919 }, 921 },
920 { 922 {
921 variantName: "bar_android_common", 923 moduleName: "bar",
924 variantName: "android_common_bar",
922 apkPath: "/target/product/test_device/system/app/bar/bar.apk", 925 apkPath: "/target/product/test_device/system/app/bar/bar.apk",
923 signFlag: "cert/new_cert.x509.pem cert/new_cert.pk8", 926 signFlag: "cert/new_cert.x509.pem cert/new_cert.pk8",
924 overrides: []string{"baz", "foo"}, 927 overrides: []string{"qux", "foo"},
925 aaptFlag: "", 928 aaptFlag: "",
926 }, 929 },
927 { 930 {
928 variantName: "baz_android_common", 931 moduleName: "baz",
932 variantName: "android_common_baz",
929 apkPath: "/target/product/test_device/system/app/baz/baz.apk", 933 apkPath: "/target/product/test_device/system/app/baz/baz.apk",
930 signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", 934 signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
931 overrides: []string{"baz", "foo"}, 935 overrides: []string{"qux", "foo"},
932 aaptFlag: "--rename-manifest-package org.dandroid.bp", 936 aaptFlag: "--rename-manifest-package org.dandroid.bp",
933 }, 937 },
934 } 938 }
@@ -972,6 +976,47 @@ func TestOverrideAndroidApp(t *testing.T) {
972 } 976 }
973} 977}
974 978
979func TestOverrideAndroidAppDependency(t *testing.T) {
980 ctx := testJava(t, `
981 android_app {
982 name: "foo",
983 srcs: ["a.java"],
984 }
985
986 override_android_app {
987 name: "bar",
988 base: "foo",
989 package_name: "org.dandroid.bp",
990 }
991
992 android_test {
993 name: "baz",
994 srcs: ["b.java"],
995 instrumentation_for: "foo",
996 }
997
998 android_test {
999 name: "qux",
1000 srcs: ["b.java"],
1001 instrumentation_for: "bar",
1002 }
1003 `)
1004
1005 // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg.
1006 javac := ctx.ModuleForTests("baz", "android_common").Rule("javac")
1007 fooTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar")
1008 if !strings.Contains(javac.Args["classpath"], fooTurbine) {
1009 t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine)
1010 }
1011
1012 // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg.
1013 javac = ctx.ModuleForTests("qux", "android_common").Rule("javac")
1014 barTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common_bar", "turbine-combined", "foo.jar")
1015 if !strings.Contains(javac.Args["classpath"], barTurbine) {
1016 t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine)
1017 }
1018}
1019
975func TestAndroidAppImport(t *testing.T) { 1020func TestAndroidAppImport(t *testing.T) {
976 ctx := testJava(t, ` 1021 ctx := testJava(t, `
977 android_app_import { 1022 android_app_import {
diff --git a/java/java_test.go b/java/java_test.go
index 370e7964..50b1c34c 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -93,10 +93,10 @@ func testContext(config android.Config, bp string,
93 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) 93 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
94 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) 94 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
95 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) 95 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
96 ctx.PreArchMutators(android.RegisterOverridePreArchMutators)
97 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { 96 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
98 ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel() 97 ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel()
99 }) 98 })
99 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
100 ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory)) 100 ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory))
101 ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory)) 101 ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory))
102 102