-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from HadrienMP/master
Loading nif in escript
- Loading branch information
Showing
4 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ c_src/*.o | |
ebin/ | ||
_build/ | ||
.rebar | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-module(paths). | ||
-export([nif_dir/0, nif_dir/2]). | ||
|
||
nif_dir() -> | ||
Cpd = code:priv_dir(encurses), | ||
MoCpd = filename:dirname(code:which(?MODULE)) ++ "/../priv", | ||
nif_dir(Cpd, MoCpd). | ||
|
||
|
||
nif_dir({error, _}, ModulePrivDir) -> handle_escript_format(ModulePrivDir); | ||
nif_dir(Dir, _) -> handle_escript_format(Dir). | ||
|
||
handle_escript_format(Dir) -> | ||
Handled = re:replace(Dir, | ||
"(_build/[^/]+)/bin/([^/]+)/encurses/priv", | ||
"\\1/lib/encurses/priv"), | ||
binary_to_list(iolist_to_binary(Handled)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-module(nif_path_test). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
'use the module priv directory when code priv isnt known_test'() -> | ||
NifDir = paths:nif_dir({error, bad_name}, "module dir"), | ||
?assertEqual("module dir", NifDir). | ||
|
||
'use the code priv directory_test'() -> | ||
NifDir = paths:nif_dir("./priv", "module dir"), | ||
?assertEqual("./priv", NifDir). | ||
|
||
'find the lib dir when in a bin escript directory_test'() -> | ||
NifDir = paths:nif_dir("/dir/_build/default/bin/app/encurses/priv", "module dir"), | ||
?assertEqual("/dir/_build/default/lib/encurses/priv", NifDir). | ||
|
||
'find the lib dir when in a bin escript directory when code priv was not found_test'() -> | ||
NifDir = paths:nif_dir({error, bad_name}, "/dir/_build/default/bin/app/encurses/priv"), | ||
?assertEqual("/dir/_build/default/lib/encurses/priv", NifDir). |