1

我想将 Elixir 集成到我们的项目中,并且好的旧代码不使用rebar,所以我认为编写构建.ex文件的规则Emakefile可能是一个好主意,但是这里的手册页没有提到任何相关内容。

编辑:

我们团队主要是在Windows环境下工作,但是部署会在Linux服务器上完成,所以我需要一个跨平台的解决方案。由于 Erlang 本身是跨平台的,所以我想用erl -make命令来做。

当然我可以写一个Makefile,但是我需要一个build.bat或类似的东西来在我们的开发环境中构建代码,因为我们的开发机器上没有make命令。

有人有更好的主意吗?

更新:

如果有人想知道,我是这样做的:

  1. 将 Elixir 源代码树中的目录复制lib/elixir到我们的源目录,例如some_project/src/tools/elixir.
  2. some_project/src/tools/elixir/src/elixir_transform.erl按顺序将和添加some_project/src/tools/elixir/src/*Emakefile,。将输出目录设置为some_project/ebin(所有其他.beam文件都位于那里)。
  3. src/elixir.app.srcElixir 源代码树复制到some_project/ebin/elixir.app,并对其进行编辑以修复版本代码。
  4. 在dir中运行erl -pa ebin -make,构建 Erlang 代码。some_project
  5. 通过运行构建 Elixir 编译器erl -pa ebin -s elixir_compiler core -s erlang halt
  6. 现在我们的代码中有一个可用的 Elixir 环境,我使用以下 escript 来构建我们的自定义.ex文件:
%%! -pa ./ebin
main(_) ->
    ExList = [ 
        <<"source_1.ex">>,
        <<"source_2.ex">>,
        <<"source_3.ex">>],
    application:start(elixir),
    gen_server:call(elixir_code_server, {compiler_options, [{docs, true}, {debug_info, true}]}),
    [elixir_compiler:file_to_path(F, <<"./ebin">>) || F <- ExList],
    erlang:halt(0).
4

1 回答 1

4

If you want to explicitly compile Elixir, I would go with the Makefile approach since it will always be supported by Elixir. However, I would recommend the precompiled binaries or even assume Elixir is installed in each developer machine. You can even add a task to your Emakefile to guarantee everyone is using the proper Elixir version.

Finally, about compiling your own Elixir code, I would recommend simply using mix. mix is a binary that ships with Elixir and you can simply do ./src/tools/elixir/bin/mix compile from your Emakefile.

In case using mix is not possible, you should use the parallel compiler, since it will compile files using all cores available in your machine and it will automatically detect and solve dependency in between files. Here is an example of calling the parallel compiler from erlang:

https://github.com/basho/rebar/pull/347/files#L1R62

The API is very simple. It expects a list of file names to compile as binary and the directory to output files to as another binary.

于 2013-02-11T21:00:38.130 回答