From 049aa7c191085861d44d99f02e02064c7921790a Mon Sep 17 00:00:00 2001 From: peterz Date: Thu, 22 Feb 2024 11:15:19 +0300 Subject: [PATCH] Musl support --- __tests__/liberica.test.ts | 21 +++++++++++++-------- dist/main/index.js | 18 ++++++++++++++++-- src/liberica.ts | 18 ++++++++++++++++-- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/__tests__/liberica.test.ts b/__tests__/liberica.test.ts index ad3a742..48e8e1b 100644 --- a/__tests__/liberica.test.ts +++ b/__tests__/liberica.test.ts @@ -1,4 +1,5 @@ import * as liberica from '../src/liberica' +import * as c from '../src/constants' import * as path from 'path' import * as semver from 'semver' import {expect, test} from '@jest/globals' @@ -35,18 +36,22 @@ test('find latest JDK version', async () => { }, 30000) test('find asset URL', async () => { - await expectURL( - '17.0.10+13', - 'core', - 'bellsoft-liberica-vm-core-openjdk17.0.10' - ) + await expectURL('11.0.22+12', '', 'bellsoft-liberica-vm-openjdk11.0.22') await expectURL('17.0.10+13', 'std', 'bellsoft-liberica-vm-openjdk17.0.10') await expectURL( '21.0.2+14', - 'full', - 'bellsoft-liberica-vm-full-openjdk21.0.2' + 'core', + 'bellsoft-liberica-vm-core-openjdk21.0.2' ) - await expectURL('21.0.2+14', '', 'bellsoft-liberica-vm-openjdk21.0.2') + + if (!c.IS_LINUX) { + // This check can fail on Linux because there's no `full` version for aarch64 and musl + await expectURL( + '21.0.2+14', + 'full', + 'bellsoft-liberica-vm-full-openjdk21.0.2' + ) + } }, 10000) type verifier = ( diff --git a/dist/main/index.js b/dist/main/index.js index 30c225f..d8dc828 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -94349,6 +94349,7 @@ const c = __importStar(__nccwpck_require__(9042)); const semver = __importStar(__nccwpck_require__(1383)); const utils_1 = __nccwpck_require__(1314); const tool_cache_1 = __nccwpck_require__(7784); +const child_process_1 = __nccwpck_require__(2081); const LIBERICA_GH_USER = 'bell-sw'; const LIBERICA_RELEASES_REPO = 'LibericaNIK'; const LIBERICA_JDK_TAG_PREFIX = 'jdk-'; @@ -94409,8 +94410,21 @@ function determineToolName(javaVersion, version) { return `${LIBERICA_VM_PREFIX}${determineToolVersionPart(version)}openjdk${javaVersion}-${determinePlatformPart()}`; } function determinePlatformPart() { - // for linux-musl, return `linux-${c.JDK_ARCH}-musl` - return `${c.JDK_PLATFORM}-${c.GRAALVM_ARCH}`; + if (isMuslBasedLinux()) { + return `linux-${c.JDK_ARCH}-musl`; + } + else { + return `${c.JDK_PLATFORM}-${c.GRAALVM_ARCH}`; + } +} +function isMuslBasedLinux() { + if (c.IS_LINUX) { + const output = (0, child_process_1.spawnSync)('ldd', ['--version']).stderr.toString('utf8'); + if (output.indexOf('musl') > -1) { + return true; + } + } + return false; } function isDigit(c) { return c.charAt(0) >= '0' && c.charAt(0) <= '9'; diff --git a/src/liberica.ts b/src/liberica.ts index eb6bc41..532e60c 100644 --- a/src/liberica.ts +++ b/src/liberica.ts @@ -6,6 +6,7 @@ import { getMatchingTags } from './utils' import {downloadTool} from '@actions/tool-cache' +import {spawnSync} from 'child_process' const LIBERICA_GH_USER = 'bell-sw' const LIBERICA_RELEASES_REPO = 'LibericaNIK' @@ -96,8 +97,21 @@ function determineToolName(javaVersion: string, version: string) { } function determinePlatformPart() { - // for linux-musl, return `linux-${c.JDK_ARCH}-musl` - return `${c.JDK_PLATFORM}-${c.GRAALVM_ARCH}` + if (isMuslBasedLinux()) { + return `linux-${c.JDK_ARCH}-musl` + } else { + return `${c.JDK_PLATFORM}-${c.GRAALVM_ARCH}` + } +} + +function isMuslBasedLinux() { + if (c.IS_LINUX) { + const output = spawnSync('ldd', ['--version']).stderr.toString('utf8') + if (output.indexOf('musl') > -1) { + return true + } + } + return false } function isDigit(c: string) {