Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d74a6afa authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Convert absolute source path to relative path in PRODUCT_COPY_FILES processing" into main

parents 7a30eddc f27c3a5a
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -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
}
+7 −2
Original line number Diff line number Diff line
@@ -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)
			}
		}
	}