rebar3使用介绍(二)配置项

rebar3使用介绍(二)配置项rebar3 使用介绍 二 全局配置 Alias 别名 ArtifactsCom 测试选项 CoverDialyze 目录 EDocEscriptE 最小 OTP 版本检查 OverridesHoo 钩子 shell 钩子功能钩子自写功能中可以 hook 的点 RELXSHELLXRe 本篇主要介绍 rebar3 的配置部分全局配置 rebar3 支持全局

本篇主要介绍rebar3的配置部分

全局配置

rebar3支持全局配置,这也配置生效于环境中的所有rebar3,配置在操作系统的环境变量中,有以下内容:

Alias 别名

别名允许你根据现有命令,创造一个新的命令出来,当然他们必须有固定的执行顺序才行,比如

{alias, [{check, [eunit, {ct, "--sys_config=config/app.config"}]}]}. 

配置中的元素可以是check这种单个atom代表一个动作,也可以是 {ct, “–sys_config=config/app.config”} 这种代表一个带参的动作,执行顺序永远是从左到右串行执行。

Artifacts

相对路径于取决于它是否在伞状项目的顶层定义。例如,假设我们有一个项目my_project包含应用程序my_app在apps/my_app/下,my_app会创建一个escript。在rebar3不要在意配置在my_project/rebar.config中,因为它是整个项目的顶级rebar.config。该artifact会相对profile_dir,默认情况下是_build/default/:

{artifacts, ["bin/rebar3"]}. 

相反的如果项目不是伞状项目,即使my_app是在顶层,rebar.config在根目录下,Artifacts项的相对目录也是_build/default/lib/my_app/

rebar3提供了几个宏来扩展相对目录如下:

Key 描述
profile_dir The base output directory with the profile string appended, default: _build/default/.
base_dir The base output directory, default: _build.
out_dir The application’s output directory, default:_build/default/lib/

/
.

再举一个实例,eleveldb

{overrides, [{override, eleveldb, [{artifacts, ["priv/eleveldb.so"]}, ... ] }]}. 

因为这个是eleveldb自己的rebar.config,所以"priv/eleveldb.so" 就相当于"{
{out_dir}}priv/eleveldb.so"

Compilation

编译选项定义在erl_opts字段下,具体可使用的字段和值参照erlang的编译选项

{erl_opts, [ debug_info, {parse_transform, lager_transform}, warn_export_all, warn_unused_import, {i, "include"}, {src_dirs, ["src"]}]}. 

除此之外,还可以设置特定于平台的选项。

 {erl_opts, [{platform_define, "(linux|solaris|freebsd|darwin)", 'HAVE_SENDFILE'}, {platform_define, "(linux|freebsd)", 'BACKLOG', 128}, {platform_define, "R13", 'old_inets'}] }. 

这里支持匹配例如

{platform_define, "^((?!R1[456]).)*$", 'maps_support'} 

一个单独的编译选项是声明模块在所有其他模块之前编译的选项:

{erl_first_files, ["src/lager_util.erl"]}. 

还有一些额外的单独编译选项

{validate_app_modules, true}. % Make sure modules in .app match those found in code {app_vars_file, undefined | Path}. % file containing elements to put in all generated app files %% Paths the compiler outputs when reporting warnings or errors %% relative (default), build (all paths are in _build, default prior %% to 3.2.0, and absolute are valid options {compiler_source_format, relative}. 

其他与Erlang相关的编译器支持自己的配置选项:

  • Leex编译器与{xrl_opts, […]}
  • SNMP MIB编译器与{mib_opts, […]}
  • Yecc编译器与{yrl_opts, […]}

测试选项

{ct_first_files, [...]}. % {erl_first_files, ...} but for CT {ct_opts, [...]}. % same as options for ct:run_test(...) {ct_readable, true | false}. % disable rebar3 modifying CT output in the shell 

ct_opts支持的字段可以在这里找到

Cover

具体看这

Dialyzer

{dialyzer, [Opts]} 

支持选项看这

Distribution

多个功能和插件可能需要支持分布式Erlang。通常,所有此类命令(例如ct和shell)的配置都遵循以下配置值:

{dist_node, [ {setcookie, 'atom-cookie'}, {name | sname, 'nodename'}, ]}. 

Directories 目录

可支持选项和默认值如下:

%% directory for artifacts produced by rebar3 {base_dir, "_build"}. %% directory in ' 
   
     / 
    
      /' where deps go {deps_dir, "lib"}. %% where rebar3 operates from; defaults to the current working directory {root_dir, "."}. %% where checkout dependencies are to be located {checkouts_dir, "_checkouts"}. %% directory in ' 
     
       / 
      
        /' where plugins go {plugins_dir, "plugins"}. %% directories where OTP applications for the project can be located {project_app_dirs, ["apps/*", "lib/*", "."]}. %% Directories where source files for an OTP application can be found {src_dirs, ["src"]}. %% Paths to miscellaneous Erlang files to compile for an app %% without including them in its modules list {extra_src_dirs, []}. %% Paths the compiler outputs when reporting warnings or errors %% relative (default), build (all paths are in _build, default prior %% to 3.2.0, and absolute are valid options {compiler_source_format, relative}. 
       
      
     
   

EDoc

配置项看这里

Escript

参看

EUnit

{eunit_first_files, [...]}. % {erl_first_files, ...} but for CT {eunit_opts, [...]}. % same as options for eunit:test(Tests, ...) {eunit_tests, [...]}. % same as Tests argument in eunit:test(Tests, ...) 

opts选项参看这里

最小OTP版本检查

{minimum_otp_vsn, "17.4"}. 

Overrides

覆盖是出于自己的项目需要对依赖项目作出改动,但是这个改动又不想套用到库上,所以选作上层覆盖,Overrides支持add, override, del操作

{overrides, [{add, app_name(), [{atom(), any()}]}, {del, app_name(), [{atom(), any()}]}, {override, app_name(), [{atom(), any()}]}, {add, [{atom(), any()}]}, {del, [{atom(), any()}]}, {override, [{atom(), any()}]}]}. 

app_name有的时候只会对指定app进行操作,如果没有指定,则会对所有app进行指定

这个特性允许你在不修改库的前提下,强制同意一些编译配置之类,或者针对自己的项目或者平台进行扩展

Hook 钩子

有两种类型的钩子:shell钩子和功能钩子

shell钩子

{pre_hooks, [{clean, "./prepare_package_files.sh"}, {"linux", compile, "c_src/build_linux.sh"}, {compile, "escript generate_headers"}, {compile, "escript check_headers"}]}. {post_hooks, [{clean, "touch file1.out"}, {"freebsd", compile, "c_src/freebsd_tweaks.sh"}, {eunit, "touch file2.out"}, {compile, "touch postcompile.out"}]}. 

功能钩子

{provider_hooks, [{pre, [{compile, clean}]} {post, [{compile, {erlydtl, compile}}]}]} 

自写功能中可以hook的点

只有部分功能支持附着钩子,

Hook before and after
clean 每个应用程序和依赖项,和/或编译所有顶级应用程序之前和之后
compile 每个应用程序和依赖项,和/或编译所有顶级应用程序之前和之后
erlc_compile 编译应用程序的梁文件
app_compile 从.app.src为应用程序构建.app文件
ct 整个运行前后
edoc 整个运行前后
escriptize 整个运行前后
eunit 整个运行前后
release 整个运行前后
tar 整个运行前后

*默认情况下,这些钩子为每个应用程序运行,因为依赖项可以在它们自己的上下文中指定它们自己的钩子。区别在于,在某些情况下(伞形应用程序),钩子可以在许多级别上定义(省略覆盖):

  • 应用程序根目录下的rebar.config文件
  • 每个顶级应用程序(在apps/或中libs/)rebar.config
  • 每个依赖项的rebar.config

默认情况下,当没有伞形应用程序时,顶级rebar.config中定义的钩子将被归为顶级应用程序的一部分。这允许钩子在以后发布库时继续为依赖项工作。

但是,如果钩子是在具有伞形应用程序的项目的根目录下的rebar.config中定义的,则钩子将在任务运行之前/之后为所有顶级应用程序运行。

要保留伞状项目中的每个应用程序行为,必须在每个应用程序的rebar.config中定义钩子。

RELX

看这里

SHELL

rebar3 shell如果relx找到条目,REPL将自动启动应用程序,但可以使用显式指定由shell启动的应用程序{shell, [{apps, [App]}]}。

以下为扩展配置:

Option Value Description
apps [app1, app2, …] 要启动的app列表,追加在relx的配置后
config “path/to/a/file.config” 加载指定配置
script_file “path/to/a/file.escript” 执行自定义脚本

XRef

{xref_warnings,false}. {xref_extra_paths,[]}. {xref_checks,[undefined_function_calls,undefined_functions,locals_not_used, exports_not_used,deprecated_function_calls, deprecated_functions]}. {xref_queries,[{"(xc - uc) || (xu - x - b - (\"mod\":\".*foo\"/\"4\"))", []}]}. {xref_ignores, [{M, F}, {M, F, A}]}. 


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/206940.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 下午3:09
下一篇 2026年3月19日 下午3:09


相关推荐

  • OpenClaw:開源界最混亂 AI 專案背後的完整故事 (2026)

    OpenClaw:開源界最混亂 AI 專案背後的完整故事 (2026)

    2026年3月13日
    1
  • delphi教程视频教程_delphi7下载

    delphi教程视频教程_delphi7下载第二季的视频我准备了很久,当然了与其说准备不如说是懒,平时上班挺累的一到了周六日就想着睡觉,导致拖延症复发,心里想着反正看的人也不多而且不赚钱晚点儿录也没事儿,最后视频录制的事情就一拖再拖!当然了懒是一个原因,另一个原因是第二季我想录制(或者说学习)网络编程相关的知识,但是因为网络编程相关的东西太大了,就【TCP/IP详解】这一本书就有三卷之多,而每一卷都是300多页,同时Delphi更多的时候是运行在Windows平台的,那这样就离不开winsoket,当年研究win32API的结果是让我直接放弃了学习

    2025年7月7日
    5
  • 深入浅出LangChain&LangGraph AI Agent 智能体开发

    深入浅出LangChain&LangGraph AI Agent 智能体开发

    2026年3月16日
    2
  • Activity工作流引擎学习笔记(一)「建议收藏」

    Activity工作流引擎学习笔记(一)「建议收藏」工作流的概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档、信息或任务的过程自动进行,从而实现某个预期的业务目标,或者促使此目标的实现”。工作流管理系统(WorkflowManagementSystem,WfMS)是一个软件系统,它完成工作量的定义和管理,并按照在系统中预先定义

    2022年7月11日
    22
  • webshell与一句话木马

    webshell与一句话木马webshell 可理解为 web shell 通常就是大佬所说的大马 web 就是指 web 页面 shell 就是命令执行环境 webshell 就是以 asp aspx php jsp 或者 cgi 等网页文件形式存在的一种命令执行环境 也可以将其称做为一种网页后门 黑客在入侵了一个网站后 通常会将 asp aspx php 或 jsp 后门文件与网站 web 服务器目录下正常的网页文件混在一起 然后就可以使用浏览器来

    2026年3月17日
    1
  • simsun是什么字体怎样改成中文_ttf 宋体

    simsun是什么字体怎样改成中文_ttf 宋体华文细黑:STHeitiLight[STXihei]华文黑体:STHeiti华文楷体:STKaiti华文宋体:STSong华文仿宋:STFangsong俪黑Pro:LiHeiProMediu

    2022年8月1日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号