nmindex: listError

This commit is contained in:
xushiwei
2024-04-20 10:56:21 +08:00
parent 0e0054779b
commit 0b1f36b6fe
2 changed files with 21 additions and 3 deletions

View File

@@ -61,7 +61,7 @@ func (p *IndexBuilder) IndexDir(fromDir, toDir string, progress func(path string
}
fname := d.Name()
switch filepath.Ext(fname) {
case ".a", ".dylib", ".so", ".dll", ".lib":
case ".a", ".dylib", ".tbd", ".so", ".dll", ".lib":
progress(path)
hash := md5.Sum([]byte(path))
hashStr := base64.RawURLEncoding.EncodeToString(hash[:])

View File

@@ -79,15 +79,33 @@ type ObjectFile struct {
// List lists symbols in an archive file.
func (p *Cmd) List(arfile string) (items []*ObjectFile, err error) {
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := exec.Command(p.app, arfile)
cmd.Stdout = &stdout
cmd.Stderr = os.Stderr
if err = cmd.Run(); err != nil {
cmd.Stderr = &stderr
err = cmd.Run()
if stderr.Len() > 0 {
listError(stderr.Bytes())
}
if err != nil {
return
}
return listOutput(stdout.Bytes())
}
func listError(data []byte) {
sep := []byte{'\n'}
nosym := []byte(": no symbols")
lines := bytes.Split(data, sep)
for _, line := range lines {
if len(line) == 0 || bytes.HasSuffix(line, nosym) {
continue
}
os.Stderr.Write(line)
os.Stderr.Write(sep)
}
}
func listOutput(data []byte) (items []*ObjectFile, err error) {
sep := []byte{'\n'}
item := &ObjectFile{}