Bläddra i källkod

Support Windows-style ar files.

Apparently Windows' .lib files are also ar. Add tests.

Change-Id: Ie35f410268086b8fe6d4d1b491de3f30a46309dd
Reviewed-on: https://boringssl-review.googlesource.com/c/33348
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
David Benjamin 5 år sedan
committed by CQ bot account: commit-bot@chromium.org
förälder
incheckning
c8cf62bba8
5 ändrade filer med 35 tillägg och 10 borttagningar
  1. +3
    -1
      util/ar/ar.go
  2. +32
    -9
      util/ar/ar_test.go
  3. Binär
     
  4. Binär
     
  5. Binär
     

+ 3
- 1
util/ar/ar.go Visa fil

@@ -102,7 +102,9 @@ func ParseAR(r io.Reader) (map[string][]byte, error) {
}

filename := longFilenameTable[offset:]
if i := bytes.IndexByte(filename, '/'); i < 0 {
// Windows terminates filenames with NUL characters,
// while sysv/GNU uses /.
if i := bytes.IndexAny(filename, "/\x00"); i < 0 {
return nil, errors.New("ar: unterminated filename in table")
} else {
filename = filename[:i]


+ 32
- 9
util/ar/ar_test.go Visa fil

@@ -28,7 +28,7 @@ var testDataDir = flag.String("testdata", "testdata", "The path to the test data
type arTest struct {
name string
in string
out []string
out map[string]string
// allowPadding is true if the contents may have trailing newlines at end.
// On macOS, ar calls ranlib which pads all inputs up to eight bytes with
// newlines. Unlike ar's native padding up to two bytes, this padding is
@@ -48,8 +48,33 @@ func removeTrailingNewlines(in []byte) []byte {
}

var arTests = []arTest{
{"linux", "libsample.a", []string{"foo.c.o", "bar.cc.o"}, false},
{"mac", "libsample.a", []string{"foo.c.o", "bar.cc.o"}, true},
{
"linux",
"libsample.a",
map[string]string{
"foo.c.o": "foo.c.o",
"bar.cc.o": "bar.cc.o",
},
false,
},
{
"mac",
"libsample.a",
map[string]string{
"foo.c.o": "foo.c.o",
"bar.cc.o": "bar.cc.o",
},
true,
},
{
"windows",
"sample.lib",
map[string]string{
"CMakeFiles\\sample.dir\\foo.c.obj": "foo.c.obj",
"CMakeFiles\\sample.dir\\bar.cc.obj": "bar.cc.obj",
},
false,
},
}

func TestAR(t *testing.T) {
@@ -66,12 +91,10 @@ func TestAR(t *testing.T) {
t.Fatalf("reading input failed: %s", err)
}

expectedFiles := make(map[string]struct{})
for _, file := range test.out {
expectedFiles[file] = struct{}{}
expected, err := ioutil.ReadFile(test.Path(file))
for file, contentsPath := range test.out {
expected, err := ioutil.ReadFile(test.Path(contentsPath))
if err != nil {
t.Fatalf("error reading %s: %s", file, err)
t.Fatalf("error reading %s: %s", contentsPath, err)
}
got, ok := ret[file]
if test.allowPadding {
@@ -86,7 +109,7 @@ func TestAR(t *testing.T) {
}

for file, _ := range ret {
if _, ok := expectedFiles[file]; !ok {
if _, ok := test.out[file]; !ok {
t.Errorf("output contained unexpected file %q", file)
}
}


Binär
Visa fil


Binär
Visa fil


Binär
Visa fil


Laddar…
Avbryt
Spara