Skip to content

Commit

Permalink
Allow building on FreeBSD (#1091)
Browse files Browse the repository at this point in the history
* Allow building on FreeBSD

With this set of change, we are able to successfuly run:

```
./gradlew publishToMavenLocal -Dbuild.snapshot=false
```

This step is used in the OpenSearch repository context when building
plugins in the current state of the CI.

While here, reorder OS conditions alphabetically.

Before building, the openjdk14 package was installed and the environment
was adjusted to use it:

```
sudo pkg install openjdk14
export JAVA_HOME=/usr/local/openjdk14/
export PATH=$JAVA_HOME/bin:$PATH
```

Signed-off-by: Romain Tartière <[email protected]>

* Unbreak CI with FreeBSD support

Signed-off-by: dblock <[email protected]>

Co-authored-by: dblock <[email protected]>
  • Loading branch information
smortex and dblock authored Oct 14, 2021
1 parent 3779576 commit ea0fe7b
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 36 deletions.
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ if (project != rootProject) {

dependencies {
reaper project('reaper')
distribution project(':distribution:archives:windows-zip')
distribution project(':distribution:archives:darwin-tar')
distribution project(':distribution:archives:linux-tar')
distribution project(':distribution:archives:linux-arm64-tar')
distribution project(':distribution:archives:linux-tar')
distribution project(':distribution:archives:windows-zip')

integTestRuntimeOnly(project(":libs:opensearch-core"))
}
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/java/org/opensearch/gradle/Jdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public class Jdk implements Buildable, Iterable<File> {

private static final List<String> ALLOWED_ARCHITECTURES = Collections.unmodifiableList(Arrays.asList("aarch64", "x64"));
private static final List<String> ALLOWED_VENDORS = Collections.unmodifiableList(Arrays.asList("adoptium", "adoptopenjdk", "openjdk"));
private static final List<String> ALLOWED_PLATFORMS = Collections.unmodifiableList(Arrays.asList("darwin", "linux", "windows", "mac"));
private static final List<String> ALLOWED_PLATFORMS = Collections.unmodifiableList(
Arrays.asList("darwin", "freebsd", "linux", "mac", "windows")
);
private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)(\\.\\d+\\.\\d+)?\\+(\\d+(?:\\.\\d+)?)(@([a-f0-9]{32}))?");
private static final Pattern LEGACY_VERSION_PATTERN = Pattern.compile("(\\d)(u\\d+)\\+(b\\d+?)(@([a-f0-9]{32}))?");

Expand Down
28 changes: 19 additions & 9 deletions buildSrc/src/main/java/org/opensearch/gradle/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,39 @@
import java.util.function.Supplier;

public enum OS {
WINDOWS,
FREEBSD,
LINUX,
MAC,
LINUX;
WINDOWS;

public static OS current() {
String os = System.getProperty("os.name", "");
if (os.startsWith("Windows")) {
return OS.WINDOWS;
if (os.startsWith("FreeBSD")) {
return OS.FREEBSD;
}
if (os.startsWith("Linux") || os.startsWith("LINUX")) {
return OS.LINUX;
}
if (os.startsWith("Mac")) {
return OS.MAC;
}
if (os.startsWith("Windows")) {
return OS.WINDOWS;
}
throw new IllegalStateException("Can't determine OS from: " + os);
}

public static class Conditional<T> {

private final Map<OS, Supplier<T>> conditions = new HashMap<>();

public Conditional<T> onWindows(Supplier<T> supplier) {
conditions.put(WINDOWS, supplier);
public Conditional<T> onLinux(Supplier<T> supplier) {
conditions.put(LINUX, supplier);
return this;
}

public Conditional<T> onLinux(Supplier<T> supplier) {
conditions.put(LINUX, supplier);
public Conditional<T> onFreeBSD(Supplier<T> supplier) {
conditions.put(FREEBSD, supplier);
return this;
}

Expand All @@ -76,8 +80,14 @@ public Conditional<T> onMac(Supplier<T> supplier) {
}

public Conditional<T> onUnix(Supplier<T> supplier) {
conditions.put(MAC, supplier);
conditions.put(FREEBSD, supplier);
conditions.put(LINUX, supplier);
conditions.put(MAC, supplier);
return this;
}

public Conditional<T> onWindows(Supplier<T> supplier) {
conditions.put(WINDOWS, supplier);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
public class OpenSearchDistribution implements Buildable, Iterable<File> {

public enum Platform {
DARWIN,
FREEBSD,
LINUX,
WINDOWS,
DARWIN;
WINDOWS;

@Override
public String toString() {
Expand Down Expand Up @@ -85,9 +86,10 @@ public boolean shouldExtract() {

// package private to tests can use
public static final Platform CURRENT_PLATFORM = OS.<Platform>conditional()
.onFreeBSD(() -> Platform.FREEBSD)
.onLinux(() -> Platform.LINUX)
.onWindows(() -> Platform.WINDOWS)
.onMac(() -> Platform.DARWIN)
.onWindows(() -> Platform.WINDOWS)
.supply();

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public static String getBundledJdk(final String platform) {
case "darwin": // fall trough
case "mac":
return bundledJdkDarwin;
case "freebsd":
return bundledJdkFreeBSD;
case "linux":
return bundledJdkLinux;
case "windows":
Expand All @@ -79,6 +81,7 @@ public static Map<String, String> getVersions() {
private static final String opensearch;
private static final String lucene;
private static final String bundledJdkDarwin;
private static final String bundledJdkFreeBSD;
private static final String bundledJdkLinux;
private static final String bundledJdkWindows;
private static final String bundledJdkVendor;
Expand All @@ -91,6 +94,7 @@ public static Map<String, String> getVersions() {
bundledJdkVendor = props.getProperty("bundled_jdk_vendor");
final String bundledJdk = props.getProperty("bundled_jdk");
bundledJdkDarwin = props.getProperty("bundled_jdk_darwin", bundledJdk);
bundledJdkFreeBSD = props.getProperty("bundled_jdk_freebsd", bundledJdk);
bundledJdkLinux = props.getProperty("bundled_jdk_linux", bundledJdk);
bundledJdkWindows = props.getProperty("bundled_jdk_windows", bundledJdk);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static List<DistributionProject> resolveArchiveProjects(File checkoutDir
projects.addAll(asList("deb", "rpm"));

if (bwcVersion.onOrAfter("7.0.0")) { // starting with 7.0 we bundle a jdk which means we have platform-specific archives
projects.addAll(asList("windows-zip", "darwin-tar", "linux-tar"));
projects.addAll(asList("darwin-tar", "linux-tar", "windows-tar"));
} else { // prior to 7.0 we published only a single zip and tar archives
projects.addAll(asList("zip", "tar"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testUnknownPlatform() {
"11.0.2+33",
"unknown",
"x64",
"unknown platform [unknown] for jdk [testjdk], must be one of [darwin, linux, windows, mac]"
"unknown platform [unknown] for jdk [testjdk], must be one of [darwin, freebsd, linux, mac, windows]"
);
}

Expand Down
38 changes: 26 additions & 12 deletions distribution/archives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,31 @@ distribution_archives {
}
}

windowsZip {
archiveClassifier = 'windows-x64'
darwinTar {
archiveClassifier = 'darwin-x64'
content {
archiveFiles(modulesFiles('windows-x64'), 'zip', 'windows', 'x64', true)
archiveFiles(modulesFiles('darwin-x64'), 'tar', 'darwin', 'x64', true)
}
}

noJdkWindowsZip {
archiveClassifier = 'no-jdk-windows-x64'
noJdkDarwinTar {
archiveClassifier = 'no-jdk-darwin-x64'
content {
archiveFiles(modulesFiles('windows-x64'), 'zip', 'windows', 'x64', false)
archiveFiles(modulesFiles('darwin-x64'), 'tar', 'darwin', 'x64', false)
}
}

darwinTar {
archiveClassifier = 'darwin-x64'
freebsdTar {
archiveClassifier = 'freebsd-x64'
content {
archiveFiles(modulesFiles('darwin-x64'), 'tar', 'darwin', 'x64', true)
archiveFiles(modulesFiles('freebsd-x64'), 'tar', 'freebsd', 'x64', false)
}
}

noJdkDarwinTar {
archiveClassifier = 'no-jdk-darwin-x64'
noJdkFreebsdTar {
archiveClassifier = 'no-jdk-freebsd-x64'
content {
archiveFiles(modulesFiles('darwin-x64'), 'tar', 'darwin', 'x64', false)
archiveFiles(modulesFiles('freebsd-x64'), 'tar', 'freebsd', 'x64', false)
}
}

Expand All @@ -136,6 +136,20 @@ distribution_archives {
archiveFiles(modulesFiles('linux-x64'), 'tar', 'linux', 'x64', false)
}
}

windowsZip {
archiveClassifier = 'windows-x64'
content {
archiveFiles(modulesFiles('windows-x64'), 'zip', 'windows', 'x64', true)
}
}

noJdkWindowsZip {
archiveClassifier = 'no-jdk-windows-x64'
content {
archiveFiles(modulesFiles('windows-x64'), 'zip', 'windows', 'x64', false)
}
}
}

subprojects {
Expand Down
14 changes: 7 additions & 7 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {

// Setup all required JDKs
project.jdks {
['darwin', 'windows', 'linux'].each { platform ->
['darwin', 'linux', 'windows'].each { platform ->
(platform == 'linux' ? ['x64', 'aarch64'] : ['x64']).each { architecture ->
"bundled_${platform}_${architecture}" {
it.platform = platform
Expand Down Expand Up @@ -353,7 +353,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
}
def buildModules = buildModulesTaskProvider
List excludePlatforms = ['linux-x64', 'linux-arm64', 'windows-x64', 'darwin-x64']
List excludePlatforms = ['darwin-x64', 'freebsd-x64', 'linux-x64', 'linux-arm64', 'windows-x64']
if (platform != null) {
excludePlatforms.remove(excludePlatforms.indexOf(platform))
} else {
Expand Down Expand Up @@ -621,13 +621,13 @@ subprojects {
}
}

['archives:windows-zip',
'archives:darwin-tar',
['archives:darwin-tar',
'archives:integ-test-zip',
'archives:linux-arm64-tar',
'archives:linux-tar',
'archives:integ-test-zip',
'packages:rpm', 'packages:deb',
'packages:arm64-rpm', 'packages:arm64-deb'
'archives:windows-zip',
'packages:arm64-rpm', 'packages:arm64-deb',
'packages:rpm', 'packages:deb'
].forEach { subName ->
Project subproject = project("${project.path}:${subName}")
Configuration configuration = configurations.create(subproject.name)
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ List projects = [
'distribution:archives:no-jdk-windows-zip',
'distribution:archives:darwin-tar',
'distribution:archives:no-jdk-darwin-tar',
'distribution:archives:freebsd-tar',
'distribution:archives:no-jdk-freebsd-tar',
'distribution:archives:linux-arm64-tar',
'distribution:archives:linux-tar',
'distribution:archives:no-jdk-linux-tar',
Expand Down

0 comments on commit ea0fe7b

Please sign in to comment.