Skip to content

Commit

Permalink
Detect when binutils are not installed on OSX and skip the test.
Browse files Browse the repository at this point in the history
Fixes google#342.
  • Loading branch information
aalexand committed Apr 4, 2018
1 parent 36d5638 commit fce204b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ matrix:
- os: osx
osx_image: xcode8.3
go: master
- os: osx
env: SKIP_BINUTILS=1
go: master

addons:
apt:
Expand All @@ -51,7 +54,7 @@ addons:
before_install:
- go get -u github.com/golang/lint/golint honnef.co/go/tools/cmd/...
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install binutils ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" && -z $SKIP_BINUTILS ]]; then brew install binutils ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" && -z $SKIP_GRAPHVIZ ]]; then brew install graphviz; fi

script:
Expand Down
20 changes: 20 additions & 0 deletions internal/binutils/binutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ func (bu *Binutils) update(fn func(r *binrep)) {
bu.rep = r
}

// String returns string representation of the binutils state for debug logging.
func (bu *Binutils) String() string {
r := bu.get()
var llvmSymbolizer, addr2line, nm, objdump string
if r.llvmSymbolizerFound {
llvmSymbolizer = r.llvmSymbolizer
}
if r.addr2lineFound {
addr2line = r.addr2line
}
if r.nmFound {
nm = r.nm
}
if r.objdumpFound {
objdump = r.objdump
}
return fmt.Sprintf("llvm-symbolizer=%q addr2line=%q nm=%q objdump=%q fast=%t",
llvmSymbolizer, addr2line, nm, objdump, r.fast)
}

// SetFastSymbolization sets a toggle that makes binutils use fast
// symbolization (using nm), which is much faster than addr2line but
// provides only symbol name information (no file/line).
Expand Down
7 changes: 7 additions & 0 deletions internal/binutils/binutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ func TestMachoFiles(t *testing.T) {
if err != nil {
t.Fatalf("Open: unexpected error %v", err)
}
t.Logf("binutils: %v", bu)
if runtime.GOOS == "darwin" && !bu.rep.addr2lineFound && !bu.rep.llvmSymbolizerFound {
// On OSX user needs to install gaddr2line or llvm-symbolizer with
// Homebrew, skip the test when the environment doesn't have it
// installed.
t.Skip("couldn't find addr2line or gaddr2line")
}
defer f.Close()
syms, err := f.Symbols(nil, 0)
if err != nil {
Expand Down

0 comments on commit fce204b

Please sign in to comment.