Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Support user-specified go executable
Browse files Browse the repository at this point in the history
  • Loading branch information
blindpirate committed Jan 14, 2017
1 parent dc58454 commit a0dabd7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SourceCodeAnalysisTest extends GogradleModuleSupport {

@WithResource('golang-example-master.zip')
@Test
@AccessWeb
void 'imports should be parsed correctly'() {
// given
Mockito.when(resolvedDependency.getName()).thenReturn("name")
Expand All @@ -32,10 +33,6 @@ class SourceCodeAnalysisTest extends GogradleModuleSupport {

// then
def expectation = ['golang.org/x/tools', 'github.com/golang/example'] as Set
assert result.size() == expectation.size()
result.each {
assert expectation.contains(it.name)
}

assert result.collect { it.name } as Set == expectation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.github.blindpirate.gogradle.crossplatform.Os;
import com.github.blindpirate.gogradle.util.ExceptionHandler;
import com.github.blindpirate.gogradle.util.ProcessUtils;
import com.google.common.collect.ImmutableMap;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
Expand All @@ -25,6 +24,7 @@
import static com.github.blindpirate.gogradle.util.IOUtils.clearDirectory;
import static com.github.blindpirate.gogradle.util.IOUtils.ensureDirExistAndWritable;
import static com.github.blindpirate.gogradle.util.IOUtils.forceMkdir;
import static com.github.blindpirate.gogradle.util.MapUtils.asMap;
import static java.util.Arrays.asList;

@Singleton
Expand Down Expand Up @@ -54,9 +54,11 @@ public void build() {
String projectGopath = ensureProjectGopathWritable().toString();

List<String> args = asList(goBinary, "-o", outputFilePath);
Map<String, String> envs = ImmutableMap.of(
"GOPATH", projectGopath,
"GOROOT", gorootEnv);

Map<String, String> envs = asMap("GOPATH", projectGopath);
if (gorootEnv != null) {
envs.put("GOROOT", gorootEnv);
}

startBuild(args, envs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ private void resolveIfNecessary() {
if (resolved) {
return;
}
if (setting.getGoExecutable() != null) {
binaryPath = setting.getGoExecutable();
} else {
determineGoBinary();
}
resolved = true;
}

void determineGoBinary() {
Optional<String> versionOnHost = goVersionOnHost();

if (setting.getGoVersion() != null) {
Expand All @@ -97,8 +106,6 @@ private void resolveIfNecessary() {
fetchNewestStableVersion();
}
}

resolved = true;
}

private boolean specificVersionIsHostVersion(Optional<String> versionOnHost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ class DefaultGoBinaryManagerTest {
when(processResult.getStdout()).thenReturn('This is not a golang executable')
}

@Test
void 'user-specified go binary should be returned if it exists'() {
// given
when(setting.getGoExecutable()).thenReturn('/bin/go')
// then
assert manager.getBinaryPath() == '/bin/go'
assert manager.getGorootEnv() == null
}

@Test
void 'local go binary should be returned if it exists and no version specified'() {
// given
Expand Down

0 comments on commit a0dabd7

Please sign in to comment.