From 4ce3d1db07a0768a0bb6bf64288fffff7eca5cdd Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sat, 9 May 2020 18:59:18 -0600 Subject: [PATCH] Add race detector support; update readme --- README.md | 10 +++++----- builder.go | 4 ++++ cmd/xcaddy/main.go | 7 ++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e20c1f7..a713468 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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", }, }, } diff --git a/builder.go b/builder.go index e8f3247..ed21912 100644 --- a/builder.go +++ b/builder.go @@ -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 @@ -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 { diff --git a/cmd/xcaddy/main.go b/cmd/xcaddy/main.go index c970d09..81ae3ed 100644 --- a/cmd/xcaddy/main.go +++ b/cmd/xcaddy/main.go @@ -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()) @@ -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 { @@ -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 {