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 2022/12/05 10:45:51 UTC
[couchdb] 03/03: hook into rebar.config.script
This is an automated email from the ASF dual-hosted git repository.
ronny pushed a commit to branch spidermonkey_version_nif
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 47d9af3bdc4ccf4e2beddd2ead4eb6d1815a4ad3
Author: Ronny Berndt <ro...@apache.org>
AuthorDate: Mon Dec 5 11:36:57 2022 +0100
hook into rebar.config.script
---
src/chttpd/src/chttpd_node.erl | 3 +--
.../priv/couch_spidermonkey/couch_spidermonkey.cpp | 4 ++--
src/couch/rebar.config.script | 17 +++++++++-------
src/couch/src/couch_server.erl | 2 +-
src/couch/src/couch_spidermonkey.erl | 23 +++++++++++++---------
5 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 193db3d4d..a63236db7 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -56,8 +56,7 @@ handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, <<"_versions">>]}
},
javascript_engine => #{
name => <<"spidermonkey">>,
- version => couch_server:get_spidermonkey_version(),
- version_dyn => list_to_binary(couch_spidermonkey:get_spidermonkey_version())
+ version => couch_server:get_spidermonkey_version()
}
});
handle_node_req(#httpd{path_parts = [_, _Node, <<"_versions">>]} = Req) ->
diff --git a/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp b/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp
index b33cd8d6f..783f55365 100644
--- a/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp
+++ b/src/couch/priv/couch_spidermonkey/couch_spidermonkey.cpp
@@ -29,10 +29,10 @@ get_spidermonkey_version(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
const string FULLVERSION = JS_GetImplementationVersion();
int full_len = FULLVERSION.length();
- //ignore "JavaScript-C"
+ //trim off "JavaScript-C"
string result = FULLVERSION.substr(js_len, full_len-js_len);
- return enif_make_binary(env, result.c_str());
+ return enif_make_string(env, result.c_str(), ERL_NIF_LATIN1);
}
static ErlNifFunc nif_functions[] = {
diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script
index 27d19c6c0..6c1ab896a 100644
--- a/src/couch/rebar.config.script
+++ b/src/couch/rebar.config.script
@@ -189,11 +189,18 @@ CouchJSEnv = case SMVsn of
]
end.
+SpiderEnv = case SMVsn of
+ "91" ->
+ [
+ {"CXXFLAGS", JS_CFLAGS},
+ {"LDFLAGS", JS_LDFLAGS}
+ ]
+end.
+
IcuEnv = [{"DRV_CFLAGS", "$DRV_CFLAGS -DPIC -O2 -fno-common"},
{"DRV_LDFLAGS", "$DRV_LDFLAGS -lm -licuuc -licudata -licui18n -lpthread"}].
IcuDarwinEnv = [{"CFLAGS", "-DXP_UNIX -I/usr/local/opt/icu4c/include -I/opt/homebrew/opt/icu4c/include"},
- {"LDFLAGS", "-L/usr/local/Cellar/spidermonkey/91.13.0_1/lib -L/usr/local/opt/icu4c/lib -L/opt/homebrew/opt/icu4c/lib"},
- {"CXXFLAGS", "-I/usr/local/Cellar/spidermonkey/91.13.0_1/include"}].
+ {"LDFLAGS", "-L/usr/local/opt/icu4c/lib -L/opt/homebrew/opt/icu4c/lib"}].
IcuBsdEnv = [{"CFLAGS", "-DXP_UNIX -I/usr/local/include"},
{"LDFLAGS", "-L/usr/local/lib"}].
IcuWinEnv = [{"CFLAGS", "$DRV_CFLAGS /DXP_WIN"},
@@ -214,10 +221,7 @@ BaseSpecs = [
{"bsd", ComparePath, CompareSrc, [{env, IcuEnv ++ IcuBsdEnv}]},
{"win32", ComparePath, CompareSrc, [{env, IcuWinEnv}]},
% couch_spidermonkey
- {"darwin", SpiderPath, SpiderSrc, [{env, IcuEnv ++ IcuDarwinEnv}]},
- {"linux", SpiderPath, SpiderSrc, [{env, IcuEnv}]},
- {"bsd", SpiderPath, SpiderSrc, [{env, IcuEnv ++ IcuBsdEnv}]},
- {"win32", SpiderPath, SpiderSrc, [{env, IcuWinEnv}]}
+ {".*", SpiderPath, SpiderSrc, [{env, CouchJSEnv}]}
].
SpawnSpec = [
@@ -247,7 +251,6 @@ AddConfig = [
{erl_opts, PlatformDefines ++ [
{d, 'COUCHDB_VERSION', Version},
{d, 'COUCHDB_GIT_SHA', GitSha},
- {d, 'COUCHDB_SPIDERMONKEY_VERSION', SMVsn},
{i, "../"}
] ++ MD5Config ++ ProperConfig},
{port_env, PortEnvOverrides},
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 6486c56c7..af4786e33 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -91,7 +91,7 @@ get_stats() ->
lists:foldl(Fun, {0, 0}, lists:seq(1, num_servers())),
[{start_time, ?l2b(Time)}, {dbs_open, Open}].
-get_spidermonkey_version() -> list_to_binary(?COUCHDB_SPIDERMONKEY_VERSION).
+get_spidermonkey_version() -> list_to_binary(couch_spidermonkey:get_spidermonkey_version()).
sup_start_link(N) ->
gen_server:start_link({local, couch_server(N)}, couch_server, [N], []).
diff --git a/src/couch/src/couch_spidermonkey.erl b/src/couch/src/couch_spidermonkey.erl
index c97cb3f26..ad42bb0c0 100644
--- a/src/couch/src/couch_spidermonkey.erl
+++ b/src/couch/src/couch_spidermonkey.erl
@@ -1,20 +1,25 @@
-%%%-------------------------------------------------------------------
-%%% @author big-r
-%%% @copyright (C) 2022, <COMPANY>
-%%% @doc
-%%%
-%%% @end
-%%% Created : 13. Okt 2022 19:40
-%%%-------------------------------------------------------------------
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
-module(couch_spidermonkey).
-export([get_spidermonkey_version/0]).
+
-nifs([get_spidermonkey_version/0]).
+
-on_load(init/0).
init() ->
Dir = code:priv_dir(couch),
- couch_log:info("Priv-Dir: ~p", [filename:join(Dir, ?MODULE)]),
ok = erlang:load_nif(filename:join(Dir, ?MODULE), 0).
get_spidermonkey_version() ->