soong_zip: add support for -j to junk paths
When -j is specified ignore the path to the source file and just zip it with its filename. -j overrides -C, and -C overrides -j, so -j -f path1 -C dir -f path2 will junk the path for path1, but treat path2 as relative to dir. Remove the filepath.Clean for the FileArgs, it would convert "" to "." sometimes, and everything gets cleaned in zip already for the non-command-line use cases. Test: m checkbuild Change-Id: I7d90572c622ee0c6f35967ff31d067b5312c72eb
This commit is contained in:
21
zip/zip.go
21
zip/zip.go
@@ -87,6 +87,7 @@ func (u *uniqueSet) Set(s string) error {
|
||||
type FileArg struct {
|
||||
PathPrefixInZip, SourcePrefixToStrip string
|
||||
SourceFiles []string
|
||||
JunkPaths bool
|
||||
GlobDir string
|
||||
}
|
||||
|
||||
@@ -228,8 +229,7 @@ func Run(args ZipArgs) (err error) {
|
||||
srcs = append(srcs, recursiveGlobFiles(fa.GlobDir)...)
|
||||
}
|
||||
for _, src := range srcs {
|
||||
err := fillPathPairs(fa.PathPrefixInZip, fa.SourcePrefixToStrip, src,
|
||||
&pathMappings, args.NonDeflatedFiles, noCompression)
|
||||
err := fillPathPairs(fa, src, &pathMappings, args.NonDeflatedFiles, noCompression)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -270,7 +270,7 @@ func Run(args ZipArgs) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func fillPathPairs(prefix, rel, src string, pathMappings *[]pathMapping,
|
||||
func fillPathPairs(fa FileArg, src string, pathMappings *[]pathMapping,
|
||||
nonDeflatedFiles map[string]bool, noCompression bool) error {
|
||||
|
||||
src = strings.TrimSpace(src)
|
||||
@@ -278,11 +278,18 @@ func fillPathPairs(prefix, rel, src string, pathMappings *[]pathMapping,
|
||||
return nil
|
||||
}
|
||||
src = filepath.Clean(src)
|
||||
dest, err := filepath.Rel(rel, src)
|
||||
if err != nil {
|
||||
return err
|
||||
var dest string
|
||||
|
||||
if fa.JunkPaths {
|
||||
dest = filepath.Base(src)
|
||||
} else {
|
||||
var err error
|
||||
dest, err = filepath.Rel(fa.SourcePrefixToStrip, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
dest = filepath.Join(prefix, dest)
|
||||
dest = filepath.Join(fa.PathPrefixInZip, dest)
|
||||
|
||||
zipMethod := zip.Deflate
|
||||
if _, found := nonDeflatedFiles[dest]; found || noCompression {
|
||||
|
Reference in New Issue
Block a user