rebar.config.erl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. -module('rebar.config').
  2. -export([do/2]).
  3. do(Dir, CONFIG) ->
  4. ok = assert_otp(),
  5. ok = warn_profile_env(),
  6. case iolist_to_binary(Dir) of
  7. <<".">> ->
  8. C1 = deps(CONFIG),
  9. Config = dialyzer(C1),
  10. maybe_dump(Config ++ [{overrides, overrides()}] ++ coveralls() ++ config());
  11. _ ->
  12. CONFIG
  13. end.
  14. assert_otp() ->
  15. Oldest = 25,
  16. Latest = 26,
  17. OtpRelease = list_to_integer(erlang:system_info(otp_release)),
  18. case OtpRelease < Oldest orelse OtpRelease > Latest of
  19. true ->
  20. io:format(
  21. standard_error,
  22. "ERROR: Erlang/OTP version ~p found. min=~p, recommended=~p~n",
  23. [OtpRelease, Oldest, Latest]
  24. ),
  25. halt(1);
  26. false when OtpRelease =/= Latest ->
  27. io:format(
  28. "WARNING: Erlang/OTP version ~p found, recommended==~p~n",
  29. [OtpRelease, Latest]
  30. );
  31. false ->
  32. ok
  33. end.
  34. quicer() ->
  35. {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.313"}}}.
  36. jq() ->
  37. {jq, {git, "https://github.com/emqx/jq", {tag, "v0.3.12"}}}.
  38. deps(Config) ->
  39. {deps, OldDeps} = lists:keyfind(deps, 1, Config),
  40. MoreDeps =
  41. [jq() || is_jq_supported()] ++
  42. [quicer() || is_quicer_supported()],
  43. lists:keystore(deps, 1, Config, {deps, OldDeps ++ MoreDeps}).
  44. overrides() ->
  45. [
  46. {add, [{extra_src_dirs, [{"etc", [{recursive, true}]}]}]}
  47. ] ++ snabbkaffe_overrides().
  48. %% Temporary workaround for a rebar3 erl_opts duplication
  49. %% bug. Ideally, we want to set this define globally
  50. snabbkaffe_overrides() ->
  51. Apps = [snabbkaffe, ekka, mria, gen_rpc],
  52. [{add, App, [{erl_opts, [{d, snk_kind, msg}]}]} || App <- Apps].
  53. config() ->
  54. [
  55. {cover_enabled, is_cover_enabled()},
  56. {profiles, profiles()},
  57. {plugins, plugins()}
  58. ].
  59. is_cover_enabled() ->
  60. case os:getenv("ENABLE_COVER_COMPILE") of
  61. "1" -> true;
  62. "true" -> true;
  63. _ -> false
  64. end.
  65. is_enterprise(ce) -> false;
  66. is_enterprise(ee) -> true.
  67. is_community_umbrella_app("apps/emqx_bridge_kafka") -> false;
  68. is_community_umbrella_app("apps/emqx_bridge_confluent") -> false;
  69. is_community_umbrella_app("apps/emqx_bridge_gcp_pubsub") -> false;
  70. is_community_umbrella_app("apps/emqx_bridge_cassandra") -> false;
  71. is_community_umbrella_app("apps/emqx_bridge_opents") -> false;
  72. is_community_umbrella_app("apps/emqx_bridge_clickhouse") -> false;
  73. is_community_umbrella_app("apps/emqx_bridge_dynamo") -> false;
  74. is_community_umbrella_app("apps/emqx_bridge_greptimedb") -> false;
  75. is_community_umbrella_app("apps/emqx_bridge_hstreamdb") -> false;
  76. is_community_umbrella_app("apps/emqx_bridge_influxdb") -> false;
  77. is_community_umbrella_app("apps/emqx_bridge_iotdb") -> false;
  78. is_community_umbrella_app("apps/emqx_bridge_matrix") -> false;
  79. is_community_umbrella_app("apps/emqx_bridge_mongodb") -> false;
  80. is_community_umbrella_app("apps/emqx_bridge_mysql") -> false;
  81. is_community_umbrella_app("apps/emqx_bridge_pgsql") -> false;
  82. is_community_umbrella_app("apps/emqx_bridge_pulsar") -> false;
  83. is_community_umbrella_app("apps/emqx_bridge_redis") -> false;
  84. is_community_umbrella_app("apps/emqx_bridge_rocketmq") -> false;
  85. is_community_umbrella_app("apps/emqx_bridge_tdengine") -> false;
  86. is_community_umbrella_app("apps/emqx_bridge_timescale") -> false;
  87. is_community_umbrella_app("apps/emqx_bridge_oracle") -> false;
  88. is_community_umbrella_app("apps/emqx_bridge_sqlserver") -> false;
  89. is_community_umbrella_app("apps/emqx_oracle") -> false;
  90. is_community_umbrella_app("apps/emqx_bridge_rabbitmq") -> false;
  91. is_community_umbrella_app("apps/emqx_ft") -> false;
  92. is_community_umbrella_app("apps/emqx_s3") -> false;
  93. is_community_umbrella_app("apps/emqx_bridge_s3") -> false;
  94. is_community_umbrella_app("apps/emqx_schema_registry") -> false;
  95. is_community_umbrella_app("apps/emqx_enterprise") -> false;
  96. is_community_umbrella_app("apps/emqx_bridge_kinesis") -> false;
  97. is_community_umbrella_app("apps/emqx_bridge_azure_event_hub") -> false;
  98. is_community_umbrella_app("apps/emqx_gcp_device") -> false;
  99. is_community_umbrella_app("apps/emqx_dashboard_rbac") -> false;
  100. is_community_umbrella_app("apps/emqx_dashboard_sso") -> false;
  101. is_community_umbrella_app("apps/emqx_audit") -> false;
  102. is_community_umbrella_app("apps/emqx_gateway_gbt32960") -> false;
  103. is_community_umbrella_app("apps/emqx_gateway_ocpp") -> false;
  104. is_community_umbrella_app("apps/emqx_gateway_jt808") -> false;
  105. is_community_umbrella_app("apps/emqx_bridge_syskeeper") -> false;
  106. is_community_umbrella_app("apps/emqx_message_validation") -> false;
  107. is_community_umbrella_app("apps/emqx_eviction_agent") -> false;
  108. is_community_umbrella_app("apps/emqx_node_rebalance") -> false;
  109. is_community_umbrella_app(_) -> true.
  110. %% BUILD_WITHOUT_JQ
  111. %% BUILD_WITHOUT_QUIC
  112. %% BUILD_WITHOUT_ROCKSDB
  113. is_build_without(Name) ->
  114. "1" =:= os:getenv("BUILD_WITHOUT_" ++ Name).
  115. %% BUILD_WITH_QUIC
  116. is_build_with(Name) ->
  117. "1" =:= os:getenv("BUILD_WITH_" ++ Name).
  118. is_jq_supported() ->
  119. not is_build_without("JQ").
  120. is_quicer_supported() ->
  121. %% for ones who want to build QUIC on macos
  122. %% export BUILD_WITH_QUIC=1
  123. is_build_with("QUIC") orelse
  124. is_quicer_supported(os:type()).
  125. is_quicer_supported({unix, darwin}) ->
  126. %% no quic on macos so far
  127. false;
  128. is_quicer_supported(_) ->
  129. not is_build_without("QUIC").
  130. is_rocksdb_supported() ->
  131. %% there is no way one can build rocksdb on raspbian
  132. %% so no need to check is_build_with
  133. Distro = os_cmd("./scripts/get-distro.sh"),
  134. is_rocksdb_supported(Distro).
  135. is_rocksdb_supported("respbian" ++ _) ->
  136. false;
  137. is_rocksdb_supported(_) ->
  138. not is_build_without("ROCKSDB").
  139. project_app_dirs() ->
  140. #{edition := Edition, reltype := RelType} = get_edition_from_profile_env(),
  141. project_app_dirs(Edition, RelType).
  142. project_app_dirs(Edition, RelType) ->
  143. IsEnterprise = is_enterprise(Edition),
  144. ExcludedApps = excluded_apps(RelType),
  145. UmbrellaApps = [
  146. Path
  147. || Path <- filelib:wildcard("apps/*"),
  148. not project_app_excluded(Path, ExcludedApps) andalso
  149. (is_community_umbrella_app(Path) orelse IsEnterprise)
  150. ],
  151. UmbrellaApps.
  152. project_app_excluded("apps/" ++ AppStr, ExcludedApps) ->
  153. App = list_to_atom(AppStr),
  154. lists:member(App, ExcludedApps).
  155. plugins() ->
  156. [
  157. %{relup_helper, {git, "https://github.com/emqx/relup_helper", {tag, "2.1.0"}}},
  158. %% emqx main project does not require port-compiler
  159. %% pin at root level for deterministic
  160. {pc, "v1.14.0"}
  161. ] ++
  162. %% test plugins are concatenated to default profile plugins
  163. %% otherwise rebar3 test profile runs are super slow
  164. test_plugins().
  165. test_plugins() ->
  166. [
  167. {rebar3_proper, "0.12.1"},
  168. {coveralls, {git, "https://github.com/emqx/coveralls-erl", {tag, "v2.2.0-emqx-1"}}}
  169. ].
  170. test_deps() ->
  171. [
  172. {bbmustache, "1.10.0"},
  173. {meck, "0.9.2"},
  174. {proper, "1.4.0"},
  175. {er_coap_client, {git, "https://github.com/emqx/er_coap_client", {tag, "v1.0.5"}}},
  176. {erl_csv, "0.2.0"},
  177. {eministat, "0.10.1"}
  178. ].
  179. common_compile_opts() ->
  180. #{edition := Edition, reltype := RelType} = get_edition_from_profile_env(),
  181. common_compile_opts(Edition, RelType, undefined).
  182. common_compile_opts(Edition, _RelType, Vsn) ->
  183. % always include debug_info
  184. [
  185. debug_info,
  186. {compile_info, [{emqx_vsn, Vsn} || Vsn /= undefined]},
  187. {d, 'EMQX_RELEASE_EDITION', Edition}
  188. ] ++
  189. [{d, 'EMQX_BENCHMARK'} || os:getenv("EMQX_BENCHMARK") =:= "1"] ++
  190. [{d, 'BUILD_WITHOUT_QUIC'} || not is_quicer_supported()].
  191. warn_profile_env() ->
  192. case os:getenv("PROFILE") of
  193. false ->
  194. io:format(
  195. standard_error,
  196. "WARN: environment variable PROFILE is not set, using 'emqx-enterprise'~n",
  197. []
  198. );
  199. _ ->
  200. ok
  201. end.
  202. %% this function is only used for test/check profiles
  203. get_edition_from_profile_env() ->
  204. case os:getenv("PROFILE") of
  205. "emqx-enterprise" ++ _ ->
  206. #{edition => ee, reltype => standard};
  207. "emqx" ++ _ ->
  208. #{edition => ce, reltype => standard};
  209. false ->
  210. #{edition => ee, reltype => standard};
  211. V ->
  212. io:format(standard_error, "ERROR: bad_PROFILE ~p~n", [V]),
  213. exit(bad_PROFILE)
  214. end.
  215. prod_compile_opts(Edition, RelType, Vsn) ->
  216. [
  217. compressed,
  218. deterministic,
  219. warnings_as_errors
  220. | common_compile_opts(Edition, RelType, Vsn)
  221. ].
  222. prod_overrides() ->
  223. [{add, [{erl_opts, [deterministic]}]}].
  224. profiles() ->
  225. #{edition := Edition, reltype := RelType} = get_edition_from_profile_env(),
  226. case Edition of
  227. ee ->
  228. profiles_ee(RelType);
  229. ce ->
  230. profiles_ce(RelType)
  231. end ++ profiles_dev(RelType).
  232. profiles_ce(RelType) ->
  233. Vsn = get_vsn(emqx),
  234. [
  235. {'emqx', [
  236. {erl_opts, prod_compile_opts(ce, RelType, Vsn)},
  237. {relx, relx(Vsn, RelType, bin, ce)},
  238. {overrides, prod_overrides()},
  239. {project_app_dirs, project_app_dirs(ce, RelType)}
  240. ]},
  241. {'emqx-pkg', [
  242. {erl_opts, prod_compile_opts(ce, RelType, Vsn)},
  243. {relx, relx(Vsn, RelType, pkg, ce)},
  244. {overrides, prod_overrides()},
  245. {project_app_dirs, project_app_dirs(ce, RelType)}
  246. ]}
  247. ].
  248. profiles_ee(RelType) ->
  249. Vsn = get_vsn('emqx-enterprise'),
  250. [
  251. {'emqx-enterprise', [
  252. {erl_opts, prod_compile_opts(ee, RelType, Vsn)},
  253. {relx, relx(Vsn, RelType, bin, ee)},
  254. {overrides, prod_overrides()},
  255. {project_app_dirs, project_app_dirs(ee, RelType)}
  256. ]},
  257. {'emqx-enterprise-pkg', [
  258. {erl_opts, prod_compile_opts(ee, RelType, Vsn)},
  259. {relx, relx(Vsn, RelType, pkg, ee)},
  260. {overrides, prod_overrides()},
  261. {project_app_dirs, project_app_dirs(ee, RelType)}
  262. ]}
  263. ].
  264. %% EE has more files than CE, always test/check with EE options.
  265. profiles_dev(_RelType) ->
  266. [
  267. {check, [
  268. {erl_opts, common_compile_opts()},
  269. {project_app_dirs, project_app_dirs()}
  270. ]},
  271. {test, [
  272. {deps, test_deps()},
  273. {erl_opts, common_compile_opts() ++ erl_opts_i()},
  274. {extra_src_dirs, [{"test", [{recursive, true}]}]},
  275. {project_app_dirs, project_app_dirs()}
  276. ]}
  277. ].
  278. %% RelType: standard
  279. %% PkgType: bin | pkg
  280. %% Edition: ce (opensource) | ee (enterprise)
  281. relx(Vsn, RelType, PkgType, Edition) ->
  282. [
  283. {include_src, false},
  284. {include_erts, true},
  285. {extended_start_script, false},
  286. {generate_start_script, false},
  287. {sys_config, false},
  288. {vm_args, false},
  289. {release, {emqx, Vsn}, relx_apps(RelType, Edition)},
  290. {overlay, relx_overlay(RelType, Edition)},
  291. {overlay_vars_values,
  292. build_info() ++
  293. [
  294. {emqx_description, emqx_description(RelType, Edition)}
  295. | overlay_vars(RelType, PkgType, Edition)
  296. ]}
  297. ].
  298. %% Make a HOCON compatible format
  299. build_info() ->
  300. Os = os_cmd("./scripts/get-distro.sh"),
  301. [
  302. {build_info_arch, erlang:system_info(system_architecture)},
  303. {build_info_wordsize, rebar_utils:wordsize()},
  304. {build_info_os, Os},
  305. {build_info_erlang, rebar_utils:otp_release()},
  306. {build_info_elixir, none},
  307. {build_info_relform, relform()}
  308. ].
  309. relform() ->
  310. case os:getenv("EMQX_REL_FORM") of
  311. false -> "tgz";
  312. Other -> Other
  313. end.
  314. emqx_description(_, ee) -> "EMQX Enterprise";
  315. emqx_description(_, ce) -> "EMQX".
  316. overlay_vars(_RelType, PkgType, Edition) ->
  317. [
  318. {emqx_default_erlang_cookie, "emqxsecretcookie"}
  319. ] ++
  320. overlay_vars_pkg(PkgType) ++
  321. overlay_vars_edition(Edition).
  322. overlay_vars_edition(ce) ->
  323. [
  324. {emqx_schema_mod, emqx_conf_schema},
  325. {is_enterprise, "no"},
  326. {emqx_configuration_doc,
  327. "https://www.emqx.io/docs/en/latest/configuration/configuration.html"},
  328. {emqx_configuration_doc_log, "https://www.emqx.io/docs/en/latest/configuration/logs.html"}
  329. ];
  330. overlay_vars_edition(ee) ->
  331. [
  332. {emqx_schema_mod, emqx_enterprise_schema},
  333. {is_enterprise, "yes"},
  334. {emqx_configuration_doc,
  335. "https://docs.emqx.com/en/enterprise/latest/configuration/configuration.html"},
  336. {emqx_configuration_doc_log,
  337. "https://docs.emqx.com/en/enterprise/latest/configuration/logs.html"}
  338. ].
  339. %% vars per packaging type, bin(zip/tar.gz/docker) or pkg(rpm/deb)
  340. overlay_vars_pkg(bin) ->
  341. [
  342. {platform_data_dir, "data"},
  343. {platform_etc_dir, "etc"},
  344. {platform_plugins_dir, "plugins"},
  345. {runner_bin_dir, "$RUNNER_ROOT_DIR/bin"},
  346. {emqx_etc_dir, "$RUNNER_ROOT_DIR/etc"},
  347. {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"},
  348. {runner_log_dir, "$RUNNER_ROOT_DIR/log"},
  349. {runner_user, ""},
  350. {is_elixir, "no"}
  351. ];
  352. overlay_vars_pkg(pkg) ->
  353. [
  354. {platform_data_dir, "/var/lib/emqx"},
  355. {platform_etc_dir, "/etc/emqx"},
  356. {platform_plugins_dir, "/var/lib/emqx/plugins"},
  357. {runner_bin_dir, "/usr/bin"},
  358. {emqx_etc_dir, "/etc/emqx"},
  359. {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"},
  360. {runner_log_dir, "/var/log/emqx"},
  361. {runner_user, "emqx"},
  362. {is_elixir, "no"}
  363. ].
  364. relx_apps(ReleaseType, Edition) ->
  365. {ok, [
  366. #{
  367. db_apps := DBApps,
  368. system_apps := SystemApps,
  369. common_business_apps := CommonBusinessApps,
  370. ee_business_apps := EEBusinessApps,
  371. ce_business_apps := CEBusinessApps
  372. }
  373. ]} = file:consult("apps/emqx_machine/priv/reboot_lists.eterm"),
  374. EditionSpecificApps =
  375. case Edition of
  376. ee -> EEBusinessApps;
  377. ce -> CEBusinessApps
  378. end,
  379. BusinessApps = CommonBusinessApps ++ EditionSpecificApps,
  380. ExcludedApps = excluded_apps(ReleaseType),
  381. Apps =
  382. ([App || App <- SystemApps, not lists:member(App, ExcludedApps)] ++
  383. %% EMQX starts the DB and the business applications:
  384. [{App, load} || App <- DBApps, not lists:member(App, ExcludedApps)] ++
  385. [emqx_machine] ++
  386. [{App, load} || App <- BusinessApps, not lists:member(App, ExcludedApps)]),
  387. Apps.
  388. excluded_apps(_RelType) ->
  389. OptionalApps = [
  390. {quicer, is_quicer_supported()},
  391. {jq, is_jq_supported()},
  392. {observer, is_app(observer)},
  393. {mnesia_rocksdb, is_rocksdb_supported()}
  394. ],
  395. [App || {App, false} <- OptionalApps].
  396. is_app(Name) ->
  397. case application:load(Name) of
  398. ok -> true;
  399. {error, {already_loaded, _}} -> true;
  400. _ -> false
  401. end.
  402. relx_overlay(ReleaseType, Edition) ->
  403. [
  404. {mkdir, "log/"},
  405. {mkdir, "data/"},
  406. {mkdir, "plugins"},
  407. {mkdir, "data/mnesia"},
  408. {mkdir, "data/configs"},
  409. {mkdir, "data/patches"},
  410. {mkdir, "data/scripts"},
  411. {template, "rel/emqx_vars", "releases/emqx_vars"},
  412. {template, "rel/BUILD_INFO", "releases/{{release_version}}/BUILD_INFO"},
  413. {copy, "bin/emqx", "bin/emqx"},
  414. {copy, "bin/emqx_ctl", "bin/emqx_ctl"},
  415. {copy, "bin/emqx_cluster_rescue", "bin/emqx_cluster_rescue"},
  416. {copy, "bin/node_dump", "bin/node_dump"},
  417. {copy, "bin/install_upgrade.escript", "bin/install_upgrade.escript"},
  418. {copy, "bin/emqx", "bin/emqx-{{release_version}}"},
  419. {copy, "bin/emqx_ctl", "bin/emqx_ctl-{{release_version}}"},
  420. {copy, "bin/install_upgrade.escript", "bin/install_upgrade.escript-{{release_version}}"},
  421. {copy, "apps/emqx_gateway_lwm2m/lwm2m_xml", "etc/lwm2m_xml"},
  422. {copy, "apps/emqx_auth/etc/acl.conf", "etc/acl.conf"},
  423. {template, "bin/emqx.cmd", "bin/emqx.cmd"},
  424. {template, "bin/emqx_ctl.cmd", "bin/emqx_ctl.cmd"},
  425. {copy, "bin/nodetool", "bin/nodetool"},
  426. {copy, "bin/nodetool", "bin/nodetool-{{release_version}}"}
  427. ] ++ etc_overlay(ReleaseType, Edition).
  428. etc_overlay(ReleaseType, Edition) ->
  429. Templates = emqx_etc_overlay(ReleaseType),
  430. [
  431. {mkdir, "etc/"},
  432. {copy, "{{base_dir}}/lib/emqx/etc/certs", "etc/"}
  433. | copy_examples(Edition)
  434. ] ++
  435. lists:map(
  436. fun
  437. ({From, To}) -> {template, From, To};
  438. (FromTo) -> {template, FromTo, FromTo}
  439. end,
  440. Templates
  441. ).
  442. copy_examples(ce) ->
  443. [{copy, "rel/config/examples", "etc/"}];
  444. copy_examples(ee) ->
  445. [
  446. {copy, "rel/config/examples", "etc/"},
  447. {copy, "rel/config/ee-examples/*", "etc/examples/"}
  448. ].
  449. emqx_etc_overlay(ReleaseType) ->
  450. emqx_etc_overlay_per_rel(ReleaseType) ++
  451. emqx_etc_overlay().
  452. emqx_etc_overlay_per_rel(_RelType) ->
  453. [{"{{base_dir}}/lib/emqx/etc/vm.args.cloud", "etc/vm.args"}].
  454. emqx_etc_overlay() ->
  455. [
  456. {"{{base_dir}}/lib/emqx/etc/ssl_dist.conf", "etc/ssl_dist.conf"},
  457. {"{{base_dir}}/lib/emqx_conf/etc/emqx.conf.all", "etc/emqx.conf"}
  458. ].
  459. get_vsn(Profile) ->
  460. case os:getenv("PKG_VSN") of
  461. false ->
  462. os_cmd("pkg-vsn.sh " ++ atom_to_list(Profile));
  463. Vsn ->
  464. Vsn
  465. end.
  466. %% to make it compatible to Linux and Windows,
  467. %% we must use bash to execute the bash file
  468. %% because "./" will not be recognized as an internal or external command
  469. os_cmd(Cmd) ->
  470. Output = os:cmd("bash " ++ Cmd),
  471. re:replace(Output, "\n", "", [{return, list}]).
  472. maybe_dump(Config) ->
  473. is_debug() andalso
  474. file:write_file("rebar.config.rendered", [io_lib:format("~p.\n", [I]) || I <- Config]),
  475. Config.
  476. is_debug() -> is_debug("DEBUG") orelse is_debug("DIAGNOSTIC").
  477. is_debug(VarName) ->
  478. case os:getenv(VarName) of
  479. false -> false;
  480. "" -> false;
  481. _ -> true
  482. end.
  483. erl_opts_i() ->
  484. [{i, "apps"}] ++
  485. [{i, Dir} || Dir <- filelib:wildcard(filename:join(["apps", "*", "include"]))].
  486. dialyzer(Config) ->
  487. {dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config),
  488. AppsToAnalyse =
  489. case os:getenv("DIALYZER_ANALYSE_APP") of
  490. false ->
  491. [];
  492. Value ->
  493. [list_to_atom(App) || App <- string:tokens(Value, ",")]
  494. end,
  495. AppNames = app_names(),
  496. KnownApps = [Name || Name <- AppsToAnalyse, lists:member(Name, AppNames)],
  497. ExcludedApps = excluded_apps(standard),
  498. AppsToExclude = ExcludedApps ++ (AppNames -- KnownApps),
  499. Extra =
  500. [system_monitor, tools, covertool] ++
  501. [jq || is_jq_supported()] ++
  502. [quicer || is_quicer_supported()],
  503. NewDialyzerConfig =
  504. OldDialyzerConfig ++
  505. [{exclude_apps, AppsToExclude} || length(AppsToAnalyse) > 0] ++
  506. [{plt_extra_apps, Extra} || length(Extra) > 0],
  507. lists:keystore(
  508. dialyzer,
  509. 1,
  510. Config,
  511. {dialyzer, NewDialyzerConfig}
  512. ).
  513. coveralls() ->
  514. case {os:getenv("GITHUB_ACTIONS"), os:getenv("GITHUB_TOKEN")} of
  515. {"true", Token} when is_list(Token) ->
  516. Cfgs = [
  517. {coveralls_repo_token, Token},
  518. {coveralls_service_job_id, os:getenv("GITHUB_RUN_ID")},
  519. {coveralls_commit_sha, os:getenv("GITHUB_SHA")},
  520. {coveralls_coverdata, "_build/test/cover/*.coverdata"},
  521. {coveralls_parallel, true},
  522. {coveralls_service_name, "github"}
  523. ],
  524. case
  525. os:getenv("GITHUB_EVENT_NAME") =:= "pull_request" andalso
  526. string:tokens(os:getenv("GITHUB_REF"), "/")
  527. of
  528. [_, "pull", PRNO, _] ->
  529. [{coveralls_service_pull_request, PRNO} | Cfgs];
  530. _ ->
  531. Cfgs
  532. end;
  533. _ ->
  534. []
  535. end.
  536. app_names() -> list_dir("apps").
  537. list_dir(Dir) ->
  538. case filelib:is_dir(Dir) of
  539. true ->
  540. {ok, Names} = file:list_dir(Dir),
  541. [list_to_atom(Name) || Name <- Names, filelib:is_dir(filename:join([Dir, Name]))];
  542. false ->
  543. []
  544. end.