Add race detector support; update readme

This commit is contained in:
Matthew Holt 2020-05-09 18:59:18 -06:00
parent 1eaff742db
commit 4ce3d1db07
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
3 changed files with 15 additions and 6 deletions

View file

@ -58,13 +58,13 @@ $ xcaddy build \
--with github.com/caddyserver/ntlm-transport --with github.com/caddyserver/ntlm-transport
$ xcaddy build v2.0.1 \ $ 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 \ $ xcaddy build \
--with github.com/caddyserver/ntlm-transport=../../my-fork --with github.com/caddyserver/ntlm-transport=../../my-fork
$ xcaddy build \ $ 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 ### For plugin development
@ -90,18 +90,18 @@ $ xcaddy run
$ xcaddy run --config caddy.json $ xcaddy run --config caddy.json
``` ```
The race detector can be enabled by setting `CADDY_RACE_DETECTOR=1`.
## Library usage ## Library usage
```go ```go
builder := xcaddy.Builder{ builder := xcaddy.Builder{
CaddyVersion: "v2.0.0-rc.1", CaddyVersion: "v2.0.0",
Plugins: []xcaddy.Dependency{ Plugins: []xcaddy.Dependency{
{ {
ModulePath: "github.com/caddyserver/ntlm-transport", ModulePath: "github.com/caddyserver/ntlm-transport",
Version: "v0.1.0", Version: "v0.1.1",
}, },
}, },
} }

View file

@ -40,6 +40,7 @@ type Builder struct {
Replacements []Replace `json:"replacements,omitempty"` Replacements []Replace `json:"replacements,omitempty"`
TimeoutGet time.Duration `json:"timeout_get,omitempty"` TimeoutGet time.Duration `json:"timeout_get,omitempty"`
TimeoutBuild time.Duration `json:"timeout_build,omitempty"` TimeoutBuild time.Duration `json:"timeout_build,omitempty"`
RaceDetector bool `json:"race_detector,omitempty"`
} }
// Build builds Caddy at the configured version with the // Build builds Caddy at the configured version with the
@ -92,6 +93,9 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
"-ldflags", "-w -s", // trim debug symbols "-ldflags", "-w -s", // trim debug symbols
"-trimpath", "-trimpath",
) )
if b.RaceDetector {
cmd.Args = append(cmd.Args, "-race")
}
cmd.Env = env cmd.Env = env
err = buildEnv.runCommand(ctx, cmd, b.TimeoutBuild) err = buildEnv.runCommand(ctx, cmd, b.TimeoutBuild)
if err != nil { if err != nil {

View file

@ -28,7 +28,10 @@ import (
"github.com/caddyserver/xcaddy" "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() { func main() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -109,6 +112,7 @@ func runBuild(ctx context.Context, args []string) error {
CaddyVersion: caddyVersion, CaddyVersion: caddyVersion,
Plugins: plugins, Plugins: plugins,
Replacements: replacements, Replacements: replacements,
RaceDetector: raceDetector,
} }
err := builder.Build(ctx, output) err := builder.Build(ctx, output)
if err != nil { if err != nil {
@ -190,6 +194,7 @@ func runDev(ctx context.Context, args []string) error {
{ModulePath: currentModule}, {ModulePath: currentModule},
}, },
Replacements: replacements, Replacements: replacements,
RaceDetector: raceDetector,
} }
err = builder.Build(ctx, binOutput) err = builder.Build(ctx, binOutput)
if err != nil { if err != nil {