aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zip2zip/zip2zip.go
diff options
context:
space:
mode:
authorJeff Gaston <jeffrygaston@google.com>2017-08-21 20:13:28 -0700
committerJeff Gaston <jeffrygaston@google.com>2017-08-24 14:43:35 -0700
commit01547b23d26b6dcde8589add0451d87d7bf63f91 (patch)
tree4d48ff404f43c6ddb1187ef8273a2173e2a60681 /cmd/zip2zip/zip2zip.go
parentc5eb66d16b82279d33746d312e91793970e0310f (diff)
downloadbuild_soong-01547b23d26b6dcde8589add0451d87d7bf63f91.tar.gz
build_soong-01547b23d26b6dcde8589add0451d87d7bf63f91.tar.bz2
build_soong-01547b23d26b6dcde8589add0451d87d7bf63f91.zip
Extract jar-sorting to be accessible to soong_zip
Bug: 64536066 Test: m -j # which runs unit tests Change-Id: I4830bd331c9dab0b1d300a18aefaf25a6af4cfdc
Diffstat (limited to 'cmd/zip2zip/zip2zip.go')
-rw-r--r--cmd/zip2zip/zip2zip.go33
1 files changed, 2 insertions, 31 deletions
diff --git a/cmd/zip2zip/zip2zip.go b/cmd/zip2zip/zip2zip.go
index 815059c9..f48d458b 100644
--- a/cmd/zip2zip/zip2zip.go
+++ b/cmd/zip2zip/zip2zip.go
@@ -24,6 +24,7 @@ import (
"strings"
"time"
+ "android/soong/jar"
"android/soong/third_party/zip"
)
@@ -178,37 +179,7 @@ func zip2zip(reader *zip.Reader, writer *zip.Writer, sortGlobs, sortJava, setTim
}
func jarSort(files []pair) {
- // Treats trailing * as a prefix match
- match := func(pattern, name string) bool {
- if strings.HasSuffix(pattern, "*") {
- return strings.HasPrefix(name, strings.TrimSuffix(pattern, "*"))
- } else {
- return name == pattern
- }
- }
-
- var jarOrder = []string{
- "META-INF/",
- "META-INF/MANIFEST.MF",
- "META-INF/*",
- "*",
- }
-
- index := func(name string) int {
- for i, pattern := range jarOrder {
- if match(pattern, name) {
- return i
- }
- }
- panic(fmt.Errorf("file %q did not match any pattern", name))
- }
-
sort.SliceStable(files, func(i, j int) bool {
- diff := index(files[i].newName) - index(files[j].newName)
- if diff == 0 {
- return files[i].newName < files[j].newName
- } else {
- return diff < 0
- }
+ return jar.EntryNamesLess(files[i].newName, files[j].newName)
})
}