Delete prebuilt APEXes when installing source-built APEXes
To build the platform for ASAN, we do
`m && SANITIZE_TARGET='addresss' m`
However, at the end of the second build, the system partition could have
conflicting APEXes; prebuilt APEXes from the first build and
source-built APEXes from the second build. Since the file names for the
prebuilt and the source-built are different (e.g.
com.google.android.media.apex v.s. com.android.media.apex), we end up
having two files for the same APEX. This is confusing apexd at runtime
and the device fails to boot.
To fix this, when building a non-prebuilt APEX, the prebuilt APEX might
have been installed by the previous build is deleted.
Bug: 138146044
Test: lunch aosp_cf_x86_pasan; m && SANITIZE_TARGET='address' m
check that out/target/product/vsoc_x86/system/apex has
com.android.*.apex only.
Change-Id: Ib5a021a297cf0173ea5a3b50e9398b1cf295c558
diff --git a/apex/apex.go b/apex/apex.go
index 0466ccb..de9ce0d 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -410,6 +410,8 @@
outputFiles map[apexPackaging]android.WritablePath
installDir android.OutputPath
+ prebuiltFileToDelete string
+
public_key_file android.Path
private_key_file android.Path
@@ -871,6 +873,12 @@
} else {
ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
}
+ case android.PrebuiltDepTag:
+ // If the prebuilt is force disabled, remember to delete the prebuilt file
+ // that might have been installed in the previous builds
+ if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
+ a.prebuiltFileToDelete = prebuilt.InstallFilename()
+ }
}
} else {
// indirect dependencies
@@ -1355,6 +1363,10 @@
if len(a.externalDeps) > 0 {
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
}
+ if a.prebuiltFileToDelete != "" {
+ fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
+ filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
+ }
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
if apexType == imageApex {
@@ -1510,6 +1522,10 @@
p.properties.Source = src
}
+func (p *Prebuilt) isForceDisabled() bool {
+ return p.properties.ForceDisable
+}
+
func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
switch tag {
case "":