Add -stripFile argument to merge_zips
Putting resources in dex jars is going to need to pull files from classpath jars that do not match *.class. Test: m -j checkbuild Change-Id: Ia37b8b9387e5f5636769afc6937b9aa3c9ec1ced
This commit is contained in:
@@ -29,26 +29,26 @@ import (
|
|||||||
"android/soong/third_party/zip"
|
"android/soong/third_party/zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type stripDir struct{}
|
type fileList []string
|
||||||
|
|
||||||
func (s *stripDir) String() string {
|
func (f *fileList) String() string {
|
||||||
return `""`
|
return `""`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stripDir) Set(dir string) error {
|
func (f *fileList) Set(name string) error {
|
||||||
stripDirs = append(stripDirs, filepath.Clean(dir))
|
*f = append(*f, filepath.Clean(name))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type zipToNotStrip struct{}
|
type zipsToNotStripSet map[string]bool
|
||||||
|
|
||||||
func (s *zipToNotStrip) String() string {
|
func (s zipsToNotStripSet) String() string {
|
||||||
return `""`
|
return `""`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *zipToNotStrip) Set(zip_path string) error {
|
func (s zipsToNotStripSet) Set(zip_path string) error {
|
||||||
zipsToNotStrip[zip_path] = true
|
s[zip_path] = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -56,15 +56,17 @@ func (s *zipToNotStrip) Set(zip_path string) error {
|
|||||||
var (
|
var (
|
||||||
sortEntries = flag.Bool("s", false, "sort entries (defaults to the order from the input zip files)")
|
sortEntries = flag.Bool("s", false, "sort entries (defaults to the order from the input zip files)")
|
||||||
emulateJar = flag.Bool("j", false, "sort zip entries using jar ordering (META-INF first)")
|
emulateJar = flag.Bool("j", false, "sort zip entries using jar ordering (META-INF first)")
|
||||||
stripDirs []string
|
stripDirs fileList
|
||||||
zipsToNotStrip = make(map[string]bool)
|
stripFiles fileList
|
||||||
|
zipsToNotStrip = make(zipsToNotStripSet)
|
||||||
stripDirEntries = flag.Bool("D", false, "strip directory entries from the output zip file")
|
stripDirEntries = flag.Bool("D", false, "strip directory entries from the output zip file")
|
||||||
manifest = flag.String("m", "", "manifest file to insert in jar")
|
manifest = flag.String("m", "", "manifest file to insert in jar")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Var(&stripDir{}, "stripDir", "the prefix of file path to be excluded from the output zip")
|
flag.Var(&stripDirs, "stripDir", "the prefix of file path to be excluded from the output zip")
|
||||||
flag.Var(&zipToNotStrip{}, "zipToNotStrip", "the input zip file which is not applicable for stripping")
|
flag.Var(&stripFiles, "stripFile", "filenames to be excluded from the output zip, accepts wildcards")
|
||||||
|
flag.Var(&zipsToNotStrip, "zipToNotStrip", "the input zip file which is not applicable for stripping")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -243,20 +245,9 @@ func mergeZips(readers []namedZipReader, writer *zip.Writer, manifest string,
|
|||||||
|
|
||||||
for _, namedReader := range readers {
|
for _, namedReader := range readers {
|
||||||
_, skipStripThisZip := zipsToNotStrip[namedReader.path]
|
_, skipStripThisZip := zipsToNotStrip[namedReader.path]
|
||||||
FileLoop:
|
|
||||||
for _, file := range namedReader.reader.File {
|
for _, file := range namedReader.reader.File {
|
||||||
if !skipStripThisZip {
|
if !skipStripThisZip && shouldStripFile(emulateJar, file.Name) {
|
||||||
for _, dir := range stripDirs {
|
continue
|
||||||
if strings.HasPrefix(file.Name, dir+"/") {
|
|
||||||
if emulateJar {
|
|
||||||
if file.Name != jar.MetaDir && file.Name != jar.ManifestFile {
|
|
||||||
continue FileLoop
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
continue FileLoop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if stripDirEntries && file.FileInfo().IsDir() {
|
if stripDirEntries && file.FileInfo().IsDir() {
|
||||||
@@ -310,6 +301,28 @@ func mergeZips(readers []namedZipReader, writer *zip.Writer, manifest string,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldStripFile(emulateJar bool, name string) bool {
|
||||||
|
for _, dir := range stripDirs {
|
||||||
|
if strings.HasPrefix(name, dir+"/") {
|
||||||
|
if emulateJar {
|
||||||
|
if name != jar.MetaDir && name != jar.ManifestFile {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, pattern := range stripFiles {
|
||||||
|
if match, err := filepath.Match(pattern, filepath.Base(name)); err != nil {
|
||||||
|
panic(fmt.Errorf("%s: %s", err.Error(), pattern))
|
||||||
|
} else if match {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func jarSort(files []fileMapping) {
|
func jarSort(files []fileMapping) {
|
||||||
sort.SliceStable(files, func(i, j int) bool {
|
sort.SliceStable(files, func(i, j int) bool {
|
||||||
return jar.EntryNamesLess(files[i].dest, files[j].dest)
|
return jar.EntryNamesLess(files[i].dest, files[j].dest)
|
||||||
|
Reference in New Issue
Block a user