You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2023/01/27 08:44:55 UTC

[couchdb] branch 3.3.x updated: chore(configure): be more defensive about SpiderMonkey location (#4407)

This is an automated email from the ASF dual-hosted git repository.

ronny pushed a commit to branch 3.3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/3.3.x by this push:
     new d42531b6d chore(configure): be more defensive about SpiderMonkey location (#4407)
d42531b6d is described below

commit d42531b6dc158db1899bda2b18ea13c745a0fb0f
Author: PÁLI Gábor János <ga...@ibm.com>
AuthorDate: Fri Jan 27 09:44:49 2023 +0100

    chore(configure): be more defensive about SpiderMonkey location (#4407)
    
    The `configure` script does not check whether SpiderMonkey
    actually exists at the presumed location.  This may go wrong when
    the user has a version different from the default one.  The
    mistake is spotted only in build time, indirectly, via missing
    header files.  That is too late and it may not be evident for the
    user what the problem is.
    
    Add a user-friendly safeguard to prevent this from happening.
---
 configure                     | 28 +++++++++++++++++++++++++---
 configure.ps1                 | 16 ++++++++++++++++
 src/couch/rebar.config.script |  3 +++
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 79377ea1a..3fe870091 100755
--- a/configure
+++ b/configure
@@ -30,10 +30,15 @@ WITH_DOCS=1
 ERLANG_MD5="false"
 SKIP_DEPS=0
 
+run_erlang() {
+    erl -noshell -eval "$1" -eval "halt()."
+}
+
 COUCHDB_USER="$(whoami 2>/dev/null || echo couchdb)"
 SM_VSN=${SM_VSN:-"1.8.5"}
 ARCH="$(uname -m)"
-ERLANG_VER="$(erl -eval 'io:put_chars(erlang:system_info(otp_release)), halt().' -noshell)"
+ERLANG_VER="$(run_erlang 'io:put_chars(erlang:system_info(otp_release)).')"
+ERLANG_OS="$(run_erlang 'case os:type() of {OS, _} -> io:format("~s~n", [OS]) end.')"
 
 . ${rootdir}/version.mk
 COUCHDB_VERSION=${vsn_major}.${vsn_minor}.${vsn_patch}
@@ -224,12 +229,29 @@ parse_opts() {
 
 parse_opts $@
 
-if [ "${ARCH}" = "aarch64" ] && [ "${SM_VSN}" = "60" ]
-then
+if [ "${ARCH}" = "aarch64" ] && [ "${SM_VSN}" = "60" ]; then
   echo "ERROR: SpiderMonkey 60 is known broken on ARM 64 (aarch64). Use another version instead."
   exit 1
 fi
 
+if [ "${ERLANG_OS}" = "unix" ]; then
+    case "${SM_VSN}" in
+        1.8.5)
+            SM_HEADERS="js"
+            ;;
+        *)  SM_HEADERS="mozjs-${SM_VSN}"
+            ;;
+        esac
+
+    # This list is taken from src/couch/rebar.config.script, please keep them in sync.
+    if [ ! -d "/usr/include/${SM_HEADERS}" ] && \
+        [ ! -d "/usr/local/include/${SM_HEADERS}" ] && \
+        [ ! -d "/opt/homebrew/include/${SM_HEADERS}" ]; then
+        echo "ERROR: SpiderMonkey ${SM_VSN} is not found. Please specify with --spidermonkey-version."
+        exit 1
+    fi
+fi
+
 echo "==> configuring couchdb in rel/couchdb.config"
 cat > rel/couchdb.config << EOF
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
diff --git a/configure.ps1 b/configure.ps1
index 7584630d6..f0fc280cd 100644
--- a/configure.ps1
+++ b/configure.ps1
@@ -103,6 +103,22 @@ If ($Test) {
     exit 0
 }
 
+# Use the MSVC linker to determine if the respective SpiderMonkey library
+# is available on the linker path.  This heuristic is taken from
+# src/couch/rebar.config.script, please keep them in sync.
+If ($SpiderMonkeyVersion -eq "1.8.5") {
+    $SpiderMonkeyLib = "mozjs185-1.0.lib"
+}
+else {
+    $SpiderMonkeyLib = "mozjs-$SpiderMonkeyVersion.lib"
+}
+
+&link $SpiderMonkeyLib /SUBSYSTEM:CONSOLE /NOENTRY /DLL /OUT:NUL *> $null
+If ($LASTEXITCODE -ne 0) {
+    Write-Output "ERROR: SpiderMonkey $SpiderMonkeyVersion is not found. Please specify with -SpiderMonkeyVersion."
+    exit 1
+}
+
 # Translate ./configure variables to CouchDB variables
 $PackageAuthorName="The Apache Software Foundation"
 $InstallDir="$LibDir\couchdb"
diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script
index f0b465135..34c7616cc 100644
--- a/src/couch/rebar.config.script
+++ b/src/couch/rebar.config.script
@@ -114,6 +114,9 @@ ProperConfig = case code:lib_dir(proper) of
     _ -> [{d, 'WITH_PROPER'}]
 end.
 
+% The include directories (parameters for the `-I` C compiler flag) are
+% considered in the `configure` script as a pre-check for their existence.
+% Please keep them in sync.
 {JS_CFLAGS, JS_LDFLAGS} = case os:type() of
     {win32, _} when SMVsn == "1.8.5" ->
         {