Allow duplicate files inputs in soong_zip

Accept duplicate file inputs in soong_zip when they are the same
source file.  This came up when trying to zip lint srcs, as some
java modules have duplicate source files that seem to be ignored
by javac.

Test: TestZip
Bug: 216456886
Change-Id: I8c43df9aded8cf094afaed79cca2b9eb091cc861
This commit is contained in:
Colin Cross
2022-08-15 15:47:41 -07:00
parent b262f883a9
commit 7ddd08ad2b
2 changed files with 74 additions and 5 deletions

View File

@@ -46,6 +46,7 @@ var mockFs = pathtools.MockFs(map[string][]byte{
"dangling -> missing": nil,
"a/a/d -> b": nil,
"c": fileC,
"d/a/a": nil,
"l_nl": []byte("a/a/a\na/a/b\nc\n\\[\n"),
"l_sp": []byte("a/a/a a/a/b c \\["),
"l2": []byte("missing\n"),
@@ -400,6 +401,17 @@ func TestZip(t *testing.T) {
fh("a/a/b", fileB, zip.Deflate),
},
},
{
name: "duplicate sources",
args: fileArgsBuilder().
File("a/a/a").
File("a/a/a"),
compressionLevel: 9,
files: []zip.FileHeader{
fh("a/a/a", fileA, zip.Deflate),
},
},
// errors
{
@@ -427,6 +439,15 @@ func TestZip(t *testing.T) {
File("a/a/a"),
err: IncorrectRelativeRootError{},
},
{
name: "error conflicting file",
args: fileArgsBuilder().
SourcePrefixToStrip("a").
File("a/a/a").
SourcePrefixToStrip("d").
File("d/a/a"),
err: ConflictingFileError{},
},
}
for _, test := range testCases {
@@ -454,13 +475,17 @@ func TestZip(t *testing.T) {
t.Fatalf("want error %v, got %v", test.err, err)
} else if test.err != nil {
if os.IsNotExist(test.err) {
if !os.IsNotExist(test.err) {
if !os.IsNotExist(err) {
t.Fatalf("want error %v, got %v", test.err, err)
}
} else if _, wantRelativeRootErr := test.err.(IncorrectRelativeRootError); wantRelativeRootErr {
if _, gotRelativeRootErr := err.(IncorrectRelativeRootError); !gotRelativeRootErr {
t.Fatalf("want error %v, got %v", test.err, err)
}
} else if _, wantConflictingFileError := test.err.(ConflictingFileError); wantConflictingFileError {
if _, gotConflictingFileError := err.(ConflictingFileError); !gotConflictingFileError {
t.Fatalf("want error %v, got %v", test.err, err)
}
} else {
t.Fatalf("want error %v, got %v", test.err, err)
}