Skip to content

Commit

Permalink
Add race detector support; update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed May 10, 2020
1 parent 1eaff74 commit 4ce3d1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ $ xcaddy build \
--with github.com/caddyserver/ntlm-transport

$ xcaddy build v2.0.1 \
--with github.com/caddyserver/ntlm-transport@v0.1.0
--with github.com/caddyserver/ntlm-transport@v0.1.1

$ xcaddy build \
--with github.com/caddyserver/ntlm-transport=../../my-fork

$ xcaddy build \
--with github.com/caddyserver/ntlm-transport@v0.1.0=../../my-fork
--with github.com/caddyserver/ntlm-transport@v0.1.1=../../my-fork
```

### For plugin development
Expand All @@ -90,18 +90,18 @@ $ xcaddy run
$ xcaddy run --config caddy.json
```


The race detector can be enabled by setting `CADDY_RACE_DETECTOR=1`.


## Library usage

```go
builder := xcaddy.Builder{
CaddyVersion: "v2.0.0-rc.1",
CaddyVersion: "v2.0.0",
Plugins: []xcaddy.Dependency{
{
ModulePath: "github.com/caddyserver/ntlm-transport",
Version: "v0.1.0",
Version: "v0.1.1",
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Builder struct {
Replacements []Replace `json:"replacements,omitempty"`
TimeoutGet time.Duration `json:"timeout_get,omitempty"`
TimeoutBuild time.Duration `json:"timeout_build,omitempty"`
RaceDetector bool `json:"race_detector,omitempty"`
}

// Build builds Caddy at the configured version with the
Expand Down Expand Up @@ -92,6 +93,9 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
"-ldflags", "-w -s", // trim debug symbols
"-trimpath",
)
if b.RaceDetector {
cmd.Args = append(cmd.Args, "-race")
}
cmd.Env = env
err = buildEnv.runCommand(ctx, cmd, b.TimeoutBuild)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion cmd/xcaddy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import (
"github.com/caddyserver/xcaddy"
)

var caddyVersion = os.Getenv("CADDY_VERSION")
var (
caddyVersion = os.Getenv("CADDY_VERSION")
raceDetector = os.Getenv("CADDY_RACE_DETECTOR") == "1"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -109,6 +112,7 @@ func runBuild(ctx context.Context, args []string) error {
CaddyVersion: caddyVersion,
Plugins: plugins,
Replacements: replacements,
RaceDetector: raceDetector,
}
err := builder.Build(ctx, output)
if err != nil {
Expand Down Expand Up @@ -190,6 +194,7 @@ func runDev(ctx context.Context, args []string) error {
{ModulePath: currentModule},
},
Replacements: replacements,
RaceDetector: raceDetector,
}
err = builder.Build(ctx, binOutput)
if err != nil {
Expand Down

0 comments on commit 4ce3d1d

Please sign in to comment.