diff options
| author | 2024-11-12 23:07:43 +0000 | |
|---|---|---|
| committer | 2024-11-12 23:07:43 +0000 | |
| commit | d74a6afaa51c6c18dd5592a6da42b4bbdf59f619 (patch) | |
| tree | 98893e43839da454f87ff0915f4f399e42eec23b | |
| parent | 7a30eddc4091a35b821e41ce928a4a3864b904d4 (diff) | |
| parent | f27c3a5aa98656664a0a8191231d475e30fed147 (diff) | |
Merge "Convert absolute source path to relative path in PRODUCT_COPY_FILES processing" into main
| -rw-r--r-- | android/paths.go | 16 | ||||
| -rw-r--r-- | fsgen/prebuilt_etc_modules_gen.go | 9 |
2 files changed, 23 insertions, 2 deletions
diff --git a/android/paths.go b/android/paths.go index 3f67c55b2..8f066cc08 100644 --- a/android/paths.go +++ b/android/paths.go @@ -2613,3 +2613,19 @@ func IsThirdPartyPath(path string) bool { } return false } + +// ToRelativeSourcePath converts absolute source path to the path relative to the source root. +// This throws an error if the input path is outside of the source root and cannot be converted +// to the relative path. +// This should be rarely used given that the source path is relative in Soong. +func ToRelativeSourcePath(ctx PathContext, path string) string { + ret := path + if filepath.IsAbs(path) { + relPath, err := filepath.Rel(absSrcDir, path) + if err != nil || strings.HasPrefix(relPath, "..") { + ReportPathErrorf(ctx, "%s is outside of the source root", path) + } + ret = relPath + } + return ret +} diff --git a/fsgen/prebuilt_etc_modules_gen.go b/fsgen/prebuilt_etc_modules_gen.go index 983dcfbcf..73fb8d70d 100644 --- a/fsgen/prebuilt_etc_modules_gen.go +++ b/fsgen/prebuilt_etc_modules_gen.go @@ -100,10 +100,15 @@ func uniqueExistingProductCopyFileMap(ctx android.LoadHookContext) map[string][] 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) } } } |