From 6869e5ac8758e88635ac31c3964e5ba9753efbc0 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Sat, 16 Jul 2022 17:14:59 -0700 Subject: [PATCH 1/3] Add support for ppc64, ppc64le and riscv64 architectures Signed-off-by: Daniel Widdis --- .../org/opensearch/gradle/Architecture.java | 3 ++ .../opensearch/gradle/ArchitectureTests.java | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java diff --git a/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java b/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java index 38d6db8c9916e..2c70c4fbfc8de 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java @@ -42,6 +42,9 @@ public static Architecture current() { switch (architecture) { case "amd64": case "x86_64": + case "ppc64": + case "ppc64le": + case "riscv64": return X64; case "aarch64": return ARM64; diff --git a/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java b/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java new file mode 100644 index 0000000000000..43390b6c3ce40 --- /dev/null +++ b/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java @@ -0,0 +1,52 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.gradle; + +import org.opensearch.gradle.test.GradleUnitTestCase; + +public class ArchitectureTests extends GradleUnitTestCase { + + final String architecture = System.getProperty("os.arch", ""); + + public void testCurrentArchitecture() { + assertEquals(Architecture.X64, currentArchitecture("amd64")); + assertEquals(Architecture.X64, currentArchitecture("x86_64")); + assertEquals(Architecture.X64, currentArchitecture("ppc64")); + assertEquals(Architecture.X64, currentArchitecture("ppc64le")); + assertEquals(Architecture.X64, currentArchitecture("riscv64")); + + assertEquals(Architecture.ARM64, currentArchitecture("aarch64")); + } + + public void testInvalidCurrentArchitecture() { + assertThrows( + "can not determine architecture from [", + IllegalArgumentException.class, + () -> currentArchitecture("fooBar64") + ); + } + + /** + * Determines the return value of {@link Architecture#current()} based on a string representing a potential OS Architecture. + * + * @param osArchToTest An expected value of the {@code os.arch} system property on another architecture. + * @return the value of the {@link Architecture} enum which would have resulted with the given value. + * @throws IllegalArgumentException if the string is not mapped to a value of the {@link Architecture} enum. + */ + private Architecture currentArchitecture(String osArchToTest) throws IllegalArgumentException { + // Test new architecture + System.setProperty("os.arch", osArchToTest); + try { + return Architecture.current(); + } finally { + // Restore actual architecture property value + System.setProperty("os.arch", this.architecture); + } + } +} From 33d4253ac7cc581ce4d3c7be4f49ed5815b29f7b Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Sat, 16 Jul 2022 17:38:40 -0700 Subject: [PATCH 2/3] Gradle spotlessApply Signed-off-by: Daniel Widdis --- .../test/java/org/opensearch/gradle/ArchitectureTests.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java b/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java index 43390b6c3ce40..ba4dadf0d6b6a 100644 --- a/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java +++ b/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java @@ -25,11 +25,7 @@ public void testCurrentArchitecture() { } public void testInvalidCurrentArchitecture() { - assertThrows( - "can not determine architecture from [", - IllegalArgumentException.class, - () -> currentArchitecture("fooBar64") - ); + assertThrows("can not determine architecture from [", IllegalArgumentException.class, () -> currentArchitecture("fooBar64")); } /** From a4a92c6cce66422350af923b345602fc719026f7 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Sat, 16 Jul 2022 22:27:54 -0700 Subject: [PATCH 3/3] Don't use X86 for non-x86 arhitectures Signed-off-by: Daniel Widdis --- .../java/org/opensearch/gradle/Architecture.java | 12 ++++++++---- .../org/opensearch/gradle/ArchitectureTests.java | 7 +++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java b/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java index 2c70c4fbfc8de..4022362ba18a4 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/Architecture.java @@ -35,19 +35,23 @@ public enum Architecture { X64, - ARM64; + ARM64, + PPC, + RISCV; public static Architecture current() { final String architecture = System.getProperty("os.arch", ""); switch (architecture) { case "amd64": case "x86_64": - case "ppc64": - case "ppc64le": - case "riscv64": return X64; case "aarch64": return ARM64; + case "ppc64": + case "ppc64le": + return PPC; + case "riscv64": + return RISCV; default: throw new IllegalArgumentException("can not determine architecture from [" + architecture + "]"); } diff --git a/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java b/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java index ba4dadf0d6b6a..eae333b59457e 100644 --- a/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java +++ b/buildSrc/src/test/java/org/opensearch/gradle/ArchitectureTests.java @@ -17,11 +17,10 @@ public class ArchitectureTests extends GradleUnitTestCase { public void testCurrentArchitecture() { assertEquals(Architecture.X64, currentArchitecture("amd64")); assertEquals(Architecture.X64, currentArchitecture("x86_64")); - assertEquals(Architecture.X64, currentArchitecture("ppc64")); - assertEquals(Architecture.X64, currentArchitecture("ppc64le")); - assertEquals(Architecture.X64, currentArchitecture("riscv64")); - assertEquals(Architecture.ARM64, currentArchitecture("aarch64")); + assertEquals(Architecture.PPC, currentArchitecture("ppc64")); + assertEquals(Architecture.PPC, currentArchitecture("ppc64le")); + assertEquals(Architecture.RISCV, currentArchitecture("riscv64")); } public void testInvalidCurrentArchitecture() {