Skip to content

Commit

Permalink
Add support for 32-bit ARM CPUs.
Browse files Browse the repository at this point in the history
  • Loading branch information
orrc committed Jan 27, 2021
1 parent f630639 commit 810836d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@ private static String getArchitecture(String arch) throws InstallationFailedExce
if (value.contains("amd64") || value.contains("86_64")) {
return "amd64";
}
if (value.contains("aarch64")) {
// There seems to be no canonical documentation on what the `os.arch` values are for different ARM CPU types,
// and presumably there's no real guarantee of consistency between JVM vendors anyway.
// It _seems_ to be `aarch64` and `arm` for 64- and 32-bit, but let's also have some reasonable fallbacks…
if (value.contains("aarch64") || value.contains("arm64")) {
return "arm64";
}
if (value.contains("aarch32") || value.contains("arm")) {
return "armv6l";
}
if (value.contains("86")) {
return "386";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.junit.Test;

import javax.annotation.Nullable;

import static org.jenkinsci.plugins.golang.GolangInstaller.GolangInstallable;
import static org.jenkinsci.plugins.golang.GolangInstaller.GolangRelease;
import static org.jenkinsci.plugins.golang.GolangInstaller.InstallationFailedException;
Expand All @@ -14,6 +16,7 @@ public class GolangInstallerTest {
private static final GolangInstallable FREEBSD_64 = createPackage("freebsd", "amd64");
private static final GolangInstallable LINUX_32 = createPackage("linux", "386");
private static final GolangInstallable LINUX_64 = createPackage("linux", "amd64");
private static final GolangInstallable LINUX_ARM32 = createPackage("linux", "armv6l");
private static final GolangInstallable LINUX_ARM64 = createPackage("linux", "arm64");
private static final GolangInstallable OS_X_10_6_32 = createPackage("darwin", "386", "10.6");
private static final GolangInstallable OS_X_10_6_64 = createPackage("darwin", "amd64", "10.6");
Expand Down Expand Up @@ -68,18 +71,54 @@ public void testUnsupportedFreeBsd32BitInstallation() throws InstallationFailedE
// Then an exception should be thrown, as there is no 32-bit package
}

@Test
public void testLinuxArm32BitInstallation() throws InstallationFailedException {
// Given we have configured a release we want to install
GolangRelease release = createReleaseInfo();

// When we try to get the install package for Linux ARM 32-bit (aka `arm`)
GolangInstallable pkg = GolangInstaller.getInstallCandidate(release, "linux", "arm", "5.4.0");

// Then we should get the correct Linux ARM 32-bit package
assertEquals("Got unexpected package", LINUX_ARM32, pkg);
}

@Test
public void testLinuxArm32BitInstallationAlias() throws InstallationFailedException {
// Given we have configured a release we want to install
GolangRelease release = createReleaseInfo();

// When we try to get the install package for Linux ARM 32-bit, with the CPU value `aarch32`
GolangInstallable pkg = GolangInstaller.getInstallCandidate(release, "linux", "aarch32", "5.4.0");

// Then we should get the correct Linux ARM 32-bit package
assertEquals("Got unexpected package", LINUX_ARM32, pkg);
}

@Test
public void testLinuxAarch64BitInstallation() throws InstallationFailedException {
// Given we have configured a release we want to install
GolangRelease release = createReleaseInfo();

// When we try to get the install package for Ubuntu ARM 64-bit (aka `aarch64`)
// When we try to get the install package for Linux ARM 64-bit (aka `aarch64`)
GolangInstallable pkg = GolangInstaller.getInstallCandidate(release, "linux", "aarch64", "5.4.0");

// Then we should get the correct Linux ARM 64-bit package
assertEquals("Got unexpected package", LINUX_ARM64, pkg);
}

@Test
public void testLinuxArm64BitInstallationAlias() throws InstallationFailedException {
// Given we have configured a release we want to install
GolangRelease release = createReleaseInfo();

// When we try to get the install package for Linux ARM 64-bit, with the CPU value `arm64`
GolangInstallable pkg = GolangInstaller.getInstallCandidate(release, "linux", "arm64", "5.4.0");

// Then we should get the correct Linux ARM 64-bit package
assertEquals("Got unexpected package", LINUX_ARM64, pkg);
}

@Test
public void testLatestGo15PackageForOsXVersionReturned() throws InstallationFailedException {
// Given we have configured a Go 1.5 release we want to install
Expand Down Expand Up @@ -164,7 +203,7 @@ public void testUnsupportedOsXVersion() throws InstallationFailedException {
}

private static GolangRelease createReleaseInfo() {
return createReleaseInfo(FREEBSD_32, FREEBSD_64, LINUX_32, LINUX_64, LINUX_ARM64,
return createReleaseInfo(FREEBSD_32, FREEBSD_64, LINUX_32, LINUX_64, LINUX_ARM32, LINUX_ARM64,
OS_X_10_6_32, OS_X_10_6_64, OS_X_10_8_32, OS_X_10_8_64);
}

Expand All @@ -174,16 +213,25 @@ private static GolangRelease createReleaseInfo(GolangInstallable... releases) {
return release;
}

/**
* @param os The OS value used in a Go archive filename.
* @param arch The CPU architecture value used in a Go archive filename.
*/
private static GolangInstallable createPackage(String os, String arch) {
return createPackage(os, arch, null);
}

private static GolangInstallable createPackage(String os, String arch, String osxVersion) {
/**
* @param os The OS value used in a Go archive filename.
* @param arch The CPU architecture value used in a Go archive filename.
* @param osxVersion Mac OS X version name.
*/
private static GolangInstallable createPackage(String os, String arch, @Nullable String osxVersion) {
GolangInstallable pkg = new GolangInstallable();
pkg.os = os;
pkg.arch = arch;
pkg.osxversion = osxVersion;
return pkg;
}

}
}

0 comments on commit 810836d

Please sign in to comment.