echocat / gradle-golang-plugin

Gradle plugin to build, test and do other stuff of Golang projects.
https://github.com/echocat/gradle-golang-plugin
Mozilla Public License 2.0
44 stars 8 forks source link

Environment variables are not handled consistently for the Go executor(), breaks bootstrap Go functionality #21

Closed iamahern closed 7 years ago

iamahern commented 7 years ago

When you do not have Go installed on a system and you attempt to use a bootstrapGo root feature, execution will fail here:

ToolchainSettings.java

   @Nullable
    public String goBinaryVersionOf(Path goroot) {
        final Path goBinary = goBinaryOf(goroot);
        if (!isExecutable(goBinary)) {
            return null;
        }
        final String stdout;
        try {
            stdout = executor(goBinary)   ////////// ISSUE Here
                .argument("version")
                .execute()
                .getStdoutAsString()

With the exception:

Caused by: java.lang.IllegalStateException: Downloaded and extracted bootstrap to .../projects/serverutils/src/test_project/build/goRoot but it could not be validated as working go installation.

========

In other instances, the executor is initialized as follows:

            executor(toolchain.getGoBinary())
                .workingDirectory(build.getGopath())
                .env("GOPATH", build.getGopath())
                .env("GOROOT", toolchain.getGoroot())
                .env("GOOS", platform.getOperatingSystem().getNameInGo())
                .env("GOARCH", platform.getArchitecture().getNameInGo())
                .env("CGO_ENABLED", TRUE.equals(toolchain.getCgoEnabled()) ? "1" : "0")
                .arguments("build", "-o", targetBinaryFilename, dependency.getGroup())
                .execute();

I believe simply addint the 'GOROOT' setting will fix the problem: .env("GOROOT", toolchain.getGoroot())

blaubaer commented 7 years ago

Thank you very much for your input. This was already addressed by issue #18 I will release this as soon as possible.