我创建了第一个Erlang项目。这是一个简单的密码游戏。我试图不惜一切代价避免OTP,因为它看起来真的很令人困惑,我的导师认为没有必要使用它。
我有三个文件夹:ebinsrc测试
我使用makefile来编译所有代码并运行测试。
直到今晚生活都很美好…
为了模拟游戏的输入(和输出?),建议我使用Meck,但我很难将其集成到我的项目中。
我尝试手动安装。我克隆了梅克。我可以"cd"到Meck目录下的eBin文件夹,然后编译,运行所有的系统测试,然后执行一个基本的命令"Meck:new(dog)"。太棒了!
现在我需要让Meck做我的项目…我在Github Meck自述中读到这行:"如果你想安装自己构建的meck版本,将ebin目录添加到你的Erlang代码路径中,或者将meck文件夹移动到你的发布文件夹中,并确保该文件夹位于你的ERL_LIBS环境变量中。"
但是我不知道如何将ebin目录添加到我的Erland代码路径,我没有发布文件夹(这是一个钢筋的东西我想?),我不知道如何添加ERL_LIBS环境变量。所以我被卡住了。
这是我尝试过的:为了将ebin目录添加到我的代码路径中,我在我的makefile中这样做了(我的桌面现在有meck目录):
erlc -pa ~/Desktop/meck/ebin/
我将ERL_LIBS添加到我的.bash_profile中,如下所示:
export ERL_LIBS='~/Desktop/meck/ebin/'
我也尝试安装Agner和得到错误时,我安装:
ERROR: compile failed while processing /private/tmp/agner.0r04Vm: {'EXIT',
{undef,
[{rebar,get_jobs,
[{config,"/private/tmp/agner.0r04Vm",
[{require_otp_vsn,"R14|R15"},
{lib_dirs,["deps"]},
{escript_incl_apps,
[getopt,gproc,rebar,plists,gen_fsm2,jsx]},
{erl_opts,[{i,"deps"}]},
{plugins,[agner_rebar_plugin]},
local]}],
[]},
{rebar_base_compiler,run,4,
[{file,"src/rebar_base_compiler.erl"},{line,49}]},
{rebar_erlc_compiler,doterl_compile,3,
[{file,"src/rebar_erlc_compiler.erl"},{line,157}]},
{rebar_core,run_modules,4,[{file,"src/rebar_core.erl"},{line,420}]},
{rebar_core,execute,4,[{file,"src/rebar_core.erl"},{line,354}]},
{rebar_core,process_dir0,6,[{file,"src/rebar_core.erl"},{line,217}]},
{rebar_core,process_dir,4,[{file,"src/rebar_core.erl"},{line,128}]},
{rebar_core,process_commands,2,
[{file,"src/rebar_core.erl"},{line,83}]}]}}
make: *** [compile] Error 1
有人能帮忙吗?我觉得我有几个选择可以尝试,但没有一个是有效的。
更新:
在阅读了@d11wtq的解决方案后,我的make文件看起来是这样的:
.SUFFIXES: .erl .beam .yrl
.erl.beam:
erlc -W $<
.yrl.erl:
erlc -W $<
ERL = erl -boot start_clean
MODS = console_io feedback mastermind secret_code meck
all: compile path run_test
compile:
erlc -o ebin/ src/*.erl
erlc -o ebin/ test/*.erl
path:
erlc -pa ebin/
-env ERL_LIBS deps/
run_test:
erl -noshell -pa ebin
-eval 'eunit:test("ebin").'
-eval 'mastermind:start_game().'
-s init stop
clean:
rm -rf ebin/*.beam
rm -rf erl_crash.dump
最终更新:根据提示,这是我现在可以工作的最终makefile。
all: compile run_test run_game
compile:
erlc -o ebin/ src/*.erl
erlc -o ebin/ test/*.erl
run_test:
erl -pa ebin
-env ERL_LIBS deps/
-eval 'eunit:test("ebin").'
-s init stop
run_game:
erl -pa ebin
-env ERL_LIBS deps/
-eval "mastermind:start_game()."
-s init stop
clean:
rm -rf ebin/*.beam
rm -rf erl_crash.dump
将meck(及其所有子目录)放在项目的子目录中;说,deps/.
现在你有:
src/
ebin/
deps/
meck/
src/
ebin/
因为Erlang中的库与应用程序的打包方式相同,所以有一个环境变量ERL_LIBS,它将告诉VM在哪里找到应用程序使用的库。Meck就是其中一个库,它位于"deps/"路径。
erl -pa ebin/ -env ERL_LIBS deps/
现在mek应该对Erlang VM可见
引用meck的README:
Meck最好通过螺纹钢使用。添加以下依赖项项目根目录下的
rebar.config
:{deps, [ {meck, ".*", {git, "https://github.com/eproxus/meck.git"}} ]}.
然后运行rebar get-deps
和rebar compile