You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ji...@apache.org on 2020/02/10 03:20:33 UTC

[couchdb] 02/11: Enable multi-version SpiderMonkey support

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

jiangphcn pushed a commit to branch spidermonkey60-porting
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e8788b3a1cb43e878945968ef56af3b219ea6c7c
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Dec 2 13:54:26 2019 -0600

    Enable multi-version SpiderMonkey support
---
 .gitignore                                 |  7 +---
 src/couch/priv/couch_js/{ => 1.8.5}/help.h |  0
 src/couch/priv/couch_js/{ => 1.8.5}/http.c |  0
 src/couch/priv/couch_js/{ => 1.8.5}/http.h |  0
 src/couch/priv/couch_js/{ => 1.8.5}/main.c |  0
 src/couch/priv/couch_js/{ => 1.8.5}/utf8.c |  0
 src/couch/priv/couch_js/{ => 1.8.5}/utf8.h |  0
 src/couch/priv/couch_js/{ => 1.8.5}/util.c |  0
 src/couch/priv/couch_js/{ => 1.8.5}/util.h |  0
 src/couch/rebar.config.script              | 59 +++++++++++++++++++++---------
 10 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/.gitignore b/.gitignore
index 2de464c..470d1d4b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,14 +35,11 @@ share/www
 src/b64url/
 src/bear/
 src/config/
-src/couch/priv/couch_js/config.h
+src/couch/priv/couch_js/**/config.h
 src/couch/priv/couchjs
 src/couch/priv/couchspawnkillable
 src/couch/priv/couch_ejson_compare/couch_ejson_compare.d
-src/couch/priv/couch_js/http.d
-src/couch/priv/couch_js/main.d
-src/couch/priv/couch_js/utf8.d
-src/couch/priv/couch_js/util.d
+src/couch/priv/couch_js/**/*.d
 src/couch/priv/icu_driver/couch_icu_driver.d
 src/mango/src/mango_cursor_text.nocompile
 src/docs/
diff --git a/src/couch/priv/couch_js/help.h b/src/couch/priv/couch_js/1.8.5/help.h
similarity index 100%
rename from src/couch/priv/couch_js/help.h
rename to src/couch/priv/couch_js/1.8.5/help.h
diff --git a/src/couch/priv/couch_js/http.c b/src/couch/priv/couch_js/1.8.5/http.c
similarity index 100%
rename from src/couch/priv/couch_js/http.c
rename to src/couch/priv/couch_js/1.8.5/http.c
diff --git a/src/couch/priv/couch_js/http.h b/src/couch/priv/couch_js/1.8.5/http.h
similarity index 100%
rename from src/couch/priv/couch_js/http.h
rename to src/couch/priv/couch_js/1.8.5/http.h
diff --git a/src/couch/priv/couch_js/main.c b/src/couch/priv/couch_js/1.8.5/main.c
similarity index 100%
rename from src/couch/priv/couch_js/main.c
rename to src/couch/priv/couch_js/1.8.5/main.c
diff --git a/src/couch/priv/couch_js/utf8.c b/src/couch/priv/couch_js/1.8.5/utf8.c
similarity index 100%
rename from src/couch/priv/couch_js/utf8.c
rename to src/couch/priv/couch_js/1.8.5/utf8.c
diff --git a/src/couch/priv/couch_js/utf8.h b/src/couch/priv/couch_js/1.8.5/utf8.h
similarity index 100%
rename from src/couch/priv/couch_js/utf8.h
rename to src/couch/priv/couch_js/1.8.5/utf8.h
diff --git a/src/couch/priv/couch_js/util.c b/src/couch/priv/couch_js/1.8.5/util.c
similarity index 100%
rename from src/couch/priv/couch_js/util.c
rename to src/couch/priv/couch_js/1.8.5/util.c
diff --git a/src/couch/priv/couch_js/util.h b/src/couch/priv/couch_js/1.8.5/util.h
similarity index 100%
rename from src/couch/priv/couch_js/util.h
rename to src/couch/priv/couch_js/1.8.5/util.h
diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script
index 846e8b4..f4c0705 100644
--- a/src/couch/rebar.config.script
+++ b/src/couch/rebar.config.script
@@ -54,6 +54,16 @@ CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of
         []
 end.
 
+SMVsn = case lists:keyfind(spidermonkey_version, 1, CouchConfig) of
+    {_, "1.8.5"} ->
+        "1.8.5";
+    undefined ->
+        "1.8.5";
+    {_, Unsupported} ->
+        io:format(standard_error, "Unsupported SpiderMonkey version: ~s~n", [Unsupported]),
+        erlang:halt(1)
+end.
+
 ConfigH = [
     {"SM185", ""},
     {"HAVE_JS_GET_STRING_CHARS_AND_LENGTH", "1"},
@@ -66,7 +76,7 @@ ConfigH = [
     {"PACKAGE_VERSION", "\"" ++ Version ++ "\""}
 ],
 
-CouchJSConfig = "priv/couch_js/config.h",
+CouchJSConfig = "priv/couch_js/" ++ SMVsn ++ "/config.h",
 ConfigSrc = [["#define ", K, " ", V, $\n] || {K, V} <- ConfigH],
 ConfigBin = iolist_to_binary(ConfigSrc),
 ok = CopyIfDifferent(CouchJSConfig, ConfigBin),
@@ -78,27 +88,45 @@ MD5Config = case lists:keyfind(erlang_md5, 1, CouchConfig) of
         []
 end,
 
-%% TODO support curl on Windows
-{JS_CFLAGS, JS_LDFLAGS} = case lists:keyfind(with_curl, 1, CouchConfig) of
+{JS_CFLAGS, JS_LDFLAGS} = case os:type() of
+    {win32, _} when SMVsn == "1.8.5" ->
+        {
+            "/DXP_WIN /IC:\\relax\\js-1.8.5\\js\\src",
+            "/LIBPATH:C:\\relax\\js-1.8.5\\js\\src mozjs185-1.0.lib"
+        };
+    _ when SMVsn == "1.8.5" ->
+        {
+            "-DXP_UNIX -I/usr/inlude/js -I/usr/local/include/js",
+            "-L/usr/local/lib -lmozjs185 -lm"
+        }
+end.
+
+{CURL_CFLAGS, CURL_LDFLAGS} = case lists:keyfind(with_curl, 1, CouchConfig) of
     {with_curl, true} ->
         case os:type() of
             {win32, _} ->
-                {"/DHAVE_CURL /IC:\\relax\\curl\\include", "/LIBPATH:C:\\relax\\js-1.8.5\\js\\src /LIBPATH:C:\\Relax\\curl\\lib\\release-ssl mozjs185-1.0.lib libcurl_imp.lib"};
+                {
+                    "/DHAVE_CURL /IC:\\relax\\curl\\include",
+                    "/LIBPATH:C:\\Relax\\curl\\lib\\release-ssl libcurl_imp.lib"
+                };
             {unix, freebsd} ->
-                {"-DHAVE_CURL -I/usr/local/include", "-DHAVE_CURL -lmozjs185 -lcurl"};
+                {
+                    "-DHAVE_CURL -I/usr/local/include",
+                    "-DHAVE_CURL -lcurl"
+                };
             _ ->
-                {"-DHAVE_CURL", "-DHAVE_CURL -lmozjs185 -lcurl"}
+                {
+                    "-DHAVE_CURL",
+                    "-DHAVE_CURL -lcurl"
+                }
         end;
     _ ->
-        case os:type() of
-            {win32, _} ->
-                {"", "/LIBPATH:C:\\relax\\js-1.8.5\\js\\src mozjs185-1.0.lib"};
-            _ ->
-                {"", "-lmozjs185"}
-        end
+        {"", ""}
 end,
 
-CouchJSSrc = ["priv/couch_js/*.c"],
+CouchJSSrc = case SMVsn of
+    "1.8.5" -> ["priv/couch_js/1.8.5/*.c"]
+end.
 
 IcuPath = "priv/couch_icu_driver.so",
 IcuSrc = ["priv/icu_driver/*.c"],
@@ -116,10 +144,7 @@ CompareSrc = ["priv/couch_ejson_compare/*.c"],
 
 BaseSpecs = [
         %% couchjs
-        {"darwin", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ " -DXP_UNIX -I/usr/local/include/js"}, {"LDFLAGS", JS_LDFLAGS ++ " -L/usr/local/lib"}]}]},
-        {"linux",  CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ " -DXP_UNIX -I/usr/include/js"}, {"LDFLAGS", JS_LDFLAGS ++ " -lm"}]}]},
-        {"bsd",   CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ " -DXP_UNIX -I/usr/local/include/js"}, {"LDFLAGS", JS_LDFLAGS ++ " -L/usr/local/lib -lm"}]}]},
-        {"win32",  CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ " /DXP_WIN /IC:\\relax\\js-1.8.5\\js\\src"}, {"LDFLAGS", JS_LDFLAGS}]}]},
+        {".*", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ " " ++ CURL_CFLAGS}, {"LDFLAGS", JS_LDFLAGS ++ " " ++ CURL_LDFLAGS}]}]},
         % ICU
         {"darwin", IcuPath, IcuSrc, [{env, IcuEnv ++ IcuDarwinEnv}]},
         {"linux",  IcuPath, IcuSrc, [{env, IcuEnv}]},