Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
Add race detector support
Browse files Browse the repository at this point in the history
Fixes #96

Adds the race detector you all know and love to gb.

Todo:
- [ ] Add support for rebuilding stdlib if -race support is not present.
- [ ] Add interlocks to restrict the race detector to certain amd64 for freebsd, linux, darwin, and linux.
- [ ] Make all binaries dependant on runtime/race.
- [ ] Add tests at cmd/gb as well as gb and gb/test.
  • Loading branch information
davecheney committed Dec 15, 2015
1 parent 73854a9 commit cea3e3d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
1 change: 1 addition & 0 deletions cmd/gb/gb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestMain(m *testing.M) {
// Don't let these environment variables confuse the test.
os.Unsetenv("GOBIN")
os.Unsetenv("GOPATH")
os.Unsetenv("DEBUG")

r := m.Run()
os.Exit(r)
Expand Down
37 changes: 20 additions & 17 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,30 @@ func Tags(tags ...string) func(*Context) error {
}
}

// Gcflags appends flags to the list passed to the compiler.
func Gcflags(flags ...string) func(*Context) error {
return func(c *Context) error {
c.gcflags = append(c.gcflags, flags...)
return nil
}
}

// Ldflags appends flags to the list passed to the linker.
func Ldflags(flags ...string) func(*Context) error {
return func(c *Context) error {
c.ldflags = append(c.ldflags, flags...)
return nil
}
}

// WithRace enables the race detector and adds the tag "race" to
// the Context build tags.
func WithRace(c *Context) error {
c.race = true
return Tags("race")(c)
Tags("race")(c)
Gcflags("-race")(c)
Ldflags("-race")(c)
return nil
}

// NewContext returns a new build context from this project.
Expand Down Expand Up @@ -149,22 +168,6 @@ func (p *Project) NewContext(opts ...func(*Context) error) (*Context, error) {
return &ctx, nil
}

// Gcflags sets options passed to the compiler.
func Gcflags(flags ...string) func(*Context) error {
return func(c *Context) error {
c.gcflags = flags
return nil
}
}

// Ldflags sets options passed to the linker.
func Ldflags(flags ...string) func(*Context) error {
return func(c *Context) error {
c.ldflags = flags
return nil
}
}

// IncludePaths returns the include paths visible in this context.
func (c *Context) IncludePaths() []string {
return []string{
Expand Down
18 changes: 18 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,36 @@ func TestContextOptions(t *testing.T) {
ctx: Context{buildtags: []string{"foo"}},
fn: Tags("bar"),
expect: matches(Context{buildtags: []string{"foo", "bar"}}),
}, {
fn: Gcflags("foo"),
expect: matches(Context{gcflags: []string{"foo"}}),
}, {
ctx: Context{gcflags: []string{"foo"}},
fn: Gcflags("bar"),
expect: matches(Context{gcflags: []string{"foo", "bar"}}),
}, {
fn: Ldflags("foo"),
expect: matches(Context{ldflags: []string{"foo"}}),
}, {
ctx: Context{ldflags: []string{"foo"}},
fn: Ldflags("bar"),
expect: matches(Context{ldflags: []string{"foo", "bar"}}),
}, {
fn: WithRace,
expect: matches(Context{
buildtags: []string{"race"},
race: true,
gcflags: []string{"-race"},
ldflags: []string{"-race"},
}),
}, {
ctx: Context{buildtags: []string{"zzz"}},
fn: WithRace,
expect: matches(Context{
buildtags: []string{"zzz", "race"},
race: true,
gcflags: []string{"-race"},
ldflags: []string{"-race"},
}),
}}

Expand Down

0 comments on commit cea3e3d

Please sign in to comment.