Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Added support for building with gotip
Browse files Browse the repository at this point in the history
Fixes #92
  • Loading branch information
pieterclaerhout committed May 4, 2020
1 parent 84b7c56 commit beb256b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ When you create a new project or init an existing one, a `go-james.json` file wi
"ld_flags_linux": [],
"extra_args": [
"-trimpath"
]
],
"use_gotip": false
},
"run": {
"environ": {
Expand Down Expand Up @@ -408,6 +409,7 @@ When you create a new project or init an existing one, a `go-james.json` file wi
* `ld_flags_linux`: the linker flags you want to use for building for `linux`. You can find more info about these flags [here](https://golang.org/cmd/link/).
* `ld_flags_windows`: the linker flags you want to use for building for `windows`. You can find more info about these flags [here](https://golang.org/cmd/link/).
* `extra_args`: contains any extra command-line parameters you want to add to the `go build` command when you run `go-james build`.
* `use_gotip`: setting this to true uses `gotip` to compile instead of the regular `go`command. Make sure you have [`gotip`](https://pkg.go.dev/golang.org/dl/gotip?tab=doc) installed.

### Run Config

Expand Down
3 changes: 2 additions & 1 deletion go-james.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"ld_flags_windows": [],
"ld_flags_darwin": [],
"ld_flags_linux": [],
"extra_args": ["-trimpath"]
"extra_args": ["-trimpath"],
"use_gotip": false
},
"run": {
"environ": {}
Expand Down
21 changes: 17 additions & 4 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"runtime"
"strconv"
"strings"
"sync"

"github.com/kballard/go-shellquote"
"github.com/pieterclaerhout/go-james"
Expand All @@ -14,6 +15,8 @@ import (
"github.com/pkg/errors"
)

var once sync.Once

// Builder implements the "build" command
type Builder struct {
common.CommandRunner
Expand Down Expand Up @@ -68,10 +71,10 @@ func (builder Builder) Execute(project common.Project, cfg config.Config) error
}

if builder.Verbose {
builder.LogInfo("> Compiling for", builder.GOOS+"/"+builder.GOARCH, "using", builder.goVersion())
builder.LogInfo("> Compiling for", builder.GOOS+"/"+builder.GOARCH, "using", builder.goVersion(cfg))
}

buildCmd := []string{"go", "build"}
buildCmd := []string{builder.goExecuteable(cfg), "build"}

if builder.Verbose {
buildCmd = append(buildCmd, "-v")
Expand Down Expand Up @@ -187,9 +190,9 @@ func (builder Builder) ldFlagForVersionInfo(packageName string, name string, val

}

func (builder Builder) goVersion() string {
func (builder Builder) goVersion(cfg config.Config) string {

result, err := builder.RunReturnOutput([]string{"go", "version"}, "", map[string]string{})
result, err := builder.RunReturnOutput([]string{builder.goExecuteable(cfg), "version"}, "", map[string]string{})
if err != nil {
builder.LogError("Failed to get Go version:", err)
return ""
Expand Down Expand Up @@ -230,3 +233,13 @@ func (builder Builder) outputPath(cfg config.Config) (string, error) {
return outputPath, nil

}

func (builder Builder) goExecuteable(cfg config.Config) string {
if cfg.Build.UseGotip {
once.Do(func() {
builder.LogWarn("> Using gotip to build")
})
return "gotip"
}
return "go"
}
5 changes: 5 additions & 0 deletions internal/common/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func (logging Logging) LogInfo(args ...interface{}) {
log.Info(args...)
}

// LogWarn logs a warning message
func (logging Logging) LogWarn(args ...interface{}) {
log.Warn(args...)
}

// LogError logs an error
func (logging Logging) LogError(args ...interface{}) {
log.Error(args...)
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type BuildConfig struct {
LDFlagsLinux []string `json:"ld_flags_linux"` // The ldflags to pass to the build command for Linux
LDFlagsWindows []string `json:"ld_flags_windows"` // The ldflags to pass to the build command for Windows
ExtraArgs []string `json:"extra_args"` // The extra arguments to pass to the build command
UseGotip bool `json:"use_gotip"` // Use gotip to build instead of Go itself
}

// RunConfig contains the run specific configuration settings
Expand Down

0 comments on commit beb256b

Please sign in to comment.