Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

2410 wiersze
93 KiB

10 lat temu
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 lat temu
10 lat temu
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 lat temu
10 lat temu
10 lat temu
10 lat temu
10 lat temu
10 lat temu
10 lat temu
10 lat temu
10 lat temu
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 lat temu
  1. -module(rebar_compile_SUITE).
  2. -compile(export_all).
  3. -include_lib("common_test/include/ct.hrl").
  4. -include_lib("eunit/include/eunit.hrl").
  5. -include_lib("kernel/include/file.hrl").
  6. suite() ->
  7. [].
  8. all() ->
  9. [{group, basic_app}, {group, release_apps},
  10. {group, checkout_apps}, {group, checkout_deps},
  11. {group, basic_srcdirs}, {group, release_srcdirs}, {group, unbalanced_srcdirs},
  12. {group, basic_extras}, {group, release_extras}, {group, unbalanced_extras},
  13. {group, root_extras},
  14. recompile_when_hrl_changes, recompile_when_included_hrl_changes,
  15. recompile_when_opts_included_hrl_changes,
  16. recompile_when_opts_change,
  17. dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl,
  18. delete_beam_if_source_deleted,
  19. deps_in_path, checkout_priority, highest_version_of_pkg_dep,
  20. parse_transform_test, erl_first_files_test, mib_test,
  21. umbrella_mib_first_test, only_default_transitive_deps, clean_all,
  22. profile_deps, deps_build_in_prod, only_deps,
  23. override_deps, override_add_deps, override_del_deps,
  24. override_opts, override_add_opts, override_del_opts,
  25. apply_overrides_exactly_once,
  26. profile_override_deps, profile_override_add_deps, profile_override_del_deps,
  27. profile_override_opts, profile_override_add_opts, profile_override_del_opts,
  28. include_file_relative_to_working_directory, include_file_in_src,
  29. include_file_relative_to_working_directory_test, include_file_in_src_test,
  30. include_file_in_src_test_multiapp,
  31. recompile_when_parse_transform_as_opt_changes,
  32. recompile_when_parse_transform_inline_changes,
  33. regex_filter_skip, regex_filter_regression,
  34. recursive, no_recursive,
  35. always_recompile_when_erl_compiler_options_set,
  36. dont_recompile_when_erl_compiler_options_env_does_not_change,
  37. recompile_when_erl_compiler_options_env_changes,
  38. rebar_config_os_var].
  39. groups() ->
  40. [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]},
  41. {release_apps, [], [build_release_apps, paths_release_apps, clean_release_apps]},
  42. {checkout_apps, [], [build_checkout_apps, paths_checkout_apps]},
  43. {checkout_deps, [], [build_checkout_deps, paths_checkout_deps]},
  44. {basic_srcdirs, [], [build_basic_srcdirs, paths_basic_srcdirs]},
  45. {release_srcdirs, [], [build_release_srcdirs,
  46. paths_release_srcdirs]},
  47. {unbalanced_srcdirs, [], [build_unbalanced_srcdirs,
  48. paths_unbalanced_srcdirs]},
  49. {basic_extras, [], [build_basic_extra_dirs,
  50. paths_basic_extra_dirs,
  51. clean_basic_extra_dirs]},
  52. {release_extras, [], [build_release_extra_dirs,
  53. paths_release_extra_dirs,
  54. clean_release_extra_dirs]},
  55. {unbalanced_extras, [], [build_unbalanced_extra_dirs,
  56. paths_unbalanced_extra_dirs]},
  57. {root_extras, [], [build_extra_dirs_in_project_root,
  58. paths_extra_dirs_in_project_root,
  59. clean_extra_dirs_in_project_root]}].
  60. init_per_group(basic_app, Config) ->
  61. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  62. AppDir = ?config(apps, NewConfig),
  63. Name = rebar_test_utils:create_random_name("app1"),
  64. Vsn = rebar_test_utils:create_random_vsn(),
  65. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  66. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  67. init_per_group(release_apps, Config) ->
  68. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_apps_"),
  69. AppDir = ?config(apps, NewConfig),
  70. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  71. Vsn1 = rebar_test_utils:create_random_vsn(),
  72. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  73. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  74. Vsn2 = rebar_test_utils:create_random_vsn(),
  75. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  76. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  77. init_per_group(checkout_apps, Config) ->
  78. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_apps_"),
  79. AppDir = ?config(apps, NewConfig),
  80. CheckoutsDir = ?config(checkouts, NewConfig),
  81. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  82. Vsn1 = rebar_test_utils:create_random_vsn(),
  83. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  84. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  85. Vsn2 = rebar_test_utils:create_random_vsn(),
  86. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  87. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  88. init_per_group(checkout_deps, Config) ->
  89. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_deps_"),
  90. AppDir = ?config(apps, NewConfig),
  91. CheckoutsDir = ?config(checkouts, NewConfig),
  92. DepsDir = filename:join([AppDir, "_build", "default", "lib"]),
  93. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  94. Vsn1 = rebar_test_utils:create_random_vsn(),
  95. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  96. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  97. Vsn2 = rebar_test_utils:create_random_vsn(),
  98. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  99. rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]),
  100. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  101. init_per_group(Group, Config) when Group == basic_srcdirs; Group == basic_extras ->
  102. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_srcdirs_"),
  103. AppDir = ?config(apps, NewConfig),
  104. Name = rebar_test_utils:create_random_name("app1_"),
  105. Vsn = rebar_test_utils:create_random_vsn(),
  106. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  107. ExtraSrc = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name]),
  108. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  109. ok = file:write_file(filename:join([AppDir, "extra", io_lib:format("~ts_extra.erl", [Name])]),
  110. ExtraSrc),
  111. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  112. init_per_group(Group, Config) when Group == release_srcdirs; Group == release_extras ->
  113. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_srcdirs_"),
  114. AppDir = ?config(apps, NewConfig),
  115. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  116. Vsn1 = rebar_test_utils:create_random_vsn(),
  117. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  118. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  119. Vsn2 = rebar_test_utils:create_random_vsn(),
  120. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  121. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  122. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  123. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  124. io_lib:format("~ts_extra.erl", [Name1])]),
  125. ExtraOne),
  126. ExtraTwo = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name2]),
  127. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "extra", "dummy"])),
  128. ok = file:write_file(filename:join([AppDir, "apps", Name2, "extra",
  129. io_lib:format("~ts_extra.erl", [Name2])]),
  130. ExtraTwo),
  131. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  132. init_per_group(Group, Config) when Group == unbalanced_srcdirs; Group == unbalanced_extras ->
  133. NewConfig = rebar_test_utils:init_rebar_state(Config, "unbalanced_srcdirs_"),
  134. AppDir = ?config(apps, NewConfig),
  135. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  136. Vsn1 = rebar_test_utils:create_random_vsn(),
  137. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  138. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  139. Vsn2 = rebar_test_utils:create_random_vsn(),
  140. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  141. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  142. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  143. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  144. io_lib:format("~ts_extra.erl", [Name1])]),
  145. ExtraOne),
  146. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  147. init_per_group(root_extras, Config) ->
  148. NewConfig = rebar_test_utils:init_rebar_state(Config, "root_extras_"),
  149. AppDir = ?config(apps, NewConfig),
  150. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  151. Vsn1 = rebar_test_utils:create_random_vsn(),
  152. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  153. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  154. Vsn2 = rebar_test_utils:create_random_vsn(),
  155. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  156. Extra = <<"-module(extra).\n-export([ok/0]).\nok() -> ok.\n">>,
  157. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  158. ok = file:write_file(filename:join([AppDir, "extra", "extra.erl"]), Extra),
  159. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig].
  160. end_per_group(_Group, _Config) ->
  161. ok.
  162. init_per_suite(Config) ->
  163. Config.
  164. end_per_suite(_Config) ->
  165. ok.
  166. init_per_testcase(Test, Config) when
  167. Test == dont_recompile_when_erl_compiler_options_env_does_not_change
  168. orelse
  169. Test == recompile_when_erl_compiler_options_env_changes ->
  170. _ = code:ensure_loaded(os),
  171. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  172. _ = code:ensure_loaded(compile),
  173. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  174. case {UnSetEnv, EnvOpts} of
  175. {true, true} -> maybe_init_config(Config);
  176. _ -> {skip, "compile:env_compiler_options/0 unavailable"}
  177. end;
  178. init_per_testcase(always_recompile_when_erl_compiler_options_set, Config) ->
  179. _ = code:ensure_loaded(os),
  180. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  181. _ = code:ensure_loaded(compile),
  182. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  183. case {UnSetEnv, EnvOpts} of
  184. {true, true} -> {skip, "compile:env_compiler_options/0 available"};
  185. {true, false} -> maybe_init_config(Config);
  186. _ -> {skip, "os:unsetenv/1 unavailable"}
  187. end;
  188. init_per_testcase(_, Config) -> maybe_init_config(Config).
  189. maybe_init_config(Config) ->
  190. case ?config(apps, Config) of
  191. undefined -> rebar_test_utils:init_rebar_state(Config);
  192. _ -> Config
  193. end.
  194. end_per_testcase(_, _Config) ->
  195. catch meck:unload().
  196. %% test cases
  197. build_basic_app(Config) ->
  198. [Name] = ?config(app_names, Config),
  199. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
  200. build_release_apps(Config) ->
  201. [Name1, Name2] = ?config(app_names, Config),
  202. rebar_test_utils:run_and_check(
  203. Config, [], ["compile"],
  204. {ok, [{app, Name1}, {app, Name2}]}
  205. ).
  206. build_checkout_apps(Config) ->
  207. [Name1, Name2] = ?config(app_names, Config),
  208. rebar_test_utils:run_and_check(
  209. Config, [], ["compile"],
  210. {ok, [{app, Name1}, {checkout, Name2}]}
  211. ).
  212. build_checkout_deps(Config) ->
  213. AppDir = ?config(apps, Config),
  214. [Name1, Name2] = ?config(app_names, Config),
  215. [_, Vsn2] = ?config(vsns, Config),
  216. Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}],
  217. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])),
  218. rebar_test_utils:run_and_check(
  219. Config, RebarConfig, ["compile"],
  220. {ok, [{app, Name1}, {checkout, Name2}]}
  221. ).
  222. build_basic_srcdirs(Config) ->
  223. AppDir = ?config(apps, Config),
  224. [Name] = ?config(app_names, Config),
  225. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  226. %% check a beam corresponding to the src in the extra src_dir exists
  227. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  228. io_lib:format("~ts_extra.beam", [Name])]),
  229. %% check the extra src_dir was copied/linked into the _build dir
  230. ExtraDir = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  231. rebar_test_utils:run_and_check(
  232. Config, RebarConfig, ["compile"],
  233. {ok, [{app, Name}, {file, ExtraBeam}, {dir, ExtraDir}]}
  234. ).
  235. build_release_srcdirs(Config) ->
  236. AppDir = ?config(apps, Config),
  237. [Name1, Name2] = ?config(app_names, Config),
  238. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  239. %% check a beam corresponding to the src in the extra src_dir exists
  240. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  241. io_lib:format("~ts_extra.beam", [Name1])]),
  242. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  243. io_lib:format("~ts_extra.beam", [Name2])]),
  244. %% check the extra src_dir was copied/linked into the _build dir
  245. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  246. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  247. rebar_test_utils:run_and_check(
  248. Config, RebarConfig, ["compile"],
  249. {ok, [{app, Name1}, {app, Name2},
  250. {file, Extra1Beam}, {file, Extra2Beam},
  251. {dir, Extra1Dir}, {dir, Extra2Dir}]}
  252. ).
  253. build_unbalanced_srcdirs(Config) ->
  254. AppDir = ?config(apps, Config),
  255. [Name1, Name2] = ?config(app_names, Config),
  256. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  257. %% check a beam corresponding to the src in the extra src_dir exists
  258. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  259. io_lib:format("~ts_extra.beam", [Name1])]),
  260. %% check the extra src_dir was copied/linked into the _build dir
  261. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  262. rebar_test_utils:run_and_check(
  263. Config, RebarConfig, ["compile"],
  264. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {dir, Extra1Dir}]}
  265. ),
  266. %% check no extra src_dir were copied/linked into the _build dir
  267. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  268. false = filelib:is_dir(Extra2Dir),
  269. %% check only expected beams are in the ebin dir
  270. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  271. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  272. Files).
  273. build_basic_extra_dirs(Config) ->
  274. AppDir = ?config(apps, Config),
  275. [Name] = ?config(app_names, Config),
  276. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  277. %% check a beam corresponding to the src in the extra src_dir exists
  278. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  279. io_lib:format("~ts_extra.beam", [Name])]),
  280. rebar_test_utils:run_and_check(
  281. Config, RebarConfig, ["compile"],
  282. {ok, [{app, Name}, {file, ExtraBeam}]}
  283. ).
  284. build_release_extra_dirs(Config) ->
  285. AppDir = ?config(apps, Config),
  286. [Name1, Name2] = ?config(app_names, Config),
  287. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  288. %% check a beam corresponding to the src in the extra src_dir exists
  289. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  290. io_lib:format("~ts_extra.beam", [Name1])]),
  291. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  292. io_lib:format("~ts_extra.beam", [Name2])]),
  293. rebar_test_utils:run_and_check(
  294. Config, RebarConfig, ["compile"],
  295. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {file, Extra2Beam}]}
  296. ).
  297. build_unbalanced_extra_dirs(Config) ->
  298. AppDir = ?config(apps, Config),
  299. [Name1, Name2] = ?config(app_names, Config),
  300. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  301. %% check a beam corresponding to the src in the extra src_dir exists
  302. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  303. io_lib:format("~ts_extra.beam", [Name1])]),
  304. rebar_test_utils:run_and_check(
  305. Config, RebarConfig, ["compile"],
  306. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}]}
  307. ),
  308. %% check no extra src_dir were copied/linked into the _build dir
  309. false = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "extra"])),
  310. %% check only expected beams are in the ebin dir
  311. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  312. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  313. Files).
  314. build_extra_dirs_in_project_root(Config) ->
  315. AppDir = ?config(apps, Config),
  316. [Name1, Name2] = ?config(app_names, Config),
  317. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  318. %% check a beam corresponding to the src in the extra src_dir exists
  319. ExtraBeam = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  320. rebar_test_utils:run_and_check(
  321. Config, RebarConfig, ["compile"],
  322. {ok, [{app, Name1}, {app, Name2}, {file, ExtraBeam}]}
  323. ).
  324. paths_basic_app(Config) ->
  325. [Name] = ?config(app_names, Config),
  326. [Vsn] = ?config(vsns, Config),
  327. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  328. code:add_paths(rebar_state:code_paths(State, all_deps)),
  329. ok = application:load(list_to_atom(Name)),
  330. Loaded = application:loaded_applications(),
  331. {_, _, Vsn} = lists:keyfind(list_to_atom(Name), 1, Loaded).
  332. paths_release_apps(Config) ->
  333. [Name1, Name2] = ?config(app_names, Config),
  334. [Vsn1, Vsn2] = ?config(vsns, Config),
  335. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  336. code:add_paths(rebar_state:code_paths(State, all_deps)),
  337. ok = application:load(list_to_atom(Name1)),
  338. ok = application:load(list_to_atom(Name2)),
  339. Loaded = application:loaded_applications(),
  340. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded),
  341. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  342. paths_checkout_apps(Config) ->
  343. [Name1, _Name2] = ?config(app_names, Config),
  344. [Vsn1, _Vsn2] = ?config(vsns, Config),
  345. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  346. code:add_paths(rebar_state:code_paths(State, all_deps)),
  347. ok = application:load(list_to_atom(Name1)),
  348. Loaded = application:loaded_applications(),
  349. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded).
  350. paths_checkout_deps(Config) ->
  351. AppDir = ?config(apps, Config),
  352. [_Name1, Name2] = ?config(app_names, Config),
  353. [_Vsn1, Vsn2] = ?config(vsns, Config),
  354. %% rebar_test_utils:init_rebar_state/1,2 uses rebar_state:new/3 which
  355. %% maybe incorrectly sets deps to [] (based on `rebar.lock`) instead of
  356. %% to the checkapps
  357. %% until that is sorted out the lock file has to be removed before
  358. %% this test will pass
  359. file:delete(filename:join([AppDir, "rebar.lock"])),
  360. {ok, RebarConfig} = file:consult(filename:join([AppDir, "rebar.config"])),
  361. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  362. code:add_paths(rebar_state:code_paths(State, all_deps)),
  363. ok = application:load(list_to_atom(Name2)),
  364. Loaded = application:loaded_applications(),
  365. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  366. paths_basic_srcdirs(Config) ->
  367. AppDir = ?config(apps, Config),
  368. [Name] = ?config(app_names, Config),
  369. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  370. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  371. code:add_paths(rebar_state:code_paths(State, all_deps)),
  372. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  373. {module, Mod} = code:ensure_loaded(Mod),
  374. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  375. io_lib:format("~ts_extra.beam", [Name])]),
  376. Expect = code:which(Mod).
  377. paths_release_srcdirs(Config) ->
  378. AppDir = ?config(apps, Config),
  379. [Name1, Name2] = ?config(app_names, Config),
  380. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  381. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  382. code:add_paths(rebar_state:code_paths(State, all_deps)),
  383. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  384. {module, Mod1} = code:ensure_loaded(Mod1),
  385. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  386. {module, Mod2} = code:ensure_loaded(Mod2),
  387. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  388. io_lib:format("~ts_extra.beam", [Name1])]),
  389. ExpectOne = code:which(Mod1),
  390. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  391. io_lib:format("~ts_extra.beam", [Name2])]),
  392. ExpectTwo = code:which(Mod2).
  393. paths_unbalanced_srcdirs(Config) ->
  394. AppDir = ?config(apps, Config),
  395. [Name1, Name2] = ?config(app_names, Config),
  396. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  397. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  398. code:add_paths(rebar_state:code_paths(State, all_deps)),
  399. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  400. {module, Mod1} = code:ensure_loaded(Mod1),
  401. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  402. {error, nofile} = code:ensure_loaded(Mod2),
  403. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  404. io_lib:format("~ts_extra.beam", [Name1])]),
  405. ExpectOne = code:which(Mod1).
  406. paths_basic_extra_dirs(Config) ->
  407. AppDir = ?config(apps, Config),
  408. [Name] = ?config(app_names, Config),
  409. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  410. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  411. code:add_paths(rebar_state:code_paths(State, all_deps)),
  412. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  413. {module, Mod} = code:ensure_loaded(Mod),
  414. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  415. io_lib:format("~ts_extra.beam", [Name])]),
  416. Expect = code:which(Mod).
  417. paths_release_extra_dirs(Config) ->
  418. AppDir = ?config(apps, Config),
  419. [Name1, Name2] = ?config(app_names, Config),
  420. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  421. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  422. code:add_paths(rebar_state:code_paths(State, all_deps)),
  423. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  424. {module, Mod1} = code:ensure_loaded(Mod1),
  425. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  426. {module, Mod2} = code:ensure_loaded(Mod2),
  427. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  428. io_lib:format("~ts_extra.beam", [Name1])]),
  429. ExpectOne = code:which(Mod1),
  430. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  431. io_lib:format("~ts_extra.beam", [Name2])]),
  432. ExpectTwo = code:which(Mod2).
  433. paths_unbalanced_extra_dirs(Config) ->
  434. AppDir = ?config(apps, Config),
  435. [Name1, Name2] = ?config(app_names, Config),
  436. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  437. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  438. code:add_paths(rebar_state:code_paths(State, all_deps)),
  439. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  440. {module, Mod1} = code:ensure_loaded(Mod1),
  441. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  442. {error, nofile} = code:ensure_loaded(Mod2),
  443. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  444. io_lib:format("~ts_extra.beam", [Name1])]),
  445. ExpectOne = code:which(Mod1).
  446. paths_extra_dirs_in_project_root(Config) ->
  447. AppDir = ?config(apps, Config),
  448. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  449. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  450. code:add_paths(rebar_state:code_paths(State, all_deps)),
  451. {module, extra} = code:ensure_loaded(extra),
  452. Expect = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  453. Expect = code:which(extra).
  454. clean_basic_app(Config) ->
  455. [Name] = ?config(app_names, Config),
  456. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}).
  457. clean_release_apps(Config) ->
  458. [Name1, Name2] = ?config(app_names, Config),
  459. rebar_test_utils:run_and_check(Config, [], ["clean"],
  460. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}).
  461. clean_basic_extra_dirs(Config) ->
  462. AppDir = ?config(apps, Config),
  463. [Name] = ?config(app_names, Config),
  464. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}),
  465. Beam = lists:flatten(io_lib:format("~ts_extra", [Name])),
  466. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name, "extras", Beam])).
  467. clean_release_extra_dirs(Config) ->
  468. AppDir = ?config(apps, Config),
  469. [Name1, Name2] = ?config(app_names, Config),
  470. rebar_test_utils:run_and_check(Config, [], ["clean"],
  471. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  472. Beam1 = lists:flatten(io_lib:format("~ts_extra", [Name1])),
  473. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name1, "extras", Beam1])),
  474. Beam2 = lists:flatten(io_lib:format("~ts_extra", [Name2])),
  475. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name2, "extras", Beam2])).
  476. clean_extra_dirs_in_project_root(Config) ->
  477. AppDir = ?config(apps, Config),
  478. [Name1, Name2] = ?config(app_names, Config),
  479. rebar_test_utils:run_and_check(Config, [], ["clean"],
  480. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  481. false = ec_file:exists(filename:join([AppDir, "_build", "default", "extras"])).
  482. recompile_when_hrl_changes(Config) ->
  483. AppDir = ?config(apps, Config),
  484. Name = rebar_test_utils:create_random_name("app1_"),
  485. Vsn = rebar_test_utils:create_random_vsn(),
  486. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  487. ExtraSrc = <<"-module(test_header_include).\n"
  488. "-export([main/0]).\n"
  489. "-include(\"test_header_include.hrl\").\n"
  490. "main() -> ?SOME_DEFINE.\n">>,
  491. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  492. HeaderFile = filename:join([AppDir, "src", "test_header_include.hrl"]),
  493. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  494. ok = file:write_file(HeaderFile, ExtraHeader),
  495. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  496. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  497. {ok, Files} = rebar_utils:list_dir(EbinDir),
  498. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  499. || F <- Files, filename:extension(F) == ".beam"],
  500. timer:sleep(1000),
  501. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  502. ok = file:write_file(HeaderFile, NewExtraHeader),
  503. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  504. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  505. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  506. || F <- NewFiles, filename:extension(F) == ".beam"],
  507. ?assert(ModTime =/= NewModTime).
  508. recompile_when_included_hrl_changes(Config) ->
  509. AppDir = ?config(apps, Config),
  510. Name = rebar_test_utils:create_random_name("app1_"),
  511. Vsn = rebar_test_utils:create_random_vsn(),
  512. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  513. ExtraSrc = <<"-module(test_header_include).\n"
  514. "-export([main/0]).\n"
  515. "-include(\"test_header_include.hrl\").\n"
  516. "main() -> ?SOME_DEFINE.\n">>,
  517. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  518. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  519. HeaderFile = filename:join([AppDir, "include", "test_header_include.hrl"]),
  520. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  521. ok = file:write_file(HeaderFile, ExtraHeader),
  522. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  523. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  524. {ok, Files} = rebar_utils:list_dir(EbinDir),
  525. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  526. || F <- Files, filename:extension(F) == ".beam"],
  527. timer:sleep(1000),
  528. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  529. ok = file:write_file(HeaderFile, NewExtraHeader),
  530. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  531. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  532. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  533. || F <- NewFiles, filename:extension(F) == ".beam"],
  534. ?assert(ModTime =/= NewModTime).
  535. recompile_when_opts_included_hrl_changes(Config) ->
  536. AppsDir = ?config(apps, Config),
  537. Name = rebar_test_utils:create_random_name("app1_"),
  538. Vsn = rebar_test_utils:create_random_vsn(),
  539. AppDir = filename:join([AppsDir, "apps", Name]),
  540. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  541. ExtraSrc = <<"-module(test_header_include).\n"
  542. "-export([main/0]).\n"
  543. "-include(\"test_header_include.hrl\").\n"
  544. "main() -> ?SOME_DEFINE.\n">>,
  545. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  546. ok = filelib:ensure_dir(filename:join([AppsDir, "include", "dummy"])),
  547. HeaderFile = filename:join([AppsDir, "include", "test_header_include.hrl"]),
  548. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  549. ok = file:write_file(HeaderFile, ExtraHeader),
  550. %% Using relative path from the project root
  551. RebarConfig = [{erl_opts, [{i, "include/"}]}],
  552. {ok,Cwd} = file:get_cwd(),
  553. ok = file:set_cwd(AppsDir),
  554. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  555. EbinDir = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
  556. {ok, Files} = rebar_utils:list_dir(EbinDir),
  557. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  558. || F <- Files, filename:extension(F) == ".beam"],
  559. timer:sleep(1000),
  560. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  561. ok = file:write_file(HeaderFile, NewExtraHeader),
  562. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  563. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  564. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  565. || F <- NewFiles, filename:extension(F) == ".beam"],
  566. ok = file:set_cwd(Cwd),
  567. ?assert(ModTime =/= NewModTime).
  568. recompile_when_opts_change(Config) ->
  569. AppDir = ?config(apps, Config),
  570. Name = rebar_test_utils:create_random_name("app1_"),
  571. Vsn = rebar_test_utils:create_random_vsn(),
  572. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  573. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  574. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  575. {ok, Files} = rebar_utils:list_dir(EbinDir),
  576. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  577. || F <- Files, filename:extension(F) == ".beam"],
  578. timer:sleep(1000),
  579. rebar_test_utils:create_config(AppDir, [{erl_opts, [{d, some_define}]}]),
  580. rebar_test_utils:run_and_check(Config, [{erl_opts, [{d, some_define}]}], ["compile"], {ok, [{app, Name}]}),
  581. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  582. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  583. || F <- NewFiles, filename:extension(F) == ".beam"],
  584. ?assert(ModTime =/= NewModTime).
  585. dont_recompile_when_opts_dont_change(Config) ->
  586. AppDir = ?config(apps, Config),
  587. Name = rebar_test_utils:create_random_name("app1_"),
  588. Vsn = rebar_test_utils:create_random_vsn(),
  589. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  590. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  591. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  592. {ok, Files} = rebar_utils:list_dir(EbinDir),
  593. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  594. || F <- Files, filename:extension(F) == ".beam"],
  595. timer:sleep(1000),
  596. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  597. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  598. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  599. || F <- NewFiles, filename:extension(F) == ".beam"],
  600. ?assertEqual(ModTime, NewModTime).
  601. dont_recompile_yrl_or_xrl(Config) ->
  602. AppDir = ?config(apps, Config),
  603. Name = rebar_test_utils:create_random_name("app1_"),
  604. Vsn = rebar_test_utils:create_random_vsn(),
  605. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  606. Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]),
  607. ok = filelib:ensure_dir(Xrl),
  608. XrlBody =
  609. "Definitions."
  610. "\n\n"
  611. "D = [0-9]"
  612. "\n\n"
  613. "Rules."
  614. "\n\n"
  615. "{D}+ :"
  616. " {token,{integer,TokenLine,list_to_integer(TokenChars)}}."
  617. "\n\n"
  618. "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :"
  619. " {token,{float,TokenLine,list_to_float(TokenChars)}}."
  620. "\n\n"
  621. "Erlang code.",
  622. ok = ec_file:write(Xrl, XrlBody),
  623. Yrl = filename:join([AppDir, "src", "not_a_real_yrl_" ++ Name ++ ".yrl"]),
  624. ok = filelib:ensure_dir(Yrl),
  625. YrlBody = ["Nonterminals E T F.\n"
  626. "Terminals '+' '*' '(' ')' number.\n"
  627. "Rootsymbol E.\n"
  628. "E -> E '+' T: {'$2', '$1', '$3'}.\n"
  629. "E -> T : '$1'.\n"
  630. "T -> T '*' F: {'$2', '$1', '$3'}.\n"
  631. "T -> F : '$1'.\n"
  632. "F -> '(' E ')' : '$2'.\n"
  633. "F -> number : '$1'.\n"],
  634. ok = ec_file:write(Yrl, YrlBody),
  635. XrlErl = filename:join([AppDir, "src", filename:basename(Xrl, ".xrl") ++ ".erl"]),
  636. YrlErl = filename:join([AppDir, "src", filename:basename(Yrl, ".yrl") ++ ".erl"]),
  637. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  638. XrlBeam = filename:join([EbinDir, filename:basename(Xrl, ".xrl") ++ ".beam"]),
  639. YrlBeam = filename:join([EbinDir, filename:basename(Yrl, ".yrl") ++ ".beam"]),
  640. Hrl = filename:join([AppDir, "include", "some_header.hrl"]),
  641. ok = filelib:ensure_dir(Hrl),
  642. HrlBody = yeccpre_hrl(),
  643. ok = ec_file:write(Hrl, HrlBody),
  644. RebarConfig = [{yrl_opts, [{includefile, "include/some_header.hrl"}]}],
  645. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  646. XrlModTime = filelib:last_modified(XrlErl),
  647. YrlModTime = filelib:last_modified(YrlErl),
  648. XrlBeamModTime = filelib:last_modified(XrlBeam),
  649. YrlBeamModTime = filelib:last_modified(YrlBeam),
  650. timer:sleep(1000),
  651. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  652. NewXrlModTime = filelib:last_modified(XrlErl),
  653. NewYrlModTime = filelib:last_modified(YrlErl),
  654. NewXrlBeamModTime = filelib:last_modified(XrlBeam),
  655. NewYrlBeamModTime = filelib:last_modified(YrlBeam),
  656. ?assert(XrlBeamModTime == NewXrlBeamModTime),
  657. ?assert(YrlBeamModTime == NewYrlBeamModTime),
  658. ?assert(XrlModTime == NewXrlModTime),
  659. ?assert(YrlModTime == NewYrlModTime).
  660. delete_beam_if_source_deleted(Config) ->
  661. AppDir = ?config(apps, Config),
  662. Name = rebar_test_utils:create_random_name("app1_"),
  663. Vsn = rebar_test_utils:create_random_vsn(),
  664. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  665. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  666. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  667. _SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]),
  668. ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))),
  669. file:delete(filename:join([AppDir, "src", "not_a_real_src_" ++ Name ++ ".erl"])),
  670. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  671. ?assertNot(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))).
  672. deps_in_path(Config) ->
  673. AppDir = ?config(apps, Config),
  674. StartPaths = code:get_path(),
  675. Name = rebar_test_utils:create_random_name("app1_"),
  676. Vsn = rebar_test_utils:create_random_vsn(),
  677. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  678. DepName = rebar_test_utils:create_random_name("dep1_"),
  679. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  680. mock_git_resource:mock([]),
  681. mock_pkg_resource:mock([
  682. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  683. ]),
  684. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  685. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  686. {list_to_atom(PkgName), Vsn}
  687. ]}]),
  688. {ok, RConf} = file:consult(RConfFile),
  689. %% Make sure apps we look for are not visible
  690. %% Hope not to find src name
  691. ?assertEqual([], [Path || Path <- code:get_path(),
  692. {match, _} <- [re:run(Path, DepName)]]),
  693. %% Hope not to find pkg name in there
  694. ?assertEqual([], [Path || Path <- code:get_path(),
  695. {match, _} <- [re:run(Path, PkgName)]]),
  696. %% Build things
  697. {ok, State} = rebar_test_utils:run_and_check(
  698. Config, RConf, ["compile"],
  699. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  700. ),
  701. code:add_paths(rebar_state:code_paths(State, all_deps)),
  702. %% Find src name in there
  703. ?assertNotEqual([], [Path || Path <- code:get_path(),
  704. {match, _} <- [re:run(Path, DepName)]]),
  705. %% find pkg name in there
  706. ?assertNotEqual([], [Path || Path <- code:get_path(),
  707. {match, _} <- [re:run(Path, PkgName)]]),
  708. true = code:set_path(lists:filter(fun(P) -> ec_file:exists(P) end, StartPaths)),
  709. %% Make sure apps we look for are not visible again
  710. %% Hope not to find src name
  711. ?assertEqual([], [Path || Path <- code:get_path(),
  712. {match, _} <- [re:run(Path, DepName)]]),
  713. %% Hope not to find pkg name in there
  714. ?assertEqual([], [Path || Path <- code:get_path(),
  715. {match, _} <- [re:run(Path, PkgName)]]),
  716. %% Rebuild
  717. {ok, State1} = rebar_test_utils:run_and_check(
  718. Config, RConf, ["compile"],
  719. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  720. ),
  721. %% Find src name in there
  722. code:add_paths(rebar_state:code_paths(State1, all_deps)),
  723. ?assertNotEqual([], [Path || Path <- code:get_path(),
  724. {match, _} <- [re:run(Path, DepName)]]),
  725. %% find pkg name in there
  726. ?assertNotEqual([], [Path || Path <- code:get_path(),
  727. {match, _} <- [re:run(Path, PkgName)]]).
  728. checkout_priority(Config) ->
  729. AppDir = ?config(apps, Config),
  730. CheckoutsDir = ?config(checkouts, Config),
  731. StartPaths = code:get_path(),
  732. Name = rebar_test_utils:create_random_name("app1_"),
  733. Vsn = rebar_test_utils:create_random_vsn(),
  734. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  735. DepName = rebar_test_utils:create_random_name("dep1_"),
  736. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  737. mock_git_resource:mock([]),
  738. mock_pkg_resource:mock([
  739. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  740. ]),
  741. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  742. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  743. {list_to_atom(PkgName), Vsn}
  744. ]}]),
  745. {ok, RConf} = file:consult(RConfFile),
  746. %% Build with deps.
  747. rebar_test_utils:run_and_check(
  748. Config, RConf, ["compile"],
  749. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  750. ),
  751. %% Build two checkout apps similar to dependencies to be fetched,
  752. %% but on a different version
  753. Vsn2 = rebar_test_utils:create_random_vsn(),
  754. rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]),
  755. rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]),
  756. %% Rebuild and make sure the checkout apps are in path
  757. code:set_path(StartPaths),
  758. {ok, State} = rebar_test_utils:run_and_check(
  759. Config, RConf, ["compile"],
  760. {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]}
  761. ),
  762. code:add_paths(rebar_state:code_paths(State, all_deps)),
  763. [DepPath] = [Path || Path <- code:get_path(),
  764. {match, _} <- [re:run(Path, DepName)]],
  765. [PkgPath] = [Path || Path <- code:get_path(),
  766. {match, _} <- [re:run(Path, PkgName)]],
  767. {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])),
  768. {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])),
  769. {application, _, DepProps} = DepApp,
  770. {application, _, PkgProps} = PkgApp,
  771. ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)),
  772. ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)).
  773. highest_version_of_pkg_dep(Config) ->
  774. AppDir = ?config(apps, Config),
  775. Name = rebar_test_utils:create_random_name("app1_"),
  776. Vsn = rebar_test_utils:create_random_vsn(),
  777. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  778. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  779. mock_git_resource:mock([]),
  780. mock_pkg_resource:mock([
  781. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  782. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  783. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  784. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  785. ]),
  786. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [list_to_atom(PkgName)]}]),
  787. {ok, RConf} = file:consult(RConfFile),
  788. %% Build with deps.
  789. rebar_test_utils:run_and_check(
  790. Config, RConf, ["compile"],
  791. {ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]}
  792. ).
  793. parse_transform_test(Config) ->
  794. AppDir = ?config(apps, Config),
  795. RebarConfig = [{erl_opts, [{parse_transform, pascal}]}],
  796. Name = rebar_test_utils:create_random_name("app1_"),
  797. Vsn = rebar_test_utils:create_random_vsn(),
  798. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  799. ExtraSrc = <<"-module(pascal). "
  800. "-export([parse_transform/2]). "
  801. "parse_transform(Forms, _Options) -> "
  802. "Forms.">>,
  803. ok = file:write_file(filename:join([AppDir, "src", "pascal.erl"]), ExtraSrc),
  804. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  805. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  806. true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])).
  807. erl_first_files_test(Config) ->
  808. AppDir = ?config(apps, Config),
  809. RebarConfig = [{erl_opts, [{parse_transform, mark_time}]},
  810. {erl_first_files, ["src/mark_time.erl",
  811. "src/b.erl",
  812. "src/d.erl",
  813. "src/a.erl"]}],
  814. Name = rebar_test_utils:create_random_name("app1_"),
  815. Vsn = rebar_test_utils:create_random_vsn(),
  816. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  817. rebar_test_utils:write_src_file(AppDir, "a.erl"),
  818. rebar_test_utils:write_src_file(AppDir, "b.erl"),
  819. rebar_test_utils:write_src_file(AppDir, "d.erl"),
  820. rebar_test_utils:write_src_file(AppDir, "e.erl"),
  821. ExtraSrc = <<"-module(mark_time). "
  822. "-export([parse_transform/2]). "
  823. "parse_transform([Form={attribute,_,module,Mod}|Forms], Options) -> "
  824. " [Form, {attribute,1,number, os:timestamp()} | Forms];"
  825. "parse_transform([Form|Forms], Options) -> "
  826. " [Form | parse_transform(Forms, Options)].">>,
  827. ok = file:write_file(filename:join([AppDir, "src", "mark_time.erl"]), ExtraSrc),
  828. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  829. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  830. true = filelib:is_file(filename:join([EbinDir, "mark_time.beam"])),
  831. code:load_abs(filename:join([EbinDir, "a"])),
  832. code:load_abs(filename:join([EbinDir, "b"])),
  833. code:load_abs(filename:join([EbinDir, "d"])),
  834. code:load_abs(filename:join([EbinDir, "e"])),
  835. A = proplists:get_value(number, a:module_info(attributes)),
  836. B = proplists:get_value(number, b:module_info(attributes)),
  837. D = proplists:get_value(number, d:module_info(attributes)),
  838. E = proplists:get_value(number, e:module_info(attributes)),
  839. ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])).
  840. mib_test(Config) ->
  841. AppDir = ?config(apps, Config),
  842. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  843. Name = rebar_test_utils:create_random_name("app1_"),
  844. Vsn = rebar_test_utils:create_random_vsn(),
  845. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  846. MibsSrc = <<"-- SIMPLE-MIB.\n"
  847. "-- This is just a simple MIB used for testing!\n"
  848. "--\n"
  849. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  850. "IMPORTS\n"
  851. " MODULE-IDENTITY, enterprises\n"
  852. " FROM SNMPv2-SMI;\n"
  853. "\n"
  854. "ericsson MODULE-IDENTITY\n"
  855. " LAST-UPDATED\n"
  856. " \"201403060000Z\"\n"
  857. " ORGANIZATION\n"
  858. " \"rebar\"\n"
  859. " CONTACT-INFO\n"
  860. " \"rebar <rebar@example.com>\n"
  861. " or\n"
  862. " whoever is currently responsible for the SIMPLE\n"
  863. " enterprise MIB tree branch (enterprises.999).\"\n"
  864. " DESCRIPTION\n"
  865. " \"This very small module is made available\n"
  866. " for mib-compilation testing.\"\n"
  867. " ::= { enterprises 999 }\n"
  868. "END\n">>,
  869. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  870. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  871. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  872. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  873. PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  874. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  875. %% check a hrl corresponding to the mib in the mibs dir exists in include
  876. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  877. %% check the mibs dir was linked into the _build dir
  878. true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])).
  879. umbrella_mib_first_test(Config) ->
  880. AppsDir = ?config(apps, Config),
  881. Name = rebar_test_utils:create_random_name("app1_"),
  882. Vsn = rebar_test_utils:create_random_vsn(),
  883. AppDir = filename:join([AppsDir, "apps", Name]),
  884. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  885. BExporterSrc = <<"-- BEXPORTER-MIB.\n"
  886. "-- This is just a simple MIB used for testing!\n"
  887. "--\n"
  888. "BEXPORTER-MIB DEFINITIONS ::= BEGIN\n"
  889. "IMPORTS\n"
  890. " TEXTUAL-CONVENTION\n"
  891. " FROM SNMPv2-TC\n"
  892. " MODULE-IDENTITY, enterprises\n"
  893. " FROM SNMPv2-SMI;\n"
  894. "\n"
  895. "ericsson MODULE-IDENTITY\n"
  896. " LAST-UPDATED\n"
  897. " \"201812050000Z\"\n"
  898. " ORGANIZATION\n"
  899. " \"rebar\"\n"
  900. " CONTACT-INFO\n"
  901. " \"rebar <rebar@example.com>\n"
  902. " or\n"
  903. " whoever is currently responsible for the SIMPLE\n"
  904. " enterprise MIB tree branch (enterprises.999).\"\n"
  905. " DESCRIPTION\n"
  906. " \"This very small module is made available\n"
  907. " for mib-compilation testing.\"\n"
  908. " ::= { enterprises 999 }\n"
  909. "\n"
  910. "Something ::= TEXTUAL-CONVENTION\n"
  911. " STATUS current\n"
  912. " DESCRIPTION \"\"\n"
  913. " SYNTAX OCTET STRING (SIZE (4))\n"
  914. "END\n">>,
  915. AImporterSrc = <<"-- AIMPORTER-MIB.\n"
  916. "-- This is just a simple MIB used for testing!\n"
  917. "--\n"
  918. "AIMPORTER-MIB DEFINITIONS ::= BEGIN\n"
  919. "IMPORTS\n"
  920. " Something\n"
  921. " FROM BEXPORTER-MIB\n"
  922. " MODULE-IDENTITY, enterprises\n"
  923. " FROM SNMPv2-SMI;\n"
  924. "\n"
  925. "ericsson MODULE-IDENTITY\n"
  926. " LAST-UPDATED\n"
  927. " \"201812050000Z\"\n"
  928. " ORGANIZATION\n"
  929. " \"rebar\"\n"
  930. " CONTACT-INFO\n"
  931. " \"rebar <rebar@example.com>\n"
  932. " or\n"
  933. " whoever is currently responsible for the SIMPLE\n"
  934. " enterprise MIB tree branch (enterprises.999).\"\n"
  935. " DESCRIPTION\n"
  936. " \"This very small module is made available\n"
  937. " for mib-compilation testing.\"\n"
  938. " ::= { enterprises 1000 }\n"
  939. "END\n">>,
  940. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  941. ok = file:write_file(filename:join([AppDir, "mibs", "AIMPORTER-MIB.mib"]), AImporterSrc),
  942. ok = file:write_file(filename:join([AppDir, "mibs", "BEXPORTER-MIB.mib"]), BExporterSrc),
  943. FailureRebarConfig = [{mib_first_files, ["mibs/AIMPORTER-MIB.mib"]}],
  944. SuccessRebarConfig = [{mib_first_files, ["mibs/BEXPORTER-MIB.mib"]}],
  945. PrivMibsDir = filename:join([AppsDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  946. FailureRebarConfig = [{mib_first_files, ["mibs/AIMPORTER-MIB.mib"]}],
  947. catch (
  948. rebar_test_utils:run_and_check(Config, FailureRebarConfig, ["compile"], {ok, [{app, Name}]}) ),
  949. %% check that the bin file was NOT cretated
  950. false = filelib:is_file(filename:join([PrivMibsDir, "AIMPORTER-MIB.bin"])),
  951. SuccessRebarConfig = [{mib_first_files, ["mibs/BEXPORTER-MIB.mib"]}],
  952. rebar_test_utils:run_and_check(Config, SuccessRebarConfig, ["compile"], {ok, [{app, Name}]}),
  953. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  954. true = filelib:is_file(filename:join([PrivMibsDir, "AIMPORTER-MIB.bin"])),
  955. %% check a hrl corresponding to the mib in the mibs dir exists in include
  956. true = filelib:is_file(filename:join([AppDir, "include", "AIMPORTER-MIB.hrl"])),
  957. %% check the mibs dir was linked into the _build dir
  958. true = filelib:is_dir(filename:join([AppsDir, "_build", "default", "lib", Name, "mibs"])).
  959. only_default_transitive_deps(Config) ->
  960. AppDir = ?config(apps, Config),
  961. Name = rebar_test_utils:create_random_name("app1_"),
  962. Vsn = rebar_test_utils:create_random_vsn(),
  963. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  964. GitDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]),
  965. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  966. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  967. mock_git_resource:mock([{deps, SrcDeps},
  968. {config, [{profiles, [{test, [{deps, [list_to_atom(PkgName)]}]}]}]}]),
  969. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  970. Deps = rebar_test_utils:top_level_deps(GitDeps),
  971. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  972. {ok, RConf} = file:consult(RConfFile),
  973. %% Build with deps.
  974. rebar_test_utils:run_and_check(
  975. Config, RConf, ["as", "test", "compile"],
  976. {ok, [{app, Name}, {dep, "a", <<"1.0.0">>}, {dep_not_exist, PkgName}]}
  977. ).
  978. clean_all(Config) ->
  979. AppDir = ?config(apps, Config),
  980. Name = rebar_test_utils:create_random_name("app1_"),
  981. Vsn = rebar_test_utils:create_random_vsn(),
  982. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  983. DepName = rebar_test_utils:create_random_name("dep1_"),
  984. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  985. mock_git_resource:mock([]),
  986. mock_pkg_resource:mock([
  987. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  988. ]),
  989. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  990. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  991. {list_to_atom(PkgName), Vsn}
  992. ]}]),
  993. {ok, RConf} = file:consult(RConfFile),
  994. %% Build things
  995. rebar_test_utils:run_and_check(
  996. Config, RConf, ["compile"],
  997. {ok, [{app, Name}, {app, DepName}, {app, PkgName}]}
  998. ),
  999. %% Clean all
  1000. rebar_test_utils:run_and_check(Config, [], ["clean", "--all"],
  1001. {ok, [{app, Name, invalid},
  1002. {app, DepName, invalid},
  1003. {app, PkgName, invalid}]}).
  1004. override_deps(Config) ->
  1005. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1006. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1007. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1008. mock_git_resource:mock([{deps, SrcDeps}]),
  1009. RebarConfig = [
  1010. {deps, TopDeps},
  1011. {overrides, [
  1012. {override, some_dep, [
  1013. {deps, []}
  1014. ]}
  1015. ]}
  1016. ],
  1017. rebar_test_utils:run_and_check(
  1018. Config, RebarConfig, ["compile"],
  1019. {ok, [{dep, "some_dep"},
  1020. {dep_not_exist, "other_dep"}]}
  1021. ).
  1022. override_add_deps(Config) ->
  1023. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1024. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1025. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  1026. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  1027. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  1028. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1029. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  1030. RebarConfig = [
  1031. {deps, TopDeps},
  1032. {overrides, [
  1033. {add, some_dep, [
  1034. {deps, [DepA, DepB]}
  1035. ]},
  1036. {add, [
  1037. {deps, [DepC]}
  1038. ]}
  1039. ]}
  1040. ],
  1041. rebar_test_utils:run_and_check(
  1042. Config, RebarConfig, ["compile"],
  1043. {ok, [{dep, "some_dep"},
  1044. {dep, "other_dep"},
  1045. {dep, "dep_a"},
  1046. {dep, "dep_b"},
  1047. {dep, "dep_c"}]}
  1048. ).
  1049. override_del_deps(Config) ->
  1050. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  1051. {"dep_b", "0.0.1", []},
  1052. {"dep_c", "0.0.1", []}]},
  1053. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  1054. {"dep_d", "0.0.1", []}]}]),
  1055. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1056. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  1057. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  1058. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  1059. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1060. mock_git_resource:mock([{deps, SrcDeps}]),
  1061. RebarConfig = [
  1062. {deps, TopDeps},
  1063. {overrides, [
  1064. {del, some_dep, [
  1065. {deps, [DepA, DepB]}
  1066. ]},
  1067. {del, [
  1068. {deps, [DepC]}
  1069. ]}
  1070. ]}
  1071. ],
  1072. rebar_test_utils:run_and_check(
  1073. Config, RebarConfig, ["compile"],
  1074. {ok, [{dep, "some_dep"},
  1075. {dep, "other_dep"},
  1076. {dep_not_exist, "dep_a"},
  1077. {dep_not_exist, "dep_b"},
  1078. {dep_not_exist, "dep_c"},
  1079. {dep, "dep_d"}]}
  1080. ).
  1081. override_opts(Config) ->
  1082. AppDir = ?config(apps, Config),
  1083. Name = rebar_test_utils:create_random_name("app1_"),
  1084. Vsn = rebar_test_utils:create_random_vsn(),
  1085. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1086. RebarConfig = [
  1087. {erl_opts, [
  1088. compressed,
  1089. warn_missing_spec
  1090. ]},
  1091. {overrides, [
  1092. {override, [
  1093. {erl_opts, [compressed]}
  1094. ]}
  1095. ]}
  1096. ],
  1097. rebar_test_utils:create_config(AppDir, RebarConfig),
  1098. rebar_test_utils:run_and_check(
  1099. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1100. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1101. code:add_patha(Path),
  1102. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1103. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1104. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1105. %% test for fix of https://github.com/erlang/rebar3/issues/1801
  1106. %% only apply overrides once
  1107. %% verify by having an override add the macro TEST to the dep some_dep
  1108. %% building under `ct` will fail if the `add` is applied more than once
  1109. apply_overrides_exactly_once(Config) ->
  1110. AppDir = ?config(apps, Config),
  1111. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1112. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1113. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1114. mock_git_resource:mock([{deps, SrcDeps}]),
  1115. Name = rebar_test_utils:create_random_name("app1_"),
  1116. Vsn = rebar_test_utils:create_random_vsn(),
  1117. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1118. RebarConfig = [{deps, TopDeps},
  1119. {overrides, [
  1120. {add, some_dep, [
  1121. {erl_opts, [{d, 'TEST'}]}
  1122. ]}
  1123. ]}],
  1124. rebar_test_utils:create_config(AppDir, RebarConfig),
  1125. rebar_test_utils:run_and_check(
  1126. Config, RebarConfig, ["ct", "--compile_only"], {ok, [{app, Name}, {dep, "some_dep"}], "test"}).
  1127. override_add_opts(Config) ->
  1128. AppDir = ?config(apps, Config),
  1129. Name = rebar_test_utils:create_random_name("app1_"),
  1130. Vsn = rebar_test_utils:create_random_vsn(),
  1131. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1132. RebarConfig = [
  1133. {erl_opts, [
  1134. warn_missing_spec
  1135. ]},
  1136. {overrides, [
  1137. {add, [
  1138. {erl_opts, [compressed]}
  1139. ]}
  1140. ]}
  1141. ],
  1142. rebar_test_utils:create_config(AppDir, RebarConfig),
  1143. rebar_test_utils:run_and_check(
  1144. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1145. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1146. code:add_patha(Path),
  1147. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1148. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1149. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1150. override_del_opts(Config) ->
  1151. AppDir = ?config(apps, Config),
  1152. Name = rebar_test_utils:create_random_name("app1_"),
  1153. Vsn = rebar_test_utils:create_random_vsn(),
  1154. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1155. RebarConfig = [
  1156. {erl_opts, [
  1157. compressed,
  1158. warn_missing_spec
  1159. ]},
  1160. {overrides, [
  1161. {del, [
  1162. {erl_opts, [warn_missing_spec]}
  1163. ]}
  1164. ]}
  1165. ],
  1166. rebar_test_utils:create_config(AppDir, RebarConfig),
  1167. rebar_test_utils:run_and_check(
  1168. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1169. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1170. code:add_patha(Path),
  1171. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1172. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1173. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1174. profile_override_deps(Config) ->
  1175. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1176. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1177. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1178. mock_git_resource:mock([{deps, SrcDeps}]),
  1179. RebarConfig = [
  1180. {deps, TopDeps},
  1181. {profiles, [
  1182. {a, [
  1183. {overrides, [
  1184. {override, some_dep, [
  1185. {deps, []}
  1186. ]}
  1187. ]}
  1188. ]}
  1189. ]}],
  1190. rebar_test_utils:run_and_check(
  1191. Config, RebarConfig, ["as", "a", "compile"],
  1192. {ok, [{dep, "some_dep"},
  1193. {dep_not_exist, "other_dep"}]}
  1194. ).
  1195. profile_override_add_deps(Config) ->
  1196. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1197. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1198. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  1199. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  1200. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  1201. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1202. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  1203. RebarConfig = [
  1204. {deps, TopDeps},
  1205. {profiles, [
  1206. {a, [
  1207. {overrides, [
  1208. {add, some_dep, [
  1209. {deps, [DepA, DepB]}
  1210. ]},
  1211. {add, [
  1212. {deps, [DepC]}
  1213. ]}
  1214. ]}
  1215. ]}
  1216. ]}
  1217. ],
  1218. rebar_test_utils:run_and_check(
  1219. Config, RebarConfig, ["as", "a", "compile"],
  1220. {ok, [{dep, "some_dep"},
  1221. {dep, "other_dep"},
  1222. {dep, "dep_a"},
  1223. {dep, "dep_b"},
  1224. {dep, "dep_c"}]}
  1225. ).
  1226. profile_override_del_deps(Config) ->
  1227. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  1228. {"dep_b", "0.0.1", []},
  1229. {"dep_c", "0.0.1", []}]},
  1230. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  1231. {"dep_d", "0.0.1", []}]}]),
  1232. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1233. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  1234. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  1235. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  1236. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1237. mock_git_resource:mock([{deps, SrcDeps}]),
  1238. RebarConfig = [
  1239. {deps, TopDeps},
  1240. {profiles, [
  1241. {a, [
  1242. {overrides, [
  1243. {del, some_dep, [
  1244. {deps, [DepA, DepB]}
  1245. ]},
  1246. {del, [
  1247. {deps, [DepC]}
  1248. ]}
  1249. ]}
  1250. ]}
  1251. ]}
  1252. ],
  1253. rebar_test_utils:run_and_check(
  1254. Config, RebarConfig, ["as", "a", "compile"],
  1255. {ok, [{dep, "some_dep"},
  1256. {dep, "other_dep"},
  1257. {dep_not_exist, "dep_a"},
  1258. {dep_not_exist, "dep_b"},
  1259. {dep_not_exist, "dep_c"},
  1260. {dep, "dep_d"}]}
  1261. ).
  1262. profile_override_opts(Config) ->
  1263. AppDir = ?config(apps, Config),
  1264. Name = rebar_test_utils:create_random_name("app1_"),
  1265. Vsn = rebar_test_utils:create_random_vsn(),
  1266. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1267. RebarConfig = [
  1268. {erl_opts, [
  1269. compressed,
  1270. warn_missing_spec
  1271. ]},
  1272. {profiles, [
  1273. {a, [
  1274. {overrides, [
  1275. {override, [
  1276. {erl_opts, [compressed]}
  1277. ]}
  1278. ]}
  1279. ]}
  1280. ]}
  1281. ],
  1282. rebar_test_utils:create_config(AppDir, RebarConfig),
  1283. rebar_test_utils:run_and_check(
  1284. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1285. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1286. code:add_patha(Path),
  1287. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1288. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1289. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1290. profile_override_add_opts(Config) ->
  1291. AppDir = ?config(apps, Config),
  1292. Name = rebar_test_utils:create_random_name("app1_"),
  1293. Vsn = rebar_test_utils:create_random_vsn(),
  1294. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1295. RebarConfig = [
  1296. {erl_opts, [
  1297. warn_missing_spec
  1298. ]},
  1299. {profiles, [
  1300. {a, [
  1301. {overrides, [
  1302. {add, [
  1303. {erl_opts, [compressed]}
  1304. ]}
  1305. ]}
  1306. ]}
  1307. ]}
  1308. ],
  1309. rebar_test_utils:create_config(AppDir, RebarConfig),
  1310. rebar_test_utils:run_and_check(
  1311. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1312. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1313. code:add_patha(Path),
  1314. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1315. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1316. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1317. profile_override_del_opts(Config) ->
  1318. AppDir = ?config(apps, Config),
  1319. Name = rebar_test_utils:create_random_name("app1_"),
  1320. Vsn = rebar_test_utils:create_random_vsn(),
  1321. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1322. RebarConfig = [
  1323. {erl_opts, [
  1324. compressed,
  1325. warn_missing_spec
  1326. ]},
  1327. {profiles, [
  1328. {a, [
  1329. {overrides, [
  1330. {del, [
  1331. {erl_opts, [warn_missing_spec]}
  1332. ]}
  1333. ]}
  1334. ]}
  1335. ]}
  1336. ],
  1337. rebar_test_utils:create_config(AppDir, RebarConfig),
  1338. rebar_test_utils:run_and_check(
  1339. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1340. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1341. code:add_patha(Path),
  1342. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1343. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1344. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1345. profile_deps(Config) ->
  1346. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1347. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1348. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1349. mock_git_resource:mock([{deps, SrcDeps}]),
  1350. RebarConfig = [
  1351. {deps, TopDeps},
  1352. {profiles, [{a, []}]}],
  1353. rebar_test_utils:run_and_check(
  1354. Config, RebarConfig, ["as", "a", "compile"],
  1355. {ok, [{dep, "some_dep"},{dep, "other_dep"}]}
  1356. ).
  1357. only_deps(Config) ->
  1358. AppDir = ?config(apps, Config),
  1359. Name = rebar_test_utils:create_random_name("app1_"),
  1360. Vsn = rebar_test_utils:create_random_vsn(),
  1361. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1362. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1363. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1364. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1365. mock_git_resource:mock([{deps, SrcDeps}]),
  1366. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
  1367. {ok, RConf} = file:consult(RConfFile),
  1368. rebar_test_utils:run_and_check(
  1369. Config, RConf, ["compile", "--deps_only"],
  1370. {ok, [{app_not_exist, Name}, {dep, "some_dep"},{dep, "other_dep"}]}
  1371. ).
  1372. %% verify a deps prod profile is used
  1373. %% tested by checking prod hooks run and outputs to default profile dir for dep
  1374. %% and prod deps are installed for dep
  1375. deps_build_in_prod(Config) ->
  1376. AppDir = ?config(apps, Config),
  1377. Name = rebar_test_utils:create_random_name("app1_"),
  1378. Vsn = rebar_test_utils:create_random_vsn(),
  1379. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1380. GitDeps = rebar_test_utils:expand_deps(git, [{"asdf", "1.0.0", []}]),
  1381. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  1382. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  1383. mock_git_resource:mock([{deps, SrcDeps},
  1384. {config, [{profiles, [{prod, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]},
  1385. {deps, [list_to_atom(PkgName)]}]}]}]}]),
  1386. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  1387. Deps = rebar_test_utils:top_level_deps(GitDeps),
  1388. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  1389. {ok, RConf} = file:consult(RConfFile),
  1390. %% Build with deps.
  1391. rebar_test_utils:run_and_check(
  1392. Config, RConf, ["compile"],
  1393. {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName},
  1394. {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]}
  1395. ).
  1396. %% verify that the proper include path is defined
  1397. %% according the erlang doc which states:
  1398. %% If the filename File is absolute (possibly after variable substitution),
  1399. %% the include file with that name is included. Otherwise, the specified file
  1400. %% is searched for in the following directories, and in this order:
  1401. %% * The current working directory
  1402. %% * The directory where the module is being compiled
  1403. %% * The directories given by the include option
  1404. include_file_relative_to_working_directory(Config) ->
  1405. AppDir = ?config(apps, Config),
  1406. Name = rebar_test_utils:create_random_name("app1_"),
  1407. Vsn = rebar_test_utils:create_random_vsn(),
  1408. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1409. Src = <<"-module(test).\n"
  1410. "\n"
  1411. "-include(\"include/test.hrl\").\n"
  1412. "\n"
  1413. "test() -> ?TEST_MACRO.\n"
  1414. "\n">>,
  1415. Include = <<"-define(TEST_MACRO, test).\n">>,
  1416. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1417. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1418. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1419. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1420. RebarConfig = [],
  1421. rebar_test_utils:run_and_check(Config, RebarConfig,
  1422. ["compile"],
  1423. {ok, [{app, Name}]}).
  1424. include_file_in_src(Config) ->
  1425. AppDir = ?config(apps, Config),
  1426. Name = rebar_test_utils:create_random_name("app1_"),
  1427. Vsn = rebar_test_utils:create_random_vsn(),
  1428. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1429. Src = <<"-module(test).\n"
  1430. "\n"
  1431. "-include(\"test.hrl\").\n"
  1432. "\n"
  1433. "test() -> ?TEST_MACRO.\n"
  1434. "\n">>,
  1435. Include = <<"-define(TEST_MACRO, test).\n">>,
  1436. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1437. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1438. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1439. RebarConfig = [],
  1440. rebar_test_utils:run_and_check(Config, RebarConfig,
  1441. ["compile"],
  1442. {ok, [{app, Name}]}).
  1443. %% verify that the proper include path is defined
  1444. %% according the erlang doc which states:
  1445. %% If the filename File is absolute (possibly after variable substitution),
  1446. %% the include file with that name is included. Otherwise, the specified file
  1447. %% is searched for in the following directories, and in this order:
  1448. %% * The current working directory
  1449. %% * The directory where the module is being compiled
  1450. %% * The directories given by the include option
  1451. %%
  1452. %% This test ensures that things keep working when additional directories
  1453. %% are used for apps, such as the test/ directory within the test profile.
  1454. include_file_relative_to_working_directory_test(Config) ->
  1455. AppDir = ?config(apps, Config),
  1456. Name = rebar_test_utils:create_random_name("app1_"),
  1457. Vsn = rebar_test_utils:create_random_vsn(),
  1458. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1459. Src = <<"-module(test).\n"
  1460. "\n"
  1461. "-include(\"include/test.hrl\").\n"
  1462. "\n"
  1463. "test() -> ?TEST_MACRO.\n"
  1464. "\n">>,
  1465. Include = <<"-define(TEST_MACRO, test).\n">>,
  1466. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1467. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1468. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1469. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1470. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1471. RebarConfig = [],
  1472. rebar_test_utils:run_and_check(Config, RebarConfig,
  1473. ["as", "test", "compile"],
  1474. {ok, [{app, Name}]}).
  1475. %% Same as `include_file_in_src/1' but using the `test/' directory
  1476. %% within the test profile.
  1477. include_file_in_src_test(Config) ->
  1478. AppDir = ?config(apps, Config),
  1479. Name = rebar_test_utils:create_random_name("app1_"),
  1480. Vsn = rebar_test_utils:create_random_vsn(),
  1481. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1482. Src = <<"-module(test).\n"
  1483. "\n"
  1484. "-include(\"test.hrl\").\n"
  1485. "\n"
  1486. "test() -> ?TEST_MACRO.\n"
  1487. "\n">>,
  1488. Include = <<"-define(TEST_MACRO, test).\n">>,
  1489. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1490. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1491. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1492. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1493. RebarConfig = [],
  1494. rebar_test_utils:run_and_check(Config, RebarConfig,
  1495. ["as", "test", "compile"],
  1496. {ok, [{app, Name}]}).
  1497. %% Same as `include_file_in_src_test/1' but using multiple top-level
  1498. %% apps as dependencies.
  1499. include_file_in_src_test_multiapp(Config) ->
  1500. Name1 = rebar_test_utils:create_random_name("app2_"),
  1501. Name2 = rebar_test_utils:create_random_name("app1_"),
  1502. AppDir1 = filename:join([?config(apps, Config), "lib", Name1]),
  1503. AppDir2 = filename:join([?config(apps, Config), "lib", Name2]),
  1504. Vsn = rebar_test_utils:create_random_vsn(),
  1505. rebar_test_utils:create_app(AppDir1, Name1, Vsn, [kernel, stdlib, list_to_atom(Name2)]),
  1506. rebar_test_utils:create_app(AppDir2, Name2, Vsn, [kernel, stdlib]),
  1507. Src = "-module(test).\n"
  1508. "\n"
  1509. "-include_lib(\"" ++ Name2 ++ "/include/test.hrl\").\n"
  1510. "\n"
  1511. "test() -> ?TEST_MACRO.\n"
  1512. "\n",
  1513. Include = <<"-define(TEST_MACRO, test).\n">>,
  1514. ok = filelib:ensure_dir(filename:join([AppDir1, "src", "dummy"])),
  1515. ok = filelib:ensure_dir(filename:join([AppDir1, "test", "dummy"])),
  1516. ok = filelib:ensure_dir(filename:join([AppDir2, "src", "dummy"])),
  1517. ok = filelib:ensure_dir(filename:join([AppDir2, "include", "dummy"])),
  1518. ok = file:write_file(filename:join([AppDir1, "test", "test.erl"]), Src),
  1519. ok = file:write_file(filename:join([AppDir2, "include", "test.hrl"]), Include),
  1520. RebarConfig = [],
  1521. rebar_test_utils:run_and_check(Config, RebarConfig,
  1522. ["as", "test", "compile"],
  1523. {ok, [{app, Name1}]}),
  1524. ok.
  1525. %% this test sets the env var, compiles, records the file last modified timestamp,
  1526. %% recompiles and compares the file last modified timestamp to ensure it hasn't
  1527. %% changed. this test should run on 19.x+
  1528. dont_recompile_when_erl_compiler_options_env_does_not_change(Config) ->
  1529. %% save existing env to restore after test
  1530. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1531. AppDir = ?config(apps, Config),
  1532. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1533. Vsn = rebar_test_utils:create_random_vsn(),
  1534. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1535. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1536. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1537. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1538. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1539. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1540. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1541. || F <- Files, filename:extension(F) == ".beam"],
  1542. timer:sleep(1000),
  1543. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1544. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1545. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1546. || F <- NewFiles, filename:extension(F) == ".beam"],
  1547. ?assert(ModTime == NewModTime),
  1548. %% restore existing env
  1549. case ExistingEnv of
  1550. false -> ok;
  1551. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1552. end.
  1553. %% this test compiles, records the file last modified timestamp, sets the env
  1554. %% var, recompiles and compares the file last modified timestamp to ensure it
  1555. %% has changed. this test should run on 19.x+
  1556. recompile_when_erl_compiler_options_env_changes(Config) ->
  1557. %% save existing env to restore after test
  1558. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1559. AppDir = ?config(apps, Config),
  1560. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1561. Vsn = rebar_test_utils:create_random_vsn(),
  1562. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1563. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1564. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1565. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1566. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1567. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1568. || F <- Files, filename:extension(F) == ".beam"],
  1569. timer:sleep(1000),
  1570. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1571. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1572. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1573. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1574. || F <- NewFiles, filename:extension(F) == ".beam"],
  1575. ?assert(ModTime =/= NewModTime),
  1576. %% restore existing env
  1577. case ExistingEnv of
  1578. false -> ok;
  1579. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1580. end.
  1581. rebar_config_os_var(Config) ->
  1582. AppDir = ?config(apps, Config),
  1583. Name = rebar_test_utils:create_random_name("rebar_config_os_var_"),
  1584. Vsn = rebar_test_utils:create_random_vsn(),
  1585. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1586. rebar_test_utils:create_config(AppDir, [{erl_opts, []}]),
  1587. AltConfig = filename:join(AppDir, "test.rebar.config"),
  1588. file:write_file(AltConfig, "{erl_opts, [compressed]}."),
  1589. true = os:putenv("REBAR_CONFIG", AltConfig),
  1590. rebar_test_utils:run_and_check(Config, ["compile"], {ok, [{app, Name}]}),
  1591. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1592. code:add_patha(Path),
  1593. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1594. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1595. ok.
  1596. %% this test sets the env var, compiles, records the file last modified
  1597. %% timestamp, recompiles and compares the file last modified timestamp to
  1598. %% ensure it has changed. this test should run on 18.x
  1599. always_recompile_when_erl_compiler_options_set(Config) ->
  1600. %% save existing env to restore after test
  1601. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1602. AppDir = ?config(apps, Config),
  1603. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1604. Vsn = rebar_test_utils:create_random_vsn(),
  1605. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1606. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1607. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1608. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1609. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1610. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1611. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1612. || F <- Files, filename:extension(F) == ".beam"],
  1613. timer:sleep(1000),
  1614. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1615. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1616. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1617. || F <- NewFiles, filename:extension(F) == ".beam"],
  1618. ?assert(ModTime =/= NewModTime),
  1619. %% restore existing env
  1620. case ExistingEnv of
  1621. false -> ok;
  1622. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1623. end.
  1624. recompile_when_parse_transform_inline_changes(Config) ->
  1625. AppDir = ?config(apps, Config),
  1626. Name = rebar_test_utils:create_random_name("parse_transform_inline_"),
  1627. Vsn = rebar_test_utils:create_random_vsn(),
  1628. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1629. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1630. ModSrc = <<"-module(example).\n"
  1631. "-export([foo/2]).\n"
  1632. "-compile([{parse_transform, example_parse_transform}]).\n"
  1633. "foo(_, _) -> ok.">>,
  1634. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1635. ModSrc),
  1636. ParseTransform = <<"-module(example_parse_transform).\n"
  1637. "-export([parse_transform/2]).\n"
  1638. "parse_transform(AST, _) -> AST.\n">>,
  1639. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1640. ParseTransform),
  1641. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1642. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1643. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1644. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1645. || F <- Files, filename:basename(F, ".beam") == "example"],
  1646. timer:sleep(1000),
  1647. NewParseTransform = <<"-module(example_parse_transform).\n"
  1648. "-export([parse_transform/2]).\n"
  1649. "parse_transform(AST, _) -> identity(AST).\n"
  1650. "identity(AST) -> AST.\n">>,
  1651. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1652. NewParseTransform),
  1653. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1654. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1655. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1656. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1657. ?assert(ModTime =/= NewModTime).
  1658. recompile_when_parse_transform_as_opt_changes(Config) ->
  1659. AppDir = ?config(apps, Config),
  1660. Name = rebar_test_utils:create_random_name("parse_transform_opt_"),
  1661. Vsn = rebar_test_utils:create_random_vsn(),
  1662. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1663. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1664. ModSrc = <<"-module(example).\n"
  1665. "-export([foo/2]).\n"
  1666. "foo(_, _) -> ok.">>,
  1667. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1668. ModSrc),
  1669. ParseTransform = <<"-module(example_parse_transform).\n"
  1670. "-export([parse_transform/2]).\n"
  1671. "parse_transform(AST, _) -> AST.">>,
  1672. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1673. ParseTransform),
  1674. RebarConfig = [{erl_opts, [{parse_transform, example_parse_transform}]}],
  1675. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1676. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1677. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1678. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1679. || F <- Files, filename:basename(F, ".beam") == "example"],
  1680. timer:sleep(1000),
  1681. NewParseTransform = <<"-module(example_parse_transform).\n"
  1682. "-export([parse_transform/2]).\n"
  1683. "parse_transform(AST, _) -> identity(AST).\n"
  1684. "identity(AST) -> AST.">>,
  1685. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1686. NewParseTransform),
  1687. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1688. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1689. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1690. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1691. ?assert(ModTime =/= NewModTime).
  1692. recursive(Config) ->
  1693. AppDir = ?config(apps, Config),
  1694. Name = rebar_test_utils:create_random_name("app1_"),
  1695. Vsn = rebar_test_utils:create_random_vsn(),
  1696. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1697. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1698. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1699. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1700. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1701. ?assert(lists:member("rec.beam",Files)),
  1702. %% check that rec is in modules list of .app file
  1703. AppFile = filename:join(EbinDir, Name++".app"),
  1704. {ok, [{application, _, List}]} = file:consult(AppFile),
  1705. {modules, Modules} = lists:keyfind(modules, 1, List),
  1706. ?assert(lists:member(rec, Modules)).
  1707. no_recursive(Config) ->
  1708. AppDir = ?config(apps, Config),
  1709. Name = rebar_test_utils:create_random_name("app1_"),
  1710. Vsn = rebar_test_utils:create_random_vsn(),
  1711. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1712. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1713. RebarConfig1 = [{erlc_compiler,[{recursive,false}]}],
  1714. rebar_test_utils:run_and_check(Config, RebarConfig1, ["compile"],
  1715. {ok, [{app, Name}]}),
  1716. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1717. {ok, Files1} = rebar_utils:list_dir(EbinDir),
  1718. ?assert(false==lists:member("rec.beam",Files1)),
  1719. RebarConfig2 = [{src_dirs,[{"src",[{recursive,false}]}]}],
  1720. rebar_test_utils:run_and_check(Config, RebarConfig2, ["compile"],
  1721. {ok, [{app, Name}]}),
  1722. {ok, Files2} = rebar_utils:list_dir(EbinDir),
  1723. ?assert(false==lists:member("rec.beam",Files2)),
  1724. ok.
  1725. regex_filter_skip(Config) ->
  1726. AppDir = ?config(apps, Config),
  1727. Name = rebar_test_utils:create_random_name("regex_skip"),
  1728. Vsn = rebar_test_utils:create_random_vsn(),
  1729. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1730. rebar_test_utils:write_src_file(filename:join(AppDir,src),"._rec.erl"),
  1731. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","._rec.beam"]),
  1732. RebarConfig = [],
  1733. try
  1734. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1735. {ok, [{file, Expected}]}),
  1736. throw(should_not_be_found)
  1737. catch
  1738. %% the file was not found, as desired!
  1739. error:{assertion_failed,_} -> %% OTP =< 17
  1740. ok;
  1741. error:{assert,_} -> %% OTP >= 18
  1742. ok
  1743. end.
  1744. regex_filter_regression(Config) ->
  1745. AppDir = ?config(apps, Config),
  1746. Name = rebar_test_utils:create_random_name("regex_regression"),
  1747. Vsn = rebar_test_utils:create_random_vsn(),
  1748. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1749. rebar_test_utils:write_src_file(filename:join(AppDir,src),"r_f.erl"),
  1750. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","r_f.beam"]),
  1751. RebarConfig = [],
  1752. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1753. {ok, [{file, Expected}]}),
  1754. ok.
  1755. %%
  1756. %% a copy of lib/parsetools/include/yeccpre.hrl so we can test yrl includefile
  1757. yeccpre_hrl() ->
  1758. <<"-type yecc_ret() :: {'error', _} | {'ok', _}.
  1759. -spec parse(Tokens :: list()) -> yecc_ret().
  1760. parse(Tokens) ->
  1761. yeccpars0(Tokens, {no_func, no_line}, 0, [], []).
  1762. -spec parse_and_scan({function() | {atom(), atom()}, [_]}
  1763. | {atom(), atom(), [_]}) -> yecc_ret().
  1764. parse_and_scan({F, A}) ->
  1765. yeccpars0([], {{F, A}, no_line}, 0, [], []);
  1766. parse_and_scan({M, F, A}) ->
  1767. Arity = length(A),
  1768. yeccpars0([], {{fun M:F/Arity, A}, no_line}, 0, [], []).
  1769. -spec format_error(any()) -> [char() | list()].
  1770. format_error(Message) ->
  1771. case io_lib:deep_char_list(Message) of
  1772. true ->
  1773. Message;
  1774. _ ->
  1775. io_lib:write(Message)
  1776. end.
  1777. %% To be used in grammar files to throw an error message to the parser
  1778. %% toplevel. Doesn't have to be exported!
  1779. -compile({nowarn_unused_function, return_error/2}).
  1780. -spec return_error(integer(), any()) -> no_return().
  1781. return_error(Line, Message) ->
  1782. throw({error, {Line, ?MODULE, Message}}).
  1783. -define(CODE_VERSION, \"1.4\").
  1784. yeccpars0(Tokens, Tzr, State, States, Vstack) ->
  1785. try yeccpars1(Tokens, Tzr, State, States, Vstack)
  1786. catch
  1787. error:Error ->
  1788. try yecc_error_type(Error, []) of
  1789. Desc ->
  1790. erlang:raise(error, {yecc_bug, ?CODE_VERSION, Desc},
  1791. [])
  1792. catch _:_ -> erlang:raise(error, Error, [])
  1793. end;
  1794. %% Probably thrown from return_error/2:
  1795. throw: {error, {_Line, ?MODULE, _M}} = Error ->
  1796. Error
  1797. end.
  1798. yecc_error_type(function_clause, _) ->
  1799. not_implemented.
  1800. yeccpars1([Token | Tokens], Tzr, State, States, Vstack) ->
  1801. yeccpars2(State, element(1, Token), States, Vstack, Token, Tokens, Tzr);
  1802. yeccpars1([], {{F, A},_Line}, State, States, Vstack) ->
  1803. case apply(F, A) of
  1804. {ok, Tokens, Endline} ->
  1805. yeccpars1(Tokens, {{F, A}, Endline}, State, States, Vstack);
  1806. {eof, Endline} ->
  1807. yeccpars1([], {no_func, Endline}, State, States, Vstack);
  1808. {error, Descriptor, _Endline} ->
  1809. {error, Descriptor}
  1810. end;
  1811. yeccpars1([], {no_func, no_line}, State, States, Vstack) ->
  1812. Line = 999999,
  1813. yeccpars2(State, '$end', States, Vstack, yecc_end(Line), [],
  1814. {no_func, Line});
  1815. yeccpars1([], {no_func, Endline}, State, States, Vstack) ->
  1816. yeccpars2(State, '$end', States, Vstack, yecc_end(Endline), [],
  1817. {no_func, Endline}).
  1818. %% yeccpars1/7 is called from generated code.
  1819. %%
  1820. %% When using the {includefile, Includefile} option, make sure that
  1821. %% yeccpars1/7 can be found by parsing the file without following
  1822. %% include directives. yecc will otherwise assume that an old
  1823. %% yeccpre.hrl is included (one which defines yeccpars1/5).
  1824. yeccpars1(State1, State, States, Vstack, Token0, [Token | Tokens], Tzr) ->
  1825. yeccpars2(State, element(1, Token), [State1 | States],
  1826. [Token0 | Vstack], Token, Tokens, Tzr);
  1827. yeccpars1(State1, State, States, Vstack, Token0, [], {{_F,_A}, _Line}=Tzr) ->
  1828. yeccpars1([], Tzr, State, [State1 | States], [Token0 | Vstack]);
  1829. yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, no_line}) ->
  1830. Line = yecctoken_end_location(Token0),
  1831. yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack],
  1832. yecc_end(Line), [], {no_func, Line});
  1833. yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, Line}) ->
  1834. yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack],
  1835. yecc_end(Line), [], {no_func, Line}).
  1836. %% For internal use only.
  1837. yecc_end({Line,_Column}) ->
  1838. {'$end', Line};
  1839. yecc_end(Line) ->
  1840. {'$end', Line}.
  1841. yecctoken_end_location(Token) ->
  1842. try erl_anno:end_location(element(2, Token)) of
  1843. undefined -> yecctoken_location(Token);
  1844. Loc -> Loc
  1845. catch _:_ -> yecctoken_location(Token)
  1846. end.
  1847. -compile({nowarn_unused_function, yeccerror/1}).
  1848. yeccerror(Token) ->
  1849. Text = yecctoken_to_string(Token),
  1850. Location = yecctoken_location(Token),
  1851. {error, {Location, ?MODULE, [\"syntax error before: \", Text]}}.
  1852. -compile({nowarn_unused_function, yecctoken_to_string/1}).
  1853. yecctoken_to_string(Token) ->
  1854. try erl_scan:text(Token) of
  1855. undefined -> yecctoken2string(Token);
  1856. Txt -> Txt
  1857. catch _:_ -> yecctoken2string(Token)
  1858. end.
  1859. yecctoken_location(Token) ->
  1860. try erl_scan:location(Token)
  1861. catch _:_ -> element(2, Token)
  1862. end.
  1863. -compile({nowarn_unused_function, yecctoken2string/1}).
  1864. yecctoken2string({atom, _, A}) -> io_lib:write_atom(A);
  1865. yecctoken2string({integer,_,N}) -> io_lib:write(N);
  1866. yecctoken2string({float,_,F}) -> io_lib:write(F);
  1867. yecctoken2string({char,_,C}) -> io_lib:write_char(C);
  1868. yecctoken2string({var,_,V}) -> io_lib:format(\"~s\", [V]);
  1869. yecctoken2string({string,_,S}) -> io_lib:write_string(S);
  1870. yecctoken2string({reserved_symbol, _, A}) -> io_lib:write(A);
  1871. yecctoken2string({_Cat, _, Val}) -> io_lib:format(\"~p\", [Val]);
  1872. yecctoken2string({dot, _}) -> \"'.'\";
  1873. yecctoken2string({'$end', _}) -> [];
  1874. yecctoken2string({Other, _}) when is_atom(Other) ->
  1875. io_lib:write_atom(Other);
  1876. yecctoken2string(Other) ->
  1877. io_lib:format(\"~p\", [Other]).
  1878. ">>.