Skip to content

Commit 468ee62

Browse files
authored
Small adjustments to escriptize provider and test (#1)
This makes a few small adjustments to the escriptize provider as well as the tests, most of these are necessary changes. A few additional changes have heen made, such as adding the users $HOME/.local, to the default AtomVV install search paths, and supporting matching on the AtomVM elf executable, as well as the shell launcher script. Signed-off-by: Winford <winford@object.stream>
1 parent ff5c0e2 commit 468ee62

File tree

5 files changed

+71
-33
lines changed

5 files changed

+71
-33
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,26 @@ on: [push, pull_request]
1010

1111
jobs:
1212
build-and-test:
13-
runs-on: "ubuntu-22.04"
13+
runs-on: "ubuntu-24.04"
1414
strategy:
1515
matrix:
1616
otp: ["25", "26", "27", "28"]
1717

1818
include:
1919
- otp: "25"
2020
make_jobs: "compile etest"
21+
rebar3_version: "3.24.0 "
2122
- otp: "26"
2223
make_jobs: "all"
24+
rebar3_version: "3.25.1"
2325
- otp: "27"
2426
make_jobs: "all"
27+
rebar3_version: "3.25.1"
2528
- otp: "28"
2629
make_jobs: "all"
30+
rebar3_version: "3.25.1"
2731

2832
steps:
29-
# Setup
30-
- name: "Checkout repo"
31-
uses: actions/checkout@v2
32-
with:
33-
submodules: 'recursive'
34-
35-
- uses: erlef/setup-beam@v1
36-
with:
37-
otp-version: ${{ matrix.otp }}
38-
3933
# Builder info
4034
- name: "System info"
4135
run: |
@@ -44,17 +38,43 @@ jobs:
4438
echo "**OTP version:**"
4539
cat $(dirname $(which erlc))/../releases/RELEASES || true
4640
41+
# Setup OTP
42+
- name: "Setup OTP"
43+
uses: erlef/setup-beam@v1
44+
with:
45+
otp-version: ${{ matrix.otp }}
46+
rebar3-version: ${{ matrix.rebar3_version }}
47+
48+
# Checkout AtomVM
49+
- name: "Checkout AtomVM"
50+
uses: actions/checkout@v5
51+
with:
52+
repository: 'atomvm/AtomVM'
53+
path: 'atomvm'
54+
submodules: 'recursive'
55+
4756
- name: "Install deps"
4857
run: |
49-
sudo apt install -y make git
58+
sudo apt install -y make git gcc-14 g++-14 cmake gperf zlib1g-dev libmbedtls-dev ninja-build
5059
51-
- name: "Build rebar3"
60+
- name: "Install AtomVM"
61+
working-directory: 'atomvm'
5262
run: |
53-
cd /tmp
54-
git clone https://github.com/erlang/rebar3.git
55-
cd rebar3
56-
./bootstrap
63+
mkdir build
64+
cd build
65+
cmake -DAVM_BUILD_RUNTIME_ONLY=ON -G Ninja ..
66+
ninja
67+
sudo ninja install
68+
atomvm -v
69+
70+
# Setup
71+
- name: "Checkout repo"
72+
uses: actions/checkout@v5
73+
with:
74+
path: 'atomvm_packbeam'
75+
submodules: 'recursive'
5776

5877
# Build
5978
- name: "Make"
79+
working-directory: 'atomvm_packbeam'
6080
run: PATH="/tmp/rebar3:${PATH}" make ${{ matrix.make_jobs }}

src/atomvm_escriptize_provider.erl

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
-define(PROVIDER, escriptize).
3030
-define(DEPS, [packbeam]).
3131
-define(OPTS, [
32-
{atomvm_binary, $b, "atomvm_binary", string, "Path to AtomVM binary (default: which AtomVM)"},
33-
{atomvmlib, $l, "atomvmlib", string, "Path to atomvmlib.avm"},
32+
{atomvm_binary, $b, "atomvm_binary", string, "Path to AtomVM binary (default: which atomvm)"},
33+
{atomvmlib, $l, "atomvmlib", string, "Path to atomvmlib.avm (default: auto discovered)"},
3434
{output, $o, "output", string, "Output executable name (default: app name)"},
3535
{objcopy, $c, "objcopy", string, "Path to objcopy tool (auto-detected if not specified)"},
3636
{start, $s, "start", atom, "Start module (default: app name)"}
@@ -115,10 +115,11 @@ do(State) ->
115115
catch
116116
C:E:S ->
117117
rebar_api:error(
118-
"An error occurred in the ~p task. Class=~p Error=~p Stacktrace=~p~n", [
119-
?PROVIDER, C, E, S
118+
"An error occurred in the ~p task. Class=~p Error=~p~n", [
119+
?PROVIDER, C, E
120120
]
121121
),
122+
rebar_api:debug("===== Stacktrace ==~n~p~n", [S]),
122123
{error, E}
123124
end.
124125

@@ -156,7 +157,7 @@ get_atomvmlib_path(Opts) ->
156157
%% @private
157158
find_atomvmlib() ->
158159
% First try to infer from AtomVM wrapper script
159-
case os:find_executable("AtomVM") of
160+
case os:find_executable("atomvm") of
160161
false ->
161162
find_atomvmlib_fallback();
162163
WrapperPath ->
@@ -173,6 +174,7 @@ find_atomvmlib_fallback() ->
173174
"/opt/local/lib/atomvm/atomvmlib.avm",
174175
"/usr/local/lib/atomvm/atomvmlib.avm",
175176
"/usr/lib/atomvm/atomvmlib.avm",
177+
filename:join([os:getenv("HOME", "/.local"), "lib", "atomvm", "atomvmlib.avm"]),
176178
filename:join([os:getenv("HOME", "/tmp"), ".atomvm", "lib", "atomvmlib.avm"])
177179
],
178180
case lists:filter(fun filelib:is_file/1, PossiblePaths) of
@@ -210,9 +212,18 @@ get_atomvm_binary(Opts) ->
210212

211213
%% @private
212214
find_atomvm_binary() ->
213-
case os:find_executable("AtomVM") of
215+
case os:find_executable("atomvm") of
214216
false ->
215-
{error, "AtomVM binary not found in PATH. Please specify with --atomvm_binary option"};
217+
case os:find_executable("AtomVM") of
218+
Path ->
219+
case resolve_atomvm_binary(Path) of
220+
{ok, BinaryPath} ->
221+
{ok, BinaryPath};
222+
_ ->
223+
{error,
224+
"AtomVM binary not found in PATH. Please specify with --atomvm_binary option"}
225+
end
226+
end;
216227
Path ->
217228
% Check if it's a shell script wrapper and find the actual binary
218229
case resolve_atomvm_binary(Path) of
@@ -227,10 +238,10 @@ resolve_atomvm_binary(Path) ->
227238
% Try to read the file to see if it's a shell script
228239
case file:read_file(Path) of
229240
{ok, Content} ->
230-
case binary:match(Content, <<"#!/bin/sh">>) of
231-
{0, _} ->
241+
case binary:part(Content, 0, 9) of
242+
<<"#!/bin/sh">> ->
232243
% It's a shell script, parse it to find the actual binary
233-
% The standard wrapper is at /prefix/bin/AtomVM
244+
% The standard wrapper is at /prefix/bin/atomvm
234245
% The actual binary is at /prefix/lib/atomvm/AtomVM
235246
Dir = filename:dirname(Path),
236247
Prefix = filename:dirname(Dir),
@@ -239,6 +250,12 @@ resolve_atomvm_binary(Path) ->
239250
true -> {ok, ActualBinary};
240251
false -> {error, not_found}
241252
end;
253+
<<_:8, $e, $l, $f, _:40>> ->
254+
% It's the actual binary
255+
case filelib:is_file(Path) of
256+
true -> {ok, Path};
257+
false -> {error, not_found}
258+
end;
242259
_ ->
243260
{error, not_a_script}
244261
end;

src/atomvm_packbeam_provider.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ get_start_module(State, Opts) ->
137137
EscriptName ->
138138
EscriptName
139139
end;
140-
StartModule -> StartModule
140+
StartModule ->
141+
StartModule
141142
end.
142143

143144
-spec format_error(any()) -> iolist().

test/driver/src/escriptize_tests.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_defaults(Opts) ->
3535
test:debug(Output, Opts),
3636

3737
ok = test:expect_contains("Created packed AVM:", Output),
38-
ok = test:expect_contains("_build/default/lib/myscript_packed.avm", Output),
38+
ok = test:expect_contains("_build/default/lib/myscript.avm", Output),
3939
ok = test:expect_contains("with start module myscript", Output),
4040

4141
ok = test:expect_contains("Created standalone executable:", Output),
@@ -44,7 +44,7 @@ test_defaults(Opts) ->
4444
ExecPath = test:make_path([AppDir, "_build/default/bin/myscript"]),
4545
ok = test:file_exists(ExecPath),
4646

47-
[] = test:execute_cmd(ExecPath),
47+
[] = test:execute_cmd(ExecPath, Opts),
4848

4949
test:tick().
5050

test/driver/src/test.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ make_opts(Opts) ->
128128
).
129129

130130
execute_cmd(Cmd) ->
131-
execute_cmd(Cmd, false).
131+
execute_cmd(Cmd, #{}).
132132

133133
execute_cmd(Cmd, Opts) ->
134-
case maps:get(verbose, Opts) orelse maps:get(debug, Opts) of
134+
case maps:get(verbose, Opts, false) orelse maps:get(debug, Opts, false) of
135135
true ->
136136
io:format("#executing> ~s~n", [Cmd]);
137137
_ ->
@@ -141,7 +141,7 @@ execute_cmd(Cmd, Opts) ->
141141
os:cmd(Cmd).
142142

143143
debug(Msg, Opts) ->
144-
case maps:get(debug, Opts) of
144+
case maps:get(debug, Opts, false) of
145145
true ->
146146
io:format("~s~n", [Msg]);
147147
_ ->

0 commit comments

Comments
 (0)