rebar.config.erl 20 KB

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