Skip to content

Support/fix cross compilation goroot #35

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

Merged
merged 2 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint
* [Contact Information](#contact-information)

# Install
Recommended way to install is:
```bash
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
```

You can also install it by brew:
```bash
brew install golangci/tap/golangci-lint
```

Check the [releases page](https://github.com/golangci/golangci-lint/releases) to fix the version.

# Demo
Example of output:
![Screenshot of sample output](docs/run_screenshot.png)
Expand Down
25 changes: 25 additions & 0 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -175,7 +176,31 @@ func buildSSAProgram(ctx context.Context, lprog *loader.Program) *ssa.Program {
return ssaProg
}

func discoverGoRoot() (string, error) {
goroot := os.Getenv("GOROOT")
if goroot != "" {
return goroot, nil
}

output, err := exec.Command("go", "env", "GOROOT").Output()
if err != nil {
return "", fmt.Errorf("can't execute go env GOROOT: %s", err)
}

return strings.TrimSpace(string(output)), nil
}

func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config) (*golinters.Context, error) {
// Set GOROOT to have working cross-compilation: cross-compiled binaries
// have invalid GOROOT. XXX: can't use runtime.GOROOT().
goroot, err := discoverGoRoot()
if err != nil {
return nil, fmt.Errorf("can't discover GOROOT: %s", err)
}
os.Setenv("GOROOT", goroot)
build.Default.GOROOT = goroot
logrus.Infof("set GOROOT=%q", goroot)

args := cfg.Run.Args
if len(args) == 0 {
args = []string{"./..."}
Expand Down