summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2017-04-06 12:10:08 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2017-04-06 12:26:36 -0500
commit018ad8a30160cd9af0c1864c374604f9cf5552c8 (patch)
tree21809353936076bd067ebc837494d3185ed060d4
parent5bd0b652788cc78eb05c78229d89bf74a70f9c00 (diff)
downloadcouchdb-018ad8a30160cd9af0c1864c374604f9cf5552c8.tar.gz
Fix mango full text detection
The check for whether full text support in mango is available was broken in that the mango_cursor_text module is only compiled if dreyfus exists while the check to use the module was a runtime check. Thus is a user were to add dreyfus after mango had been compiled it would have led to a runtime error when we attempted to use a module that didn't exist. This changes the check to a compile time check in both places. And now that its a compile time define we can remove the need to rename source files around which causes problems with source control seeing that file change depending on local configuration.
-rw-r--r--src/mango/rebar.config.script25
-rw-r--r--src/mango/src/mango_cursor.erl21
-rw-r--r--src/mango/src/mango_cursor_text.erl (renamed from src/mango/src/mango_cursor_text.erl.nocompile)4
3 files changed, 30 insertions, 20 deletions
diff --git a/src/mango/rebar.config.script b/src/mango/rebar.config.script
index 3b046f4b9..9b92d97e1 100644
--- a/src/mango/rebar.config.script
+++ b/src/mango/rebar.config.script
@@ -10,18 +10,17 @@
% License for the specific language governing permissions and limitations under
% the License.
-DreyfusAppFile = filename:join(filename:dirname(SCRIPT),
- "../dreyfus/src/dreyfus.app.src"),
-RenameFile = filename:join(filename:dirname(SCRIPT),
- "src/mango_cursor_text.erl"),
-CursorFile = filename:join(filename:dirname(SCRIPT),
- "src/mango_cursor_text.erl.nocompile"),
-case filelib:is_regular(DreyfusAppFile) of
- true ->
- file:rename(CursorFile, RenameFile);
- false ->
- ok
-end,
+BaseDir = filename:dirname(SCRIPT),
+DreyfusAppFile = filename:join(BaseDir, "../dreyfus/src/dreyfus.app.src"),
+HaveDreyfus = filelib:is_regular(DreyfusAppFile),
+
+if not HaveDreyfus -> CONFIG; true ->
+ CurrOpts = case lists:keyfind(erl_opts, 1, CONFIG) of
+ {erl_opts, Opts} -> Opts;
+ false -> []
+ end,
+ NewOpts = [{d, 'HAVE_DREYFUS'} | CurrOpts],
+ lists:keystore(erl_opts, 1, {erl_opts, NewOpts})
+end.
-CONFIG.
diff --git a/src/mango/src/mango_cursor.erl b/src/mango/src/mango_cursor.erl
index 911ecdb3e..cf7179079 100644
--- a/src/mango/src/mango_cursor.erl
+++ b/src/mango/src/mango_cursor.erl
@@ -26,6 +26,19 @@
-include("mango_cursor.hrl").
+-ifdef(HAVE_DREYFUS).
+-define(CURSOR_MODULES, [
+ mango_cursor_view,
+ mango_cursor_text,
+ mango_cursor_special
+]).
+-else.
+-define(CURSOR_MODULES, [
+ mango_cursor_view,
+ mango_cursor_special
+]).
+-endif.
+
-define(SUPERVISOR, mango_cursor_sup).
@@ -113,12 +126,6 @@ group_indexes_by_type(Indexes) ->
% used to service this query. This is so that we
% don't suddenly switch indexes for existing client
% queries.
- CursorModules = case module_loaded(dreyfus_index) of
- true ->
- [mango_cursor_view, mango_cursor_text, mango_cursor_special];
- false ->
- [mango_cursor_view, mango_cursor_special]
- end,
lists:flatmap(fun(CMod) ->
case dict:find(CMod, IdxDict) of
{ok, CModIndexes} ->
@@ -126,4 +133,4 @@ group_indexes_by_type(Indexes) ->
error ->
[]
end
- end, CursorModules).
+ end, ?CURSOR_MODULES).
diff --git a/src/mango/src/mango_cursor_text.erl.nocompile b/src/mango/src/mango_cursor_text.erl
index a094b5528..96e365a49 100644
--- a/src/mango/src/mango_cursor_text.erl.nocompile
+++ b/src/mango/src/mango_cursor_text.erl
@@ -12,6 +12,8 @@
-module(mango_cursor_text).
+-ifdef(HAVE_DREYFUS).
+
-export([
create/4,
explain/1,
@@ -304,3 +306,5 @@ get_json_docs(DbName, Hits) ->
{Sort, not_found}
end
end, Hits).
+
+-endif.