Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion install-template
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,28 @@ write_device_template() {
EOF
}

render_shared_rebar_config() {
path="$1"
shared_config="$2"
out="$3"
# reason: generated device repos cannot read files from this repo when their
# rebar.config loads, so render shared_rebar.config inline.
while IFS= read -r line; do
case "$line" in
*"{{hb_shared_rebar_config}}"*) cat "$shared_config" ;;
*) printf '%s\n' "$line" ;;
esac
done < "$path" > "$out"
mv "$out" "$path"
}

install_template() {
template_dir="$1"
hb_dep="$2"
hb_plugin="$3"
src="$(script_dir)/src/forge/plugin/priv"
root="$(script_dir)"
src="$root/src/forge/plugin/priv"
shared_rebar_config="$root/shared_rebar.config"
support="$template_dir/hyperbeam-device"
tmp="$support.tmp.$$"
template="$template_dir/device.template"
Expand All @@ -117,6 +134,10 @@ install_template() {
mkdir -p "$tmp"
cp -R "$src/." "$tmp"
rm -f "$tmp/device.template"
render_shared_rebar_config \
"$tmp/_rebar.config" \
"$shared_rebar_config" \
"$tmp/_rebar.config.rendered"
write_device_template \
"$template_tmp" \
"$hb_dep" \
Expand Down
4 changes: 0 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@
{release, true}
]}.

{overrides, [
{override, gun, [{deps, [cowlib]}]}
]}.

{pre_hooks, [
{compile, "bash -c \"mkdir -p _build && printf '%s\\n\\n%s\\n\\n%s\\n' '-define(HB_BUILD_SOURCE, <<\\\"$(git rev-parse HEAD)\\\">>).' '-define(HB_BUILD_SOURCE_SHORT, <<\\\"$(git rev-parse --short HEAD)\\\">>).' '-define(HB_BUILD_TIME, $(date +%s)).' > _build/hb_buildinfo.hrl\""},
{compile, "bash -c \"mkdir -p _build && (test -f _build/hb_preloaded_index.hrl || printf '%s\\n\\n%s\\n' '%% Generated by hb_preload - do not edit.' '-define(PRELOADED_DEVICES_INDEX_MESSAGE_ID, undefined).' > _build/hb_preloaded_index.hrl)\""},
Expand Down
14 changes: 14 additions & 0 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%% -*- erlang -*-
%% sequence: rebar3 reads rebar.config before Forge plugins run.
%% load shared_rebar.config here, then install-template render the same file into
%% `rebar3 new device`.
ScriptDir = filename:dirname(SCRIPT),
{ok, SharedConfig} =
file:consult(
filename:join(ScriptDir, "shared_rebar.config")
),
lists:foldl(
fun({Key, _} = Term, Acc) -> lists:keystore(Key, 1, Acc, Term) end,
CONFIG,
SharedConfig
).
7 changes: 7 additions & 0 deletions shared_rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%% shared rebar.config terms for hyperbeam codebase and `rebar3 new device`.
%% rebar3 reads config before Forge plugins run, so install-template renders
%% this file into generated device repos.
{overrides, [
{override, cowboy, [{deps, [cowlib, ranch]}]},
{override, gun, [{deps, [cowlib]}]}
]}.
4 changes: 4 additions & 0 deletions src/forge/plugin/priv/_rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
{hb, {{hb_dep}}}
]}.

%% install-template replaces this marker with repo's in-root shared_rebar.config.
%% DO NOT TOUCH OR MODIFY THE MARKER:
%% {{hb_shared_rebar_config}}

{plugins, [
{plugin, {{hb_plugin}}},
{rebar3_eunit_start,
Expand Down