From 72a2ba90fd13f69961eb4fbd2c7de57240f6320d Mon Sep 17 00:00:00 2001 From: aramisf Date: Sun, 30 Dec 2018 22:56:31 +0100 Subject: [PATCH 1/2] Adds support for OpenBSD. In order to download and unpack node source files under OpenBSD it is necessary to run the extraction into two steps. Since `tar` and `xz` are not integrated, the `-J` option is not available on OpenBSD default `tar` tool. This commit adds a test in order to figure this out, and handles the proper file extraction under OpenBSD. The previous behaviour for other Operating Systems should be untouched (more testing is welcome). This commit does not yet handles the next issue, which is to compile certain versions of node under OpenBSD. This issue is a bit more delicated, since OpenBSD uses LibreSSL, and node support for it is still not complete. - Adds check for tar's support for J option --- nvm.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/nvm.sh b/nvm.sh index 639165c..4561077 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1606,6 +1606,7 @@ nvm_get_os() { Darwin\ *) NVM_OS=darwin ;; SunOS\ *) NVM_OS=sunos ;; FreeBSD\ *) NVM_OS=freebsd ;; + OpenBSD\ *) NVM_OS=openbsd ;; AIX\ *) NVM_OS=aix ;; esac nvm_echo "${NVM_OS-}" @@ -1933,6 +1934,69 @@ nvm_download_artifact() { nvm_echo "${TARBALL}" } +nvm_tar_knows_J() { + ERR_MSG=$(tar -J 2>&1 | head -1) + [ "_$ERR_MSG" != "_tar: unknown option -- J" ] +} + + +# args: tarball path, NVM_OS var +# returns: a string with the path of the extracted compressed file +nvm_extract_tar_artifact() { + local tar_compression_flag + local TARBALL + local TAR_COMMAND_SUFFIX + local TMPDIR + local NVM_OS + local tar + + TARBALL="${1}" + NVM_OS="${2}" + + tar='tar' + if [ "${NVM_OS}" = 'aix' ]; then + tar='gtar' + fi + + tar_compression_flag='z' + + if ! nvm_tar_knows_J && nvm_has xz && nvm_supports_xz "${VERSION}"; then + + if [ -f "${TARBALL}" ]; then + command xz -dk "${TARBALL}" + fi + + TARBALL=${TARBALL%.xz} + tar_compression_flag= + TAR_COMMAND_SUFFIX= + TMPDIR="$(dirname "${TARBALL}")" + + else + + if nvm_tar_knows_J; then + tar_compression_flag='J' + fi + + TAR_COMMAND_SUFFIX="--strip-components 1" + TMPDIR="$(dirname "${TARBALL}")/files" + fi + + if [ -f "${TARBALL}" ] && [ -d "${TMPDIR}" ]; then + # shellcheck disable=SC2086 + command ${tar} "-x${tar_compression_flag}f" "${TARBALL}" -C "${TMPDIR}" ${TAR_COMMAND_SUFFIX} + fi + + # The `-C` option for `tar` on Openbsd takes its parameter and extracts files + # from the tarball into a new directory named after it. That's why this update + # in the `$TMPDIR` is necessary + if [ "_$NVM_OS" = "_openbsd" ]; then + BASE=$(basename "${TMPDIR}") + TMPDIR="${TMPDIR}/${BASE}" + fi + + nvm_echo "$TMPDIR" +} + nvm_get_make_jobs() { if nvm_is_natural_num "${1-}"; then NVM_MAKE_JOBS="$1" @@ -2030,7 +2094,7 @@ nvm_install_source() { make='gmake' MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}" ;; - 'darwin') + 'openbsd' | 'darwin') MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}" ;; 'aix') @@ -2044,18 +2108,6 @@ nvm_install_source() { fi fi - local tar_compression_flag - tar_compression_flag='z' - if nvm_supports_xz "${VERSION}"; then - tar_compression_flag='J' - fi - - local tar - tar='tar' - if [ "${NVM_OS}" = 'aix' ]; then - tar='gtar' - fi - local TARBALL local TMPDIR local VERSION_PATH @@ -2071,11 +2123,8 @@ nvm_install_source() { TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \ [ -f "${TARBALL}" ] && \ - TMPDIR="$(dirname "${TARBALL}")/files" && \ + TMPDIR="$(nvm_extract_tar_artifact "${TARBALL}" "${NVM_OS}" | command tail -1)" && \ if ! ( - # shellcheck disable=SC2086 - command mkdir -p "${TMPDIR}" && \ - command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 && \ VERSION_PATH="$(nvm_version_path "${PREFIXED_VERSION}")" && \ nvm_cd "${TMPDIR}" && \ nvm_echo '$>'./configure --prefix="${VERSION_PATH}" $ADDITIONAL_PARAMETERS'<' && \ From 79e13d5bd8c6cd8b61a1b7e08a22c90fbfd61140 Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Fri, 13 Dec 2019 10:27:07 -0800 Subject: [PATCH 2/2] support build on OpenBSD with bash, gtar, gmake and libexecinfo --- nvm.sh | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/nvm.sh b/nvm.sh index 4561077..cd802c7 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1763,7 +1763,7 @@ nvm_install_binary() { fi local tar tar='tar' - if [ "${NVM_OS}" = 'aix' ]; then + if [ "${NVM_OS}" = 'aix' ] || [ "${NVM_OS}" = 'openbsd' ]; then tar='gtar' fi if ( @@ -2013,7 +2013,7 @@ nvm_get_make_jobs() { "_linux") NVM_CPU_CORES="$(nvm_grep -c -E '^processor.+: [0-9]+' /proc/cpuinfo)" ;; - "_freebsd" | "_darwin") + "_freebsd" | "_openbsd" | "_darwin") NVM_CPU_CORES="$(sysctl -n hw.ncpu)" ;; "_sunos") @@ -2090,7 +2090,7 @@ nvm_install_source() { make='make' local MAKE_CXX case "${NVM_OS}" in - 'freebsd') + 'freebsd' | 'openbsd') make='gmake' MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}" ;; @@ -2108,6 +2108,12 @@ nvm_install_source() { fi fi + local tar + tar='tar' + if [ "${NVM_OS}" = 'aix' ] || [ "${NVM_OS}" = 'openbsd' ]; then + tar='gtar' + fi + local TARBALL local TMPDIR local VERSION_PATH @@ -2124,11 +2130,26 @@ nvm_install_source() { TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \ [ -f "${TARBALL}" ] && \ TMPDIR="$(nvm_extract_tar_artifact "${TARBALL}" "${NVM_OS}" | command tail -1)" && \ + + local configure_env + # Node's configure.py sets gcc and g++ by default except for darwin + # OpenBSD needs to use cc and c++ + if [ "${NVM_OS}" = 'openbsd' ]; then + configure_env="CC=cc CXX=c++" + fi + if ! ( VERSION_PATH="$(nvm_version_path "${PREFIXED_VERSION}")" && \ nvm_cd "${TMPDIR}" && \ - nvm_echo '$>'./configure --prefix="${VERSION_PATH}" $ADDITIONAL_PARAMETERS'<' && \ - ./configure --prefix="${VERSION_PATH}" $ADDITIONAL_PARAMETERS && \ + nvm_echo '$>'env ${configure_env} ./configure --prefix="${VERSION_PATH}" ${ADDITIONAL_PARAMETERS}'<' && \ + env ${configure_env} ./configure --prefix="${VERSION_PATH}" ${ADDITIONAL_PARAMETERS} && \ + + # Post-configure: OpenBSD needs to remove the ldl flag in the OpenSSL dep + if [ "${NVM_OS}" = 'openbsd' ]; then + sed -i 's/-ldl //' ${TMPDIR}/out/deps/openssl/openssl.target.mk + sed -i 's/-ldl //' ${TMPDIR}/out/deps/openssl/openssl-cli.target.mk + fi + $make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} && \ command rm -f "${VERSION_PATH}" 2>/dev/null && \ $make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} install @@ -2533,7 +2554,7 @@ nvm() { local TEST_TOOLS ADD_TEST_TOOLS TEST_TOOLS="git grep awk" ADD_TEST_TOOLS="sed cut basename rm mkdir xargs" - if [ "darwin" != "$(nvm_get_os)" ] && [ "freebsd" != "$(nvm_get_os)" ]; then + if [ "darwin" != "$(nvm_get_os)" ] && [ "freebsd" != "$(nvm_get_os)" ] && [ "openbsd" != "$(nvm_get_os)" ]; then TEST_TOOLS="${TEST_TOOLS} ${ADD_TEST_TOOLS}" else for tool in ${ADD_TEST_TOOLS} ; do @@ -2786,10 +2807,10 @@ nvm() { EXIT_CODE=0 else - if [ "_${NVM_OS}" = "_freebsd" ]; then - # node.js and io.js do not have a FreeBSD binary + if [ "_${NVM_OS}" = "_freebsd" ] || [ "_${NVM_OS}" = "_openbsd" ]; then + # node.js and io.js do not have a FreeBSD/OpenBSD binary nobinary=1 - nvm_err "Currently, there is no binary for FreeBSD" + nvm_err "Currently, there is no binary for ${NVM_OS}" elif [ "_${NVM_OS}" = "_sunos" ]; then # Not all node/io.js versions have a Solaris binary if ! nvm_has_solaris_binary "${VERSION}"; then