Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not use only hardcoded "go" #97

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
log.Println("[INFO] Building Caddy")

// tidy the module to ensure go.mod and go.sum are consistent with the module prereq
tidyCmd := buildEnv.newCommand("go", "mod", "tidy")
tidyCmd := buildEnv.newCommand(GetGo(), "mod", "tidy")
if err := buildEnv.runCommand(ctx, tidyCmd, b.TimeoutGet); err != nil {
return err
}

// compile
cmd := buildEnv.newCommand("go", "build",
cmd := buildEnv.newCommand(GetGo(), "build",
"-o", absOutputFile,
)
if b.Debug {
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
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", "-json", "all")
cmd := exec.Command(xcaddy.GetGo(), "list", "-m", "-json", "all")
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) {

// initialize the go module
log.Println("[INFO] Initializing Go module")
cmd := env.newCommand("go", "mod", "init", "caddy")
cmd := env.newCommand(GetGo(), "mod", "init", "caddy")
err = env.runCommand(ctx, cmd, 10*time.Second)
if err != nil {
return nil, err
Expand All @@ -110,7 +110,7 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) {
replaced := make(map[string]string)
for _, r := range b.Replacements {
log.Printf("[INFO] Replace %s => %s", r.Old.String(), r.New.String())
cmd := env.newCommand("go", "mod", "edit",
cmd := env.newCommand(GetGo(), "mod", "edit",
"-replace", fmt.Sprintf("%s=%s", r.Old.Param(), r.New.Param()))
err := env.runCommand(ctx, cmd, 10*time.Second)
if err != nil {
Expand Down Expand Up @@ -263,9 +263,9 @@ func (env environment) execGoGet(ctx context.Context, modulePath, moduleVersion,
// distinct argument, so we're using an if statement to avoid it.
var cmd *exec.Cmd
if caddy != "" {
cmd = env.newCommand("go", "get", "-d", "-v", mod, caddy)
cmd = env.newCommand(GetGo(), "get", "-d", "-v", mod, caddy)
} else {
cmd = env.newCommand("go", "get", "-d", "-v", mod)
cmd = env.newCommand(GetGo(), "get", "-d", "-v", mod)
}

return env.runCommand(ctx, cmd, env.timeoutGoGet)
Expand Down
2 changes: 1 addition & 1 deletion platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Platform struct {
// SupportedPlatforms runs `go tool dist list` to make
// a list of possible build targets.
func SupportedPlatforms() ([]Compile, error) {
out, err := exec.Command("go", "tool", "dist", "list", "-json").Output()
out, err := exec.Command(GetGo(), "tool", "dist", "list", "-json").Output()
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions sdk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package xcaddy

import "os"

func GetGo() string {
sdk := os.Getenv("XCADDY_SDK")
kmpm marked this conversation as resolved.
Show resolved Hide resolved
if sdk == "" {
return "go"
}
return sdk
}