Reverse RRO dir paths when passing to Make

LOCAL_RESOURCE_DIRS puts the highest priority overlay first, but
aapt2 expects the highest priority overlay last.  Soong stores the
list in aapt2 order (low to high priority), but that means when it
exports to Make as LOCAL_SOONG_RRO_DIRS, which goes to
build_rro_package.mk and then package_internal.mk, it gets reversed
again and comes out backwards.

Bug: 78032566
Test: m checkbuild
Change-Id: If72bf929fbf1d126f9051a2f21ec1eb4e3030e6e
Merged-In: If72bf929fbf1d126f9051a2f21ec1eb4e3030e6e
(cherry picked from commit a140bb05f1)
This commit is contained in:
Colin Cross
2018-04-17 10:52:26 -07:00
parent e20c1b1904
commit 9ccbc6036d
3 changed files with 16 additions and 5 deletions

View File

@@ -308,6 +308,18 @@ func LastUniquePaths(list Paths) Paths {
return list[totalSkip:] return list[totalSkip:]
} }
// ReversePaths returns a copy of a Paths in reverse order.
func ReversePaths(list Paths) Paths {
if list == nil {
return nil
}
ret := make(Paths, len(list))
for i := range list {
ret[i] = list[len(list)-1-i]
}
return ret
}
func indexPathList(s Path, list []Path) int { func indexPathList(s Path, list []Path) int {
for i, l := range list { for i, l := range list {
if l == s { if l == s {

View File

@@ -474,10 +474,7 @@ func TestDirectorySortedPaths(t *testing.T) {
} }
paths := makePaths() paths := makePaths()
reversePaths := make(Paths, len(paths)) reversePaths := ReversePaths(paths)
for i, v := range paths {
reversePaths[len(paths)-i-1] = v
}
sortedPaths := PathsToDirectorySortedPaths(paths) sortedPaths := PathsToDirectorySortedPaths(paths)
reverseSortedPaths := PathsToDirectorySortedPaths(reversePaths) reverseSortedPaths := PathsToDirectorySortedPaths(reversePaths)

View File

@@ -195,7 +195,9 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData {
} }
if len(app.rroDirs) > 0 { if len(app.rroDirs) > 0 {
fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(app.rroDirs.Strings(), " ")) // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
// expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(android.ReversePaths(app.rroDirs).Strings(), " "))
} }
if Bool(app.appProperties.Export_package_resources) { if Bool(app.appProperties.Export_package_resources) {