【问题标题】:Command 'generate' not found, compiling with rebar找不到命令“生成”,使用钢筋编译
【发布时间】:2015-01-26 02:41:08
【问题描述】:

我正在关注这个博客: http://maplekeycompany.blogspot.se/2012/03/very-basic-cowboy-setup.html

简而言之,我正在尝试用 rebar 编译一个应用程序,就像博客中的人一样。 一切顺利,直到我想运行命令:

./rebar get-deps compile generate

这会给我以下错误和警告,

> User@user-:~/simple_server/rebar$ ./rebar get-deps compile generate
> ==> rebar (get-deps)
> ==> rebar (compile) Compiled src/simple_server.erl Compiled src/simple_server_http.erl src/simple_server_http_static.erl:5:
> Warning: behaviour cowboy_http_handler undefined Compiled
> src/simple_server_http_static.erl
> src/simple_server_http_catchall.erl:2: Warning: behaviour
> cowboy_http_handler undefined Compiled
> src/simple_server_http_catchall.erl WARN:  'generate' command does not
> apply to directory /home/harri/simple_server/rebar Command 'generate'
> not understood or not applicable

我发现了一个类似的帖子,同样的错误:

Command 'generate' not understood or not applicable

我认为问题出在 reltool.config 但不知道如何继续,我将路径更改为以下内容:{lib_dirs, ["home/user/simple_server/rebar"]}

路径有问题吗? rebar 如何访问所有 src 文件以及编译和构建应用程序所需的 rebar 文件?

【问题讨论】:

  • 确保至少一个在 rebar.config 中指向 {sub_dirs, ...} 的目录包含您尝试生成的版本的 reltool.config。

标签: http path erlang rebar cowboy


【解决方案1】:

您需要确保您的目录结构及其内容已安排好,以便 rebar 知道如何在系统中构建所有内容并为其生成发布。您的目录结构应如下所示:

project
   |
   -- rel
   |
   -- deps
   |
   -- apps
       |
       -- myapp
       |    |
       |    -- src
       |    -- priv
       |
       -- another_app

rel 目录包含生成发布所需的所有信息,apps 目录是构成项目的应用程序所在的位置。应用程序依赖项位于deps 目录中。 apps目录下的myappanother_app等每个应用程序都可以有自己的rebar.config文件。虽然这里可能有两个或多个这样的应用程序,但通常您只有一个,而所有其他应用程序都是依赖项。

在顶级 project 目录中还有一个 rebar.config 文件,其内容如下所示:

{sub_dirs, ["rel", "apps/myapp", "apps/another_app"]}.
{lib_dirs, ["apps"]}.

如有必要,您可以使用 rebar 从应用程序骨架生成您的应用程序:

cd apps
mkdir myapp another_app
( cd myapp && rebar create-app appid=myapp )
( cd another_app && rebar create-app appid=another_app )

如果应用程序具有依赖项,您必须将rebar.config 添加到其目录并在其中声明每个依赖项。例如,如果myapp 依赖于应用程序foo 1.2 版,则使用以下内容创建apps/myapp/rebar.config

{deps,
 [{foo, "1.*", {git, "git://github.com/user/foo.git", {tag, "foo-1.2"}}}]
}.

当您运行rebar get-deps 时,rebar 将填充顶级deps 目录以保存所有依赖项,并在必要时创建deps。顶层rebar.config也可以根据需要声明依赖。

您还需要生成一个节点,这是您的发布所必需的:

cd ../rel
rebar create-node nodeid=project

然后需要修改上一步生成的reltool.config文件。你需要改变

{lib_dirs, []},

{lib_dirs, ["../apps", "../deps"]},

并在 {incl_cond, derived}, 行之后添加 {mod_cond, derived}, 以便发布仅包含正确执行所需的应用程序。

接下来,无论原子'project' 出现在哪里,您都需要将其替换为apps 目录下的应用程序。对于我们的示例,我们将更改这部分:

{rel, "project", "1",
 [
  kernel,
  stdlib,
  sasl,
  project
 ]},

到这里:

{rel, "project", "1",
 [
  kernel,
  stdlib,
  sasl,
  myapp,
  another_app
 ]},

并更改此部分:

{app, project, [{mod_cond, app}, {incl_cond, include}]}

到这里:

{app, myapp, [{mod_cond, app}, {incl_cond, include}]},
{app, another_app, [{mod_cond, app}, {incl_cond, include}]}

您可能还需要添加以下行:

{app, hipe, [{incl_cond, exclude}]},

排除hipe 应用程序,因为有时它会在版本生成期间或尝试运行版本时导致错误。请先尝试不使用它,但如果您在生成发布时看到与 hipe 相关的错误,或者尝试运行生成的发布导致此类错误,请添加它:

{"init terminating in do_boot",{'cannot load',elf_format,get_files}}

你需要添加它。

一切就绪后,您现在可以执行:

rebar get-deps compile generate

并且您应该能够成功生成版本。请注意,在顶层而不是在 rel 目录中运行 rebar generate 会导致类似这样的无害警告,您可以忽略:

WARN:  'generate' command does not apply to directory /path/to/project

最后,您可以运行该版本。以下是使用交互式控制台运行它的方法:

$ ./rel/project/bin/project console
Exec: /path/to/project/rel/project/erts-6.2/bin/erlexec  -boot /path/to/project/rel/project/releases/1/project -mode embedded -config /path/to/project/rel/project/releases/1/sys.config -args_file /path/to/project/rel/project/releases/1/vm.args -- console
Root: /path/to/project/rel/project
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]

Eshell V6.2  (abort with ^G)
(project@127.0.0.1)1>

或者您可以运行./rel/project/bin/project start 在后台启动它。不带参数运行 ./rel/project/bin/project 以查看所有可用选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-09
    • 2012-06-26
    • 2012-04-28
    • 2015-03-30
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2011-11-17
    相关资源
    最近更新 更多