Add GSI support for android_system_image

GSI's system.img includes system_ext and product artifacts. This patches
android_system_image module so it can include such artifacts when
building GSI.

Bug: 370351758
Test: m android_gsi
Change-Id: Id29678b1101e787e88dbedae38cdbf6d82d1cb95
diff --git a/filesystem/system_image.go b/filesystem/system_image.go
index 672458c..4d176ae 100644
--- a/filesystem/system_image.go
+++ b/filesystem/system_image.go
@@ -18,6 +18,9 @@
 	"android/soong/android"
 	"android/soong/linkerconfig"
 
+	"path/filepath"
+	"strings"
+
 	"github.com/google/blueprint/proptools"
 )
 
@@ -58,5 +61,14 @@
 // for symbol lookup by imitating "activated" paths.
 func (s *systemImage) FilterPackagingSpec(ps android.PackagingSpec) bool {
 	return !ps.SkipInstall() &&
-		(ps.Partition() == "system" || ps.Partition() == "root")
+		(ps.Partition() == "system" || ps.Partition() == "root" ||
+			strings.HasPrefix(ps.Partition(), "system/"))
+}
+
+func (s *systemImage) ModifyPackagingSpec(ps *android.PackagingSpec) {
+	if strings.HasPrefix(ps.Partition(), "system/") {
+		subPartition := strings.TrimPrefix(ps.Partition(), "system/")
+		ps.SetPartition("system")
+		ps.SetRelPathInPackage(filepath.Join(subPartition, ps.RelPathInPackage()))
+	}
 }