Skip to content

Commit

Permalink
Rename XCADDY_NO_BUILD to XCADDY_SKIP_CLEANUP
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Feb 5, 2021
1 parent cdd8596 commit e9fa593
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
4 changes: 2 additions & 2 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Builder struct {
TimeoutBuild time.Duration `json:"timeout_build,omitempty"`
RaceDetector bool `json:"race_detector,omitempty"`
SkipCleanup bool `json:"skip_cleanup,omitempty"`
NoBuild bool `json:"no_build,omitempty"`
SkipBuild bool `json:"skip_build,omitempty"`
}

// Build builds Caddy at the configured version with the
Expand Down Expand Up @@ -78,7 +78,7 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
}
defer buildEnv.Close()

if b.NoBuild {
if b.SkipBuild {
log.Printf("[INFO] Skipping build as requested")

return nil
Expand Down
34 changes: 10 additions & 24 deletions cmd/xcaddy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
var (
caddyVersion = os.Getenv("CADDY_VERSION")
raceDetector = os.Getenv("XCADDY_RACE_DETECTOR") == "1"
noBuild = os.Getenv("XCADDY_NO_BUILD") == "1"
skipCleanup = noBuild || os.Getenv("XCADDY_SKIP_CLEANUP") == "1"
skipBuild = os.Getenv("XCADDY_SKIP_BUILD") == "1"
skipCleanup = skipBuild || os.Getenv("XCADDY_SKIP_CLEANUP") == "1"
)

func main() {
Expand Down Expand Up @@ -113,7 +113,7 @@ func runBuild(ctx context.Context, args []string) error {
Replacements: replacements,
RaceDetector: raceDetector,
SkipCleanup: skipCleanup,
NoBuild: noBuild,
SkipBuild: skipBuild,
}
err := builder.Build(ctx, output)
if err != nil {
Expand Down Expand Up @@ -143,7 +143,7 @@ func getCaddyOutputFile() string {
if runtime.GOOS == "windows" {
return "caddy.exe"
}
return "." + string(filepath.Separator) + "caddy"
return "caddy"
}

func runDev(ctx context.Context, args []string) error {
Expand Down Expand Up @@ -177,7 +177,7 @@ func runDev(ctx context.Context, args []string) error {
// and since this tool is a carry-through for the user's actual
// go.mod, we need to transfer their replace directives through
// to the one we're making
cmd = exec.Command("go", "list", "-m", "-f={{if .Replace}}{{.Path}}=>{{.Replace}}{{end}}", "all")
cmd = exec.Command("go", "list", "-m", "-f={{if .Replace}}{{.Path}} => {{.Replace}}{{end}}", "all")
cmd.Stderr = os.Stderr
out, err = cmd.Output()
if err != nil {
Expand All @@ -188,14 +188,10 @@ func runDev(ctx context.Context, args []string) error {
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
continue
}

// adjust relative replacements in original module since our temporary module is in a different directory
if !filepath.IsAbs(parts[1]) {
parts[1] = filepath.Join(moduleDir, parts[1])
log.Printf("[INFO] Resolved relative replacement %s to %s", line, parts[1])
}

replacements = append(replacements, xcaddy.NewReplace(parts[0], parts[1]))
replacements = append(replacements, xcaddy.NewReplace(
strings.TrimSpace(parts[0]),
strings.TrimSpace(parts[1]),
))
}

// reconcile remaining path segments; for example if a module foo/a
Expand All @@ -219,23 +215,13 @@ func runDev(ctx context.Context, args []string) error {
Replacements: replacements,
RaceDetector: raceDetector,
SkipCleanup: skipCleanup,
NoBuild: noBuild,
SkipBuild: skipBuild,
}
err = builder.Build(ctx, binOutput)
if err != nil {
return err
}

if os.Getenv("XCADDY_SETCAP") == "1" {
cmd = exec.Command("sudo", "setcap", "cap_net_bind_service=+ep", binOutput)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Printf("[INFO] Setting capabilities (requires admin privileges): %v", cmd.Args)
if err = cmd.Run(); err != nil {
return err
}
}

log.Printf("[INFO] Running %v\n\n", append([]string{binOutput}, args...))

cmd = exec.Command(binOutput, args...)
Expand Down

0 comments on commit e9fa593

Please sign in to comment.