Convert absolute source path to relative path in PRODUCT_COPY_FILES processing
Source paths should be relative to the top in most builds, but this is
not true for some downstream builds. Kati does not restrict this, but
Soong enforces that all source paths are relative and leads to error for
these downstream branches. This change deals with such issue by
converting the absolute paths to relative paths.
Test: m nothing --no-skip-soong-tests
Bug: 378298832
Change-Id: I313b3827417c9672b38737e8fe846bb7521b17d1
diff --git a/fsgen/prebuilt_etc_modules_gen.go b/fsgen/prebuilt_etc_modules_gen.go
index 983dcfb..73fb8d7 100644
--- a/fsgen/prebuilt_etc_modules_gen.go
+++ b/fsgen/prebuilt_etc_modules_gen.go
@@ -100,10 +100,15 @@
ctx.ModuleErrorf("PRODUCT_COPY_FILES must follow the format \"src:dest\", got: %s", copyFilePair)
}
src, dest := srcDestList[0], srcDestList[1]
+
+ // Some downstream branches use absolute path as entries in PRODUCT_COPY_FILES.
+ // Convert them to relative path from top and check if they do not escape the tree root.
+ relSrc := android.ToRelativeSourcePath(ctx, src)
+
if _, ok := seen[dest]; !ok {
- if optionalPath := android.ExistentPathForSource(ctx, src); optionalPath.Valid() {
+ if optionalPath := android.ExistentPathForSource(ctx, relSrc); optionalPath.Valid() {
seen[dest] = true
- filtered[src] = append(filtered[src], dest)
+ filtered[relSrc] = append(filtered[relSrc], dest)
}
}
}