Merge "Document usage, perform minor cleanups."
This commit is contained in:
commit
9240f955cb
3 changed files with 18 additions and 10 deletions
|
@ -12,6 +12,13 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
// soong_zip is a utility used during the build to create a zip archive by pulling the entries from
|
||||||
|
// various sources:
|
||||||
|
// * explicitly specified files
|
||||||
|
// * files whose paths are read from a file
|
||||||
|
// * directories traversed recursively
|
||||||
|
// It can optionally change the recorded path of an entry.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
17
zip/zip.go
17
zip/zip.go
|
@ -126,6 +126,7 @@ func (b *FileArgsBuilder) Dir(name string) *FileArgsBuilder {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List reads the file names from the given file and adds them to the source files list.
|
||||||
func (b *FileArgsBuilder) List(name string) *FileArgsBuilder {
|
func (b *FileArgsBuilder) List(name string) *FileArgsBuilder {
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return b
|
return b
|
||||||
|
@ -150,6 +151,7 @@ func (b *FileArgsBuilder) List(name string) *FileArgsBuilder {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RspFile reads the file names from given .rsp file and adds them to the source files list.
|
||||||
func (b *FileArgsBuilder) RspFile(name string) *FileArgsBuilder {
|
func (b *FileArgsBuilder) RspFile(name string) *FileArgsBuilder {
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return b
|
return b
|
||||||
|
@ -291,7 +293,7 @@ func ReadRespFile(bytes []byte) []string {
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
func ZipTo(args ZipArgs, w io.Writer) error {
|
func zipTo(args ZipArgs, w io.Writer) error {
|
||||||
if args.EmulateJar {
|
if args.EmulateJar {
|
||||||
args.AddDirectoryEntriesToZip = true
|
args.AddDirectoryEntriesToZip = true
|
||||||
}
|
}
|
||||||
|
@ -392,6 +394,7 @@ func ZipTo(args ZipArgs, w io.Writer) error {
|
||||||
return z.write(w, pathMappings, args.ManifestSourcePath, args.EmulateJar, args.SrcJar, args.NumParallelJobs)
|
return z.write(w, pathMappings, args.ManifestSourcePath, args.EmulateJar, args.SrcJar, args.NumParallelJobs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zip creates an output zip archive from given sources.
|
||||||
func Zip(args ZipArgs) error {
|
func Zip(args ZipArgs) error {
|
||||||
if args.OutputFilePath == "" {
|
if args.OutputFilePath == "" {
|
||||||
return fmt.Errorf("output file path must be nonempty")
|
return fmt.Errorf("output file path must be nonempty")
|
||||||
|
@ -416,7 +419,7 @@ func Zip(args ZipArgs) error {
|
||||||
out = f
|
out = f
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ZipTo(args, out)
|
err := zipTo(args, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -450,7 +453,6 @@ func fillPathPairs(fa FileArg, src string, pathMappings *[]pathMapping,
|
||||||
RelativeRoot: fa.SourcePrefixToStrip,
|
RelativeRoot: fa.SourcePrefixToStrip,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
dest = filepath.Join(fa.PathPrefixInZip, dest)
|
dest = filepath.Join(fa.PathPrefixInZip, dest)
|
||||||
|
|
||||||
|
@ -465,10 +467,9 @@ func fillPathPairs(fa FileArg, src string, pathMappings *[]pathMapping,
|
||||||
}
|
}
|
||||||
|
|
||||||
func jarSort(mappings []pathMapping) {
|
func jarSort(mappings []pathMapping) {
|
||||||
less := func(i int, j int) (smaller bool) {
|
sort.SliceStable(mappings, func(i int, j int) bool {
|
||||||
return jar.EntryNamesLess(mappings[i].dest, mappings[j].dest)
|
return jar.EntryNamesLess(mappings[i].dest, mappings[j].dest)
|
||||||
}
|
})
|
||||||
sort.SliceStable(mappings, less)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZipWriter) write(f io.Writer, pathMappings []pathMapping, manifest string, emulateJar, srcJar bool,
|
func (z *ZipWriter) write(f io.Writer, pathMappings []pathMapping, manifest string, emulateJar, srcJar bool,
|
||||||
|
@ -709,7 +710,7 @@ func (z *ZipWriter) addFile(dest, src string, method uint16, emulateJar, srcJar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZipWriter) addManifest(dest string, src string, method uint16) error {
|
func (z *ZipWriter) addManifest(dest string, src string, _ uint16) error {
|
||||||
if prev, exists := z.createdDirs[dest]; exists {
|
if prev, exists := z.createdDirs[dest]; exists {
|
||||||
return fmt.Errorf("destination %q is both a directory %q and a file %q", dest, prev, src)
|
return fmt.Errorf("destination %q is both a directory %q and a file %q", dest, prev, src)
|
||||||
}
|
}
|
||||||
|
@ -963,7 +964,7 @@ func (z *ZipWriter) writeDirectory(dir string, src string, emulateJar bool) erro
|
||||||
dir = filepath.Clean(dir)
|
dir = filepath.Clean(dir)
|
||||||
|
|
||||||
// discover any uncreated directories in the path
|
// discover any uncreated directories in the path
|
||||||
zipDirs := []string{}
|
var zipDirs []string
|
||||||
for dir != "" && dir != "." {
|
for dir != "" && dir != "." {
|
||||||
if _, exists := z.createdDirs[dir]; exists {
|
if _, exists := z.createdDirs[dir]; exists {
|
||||||
break
|
break
|
||||||
|
|
|
@ -442,7 +442,7 @@ func TestZip(t *testing.T) {
|
||||||
args.Stderr = &bytes.Buffer{}
|
args.Stderr = &bytes.Buffer{}
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
err := ZipTo(args, buf)
|
err := zipTo(args, buf)
|
||||||
|
|
||||||
if (err != nil) != (test.err != nil) {
|
if (err != nil) != (test.err != nil) {
|
||||||
t.Fatalf("want error %v, got %v", test.err, err)
|
t.Fatalf("want error %v, got %v", test.err, err)
|
||||||
|
@ -627,7 +627,7 @@ func TestSrcJar(t *testing.T) {
|
||||||
args.Stderr = &bytes.Buffer{}
|
args.Stderr = &bytes.Buffer{}
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
err := ZipTo(args, buf)
|
err := zipTo(args, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("got error %v", err)
|
t.Fatalf("got error %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue