Skip to content

Commit cea55dc

Browse files
committed
Detect executable with file(1)
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 6fc8beb commit cea55dc

File tree

2 files changed

+52
-38
lines changed

2 files changed

+52
-38
lines changed

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

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ on: [push, pull_request]
1010

1111
jobs:
1212
build-and-test:
13-
runs-on: "ubuntu-24.04"
13+
runs-on: ${{ matrix.os }}
1414
strategy:
15+
fail-fast: false
1516
matrix:
1617
otp: ["25", "26", "27", "28"]
18+
os: ["ubuntu-24.04", "ubuntu-24.04-arm", "macos-26", "macos-15-intel"]
1719

1820
include:
1921
- otp: "25"
2022
make_jobs: "compile etest"
21-
rebar3_version: "3.24.0 "
23+
rebar3_version: "3.24.0"
2224
- otp: "26"
2325
make_jobs: "all"
2426
rebar3_version: "3.25.1"
@@ -31,20 +33,44 @@ jobs:
3133

3234
steps:
3335
# Builder info
34-
- name: "System info"
36+
- name: "Install deps"
37+
if: startsWith(matrix.os, 'macos-') && matrix.otp != '25'
38+
run: brew update && HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf ninja llvm erlang@${{ matrix.otp }} rebar3
39+
40+
- name: "Install deps"
41+
if: startsWith(matrix.os, 'macos-') && matrix.otp == '25'
3542
run: |
36-
echo "**uname:**"
37-
uname -a
38-
echo "**OTP version:**"
39-
cat $(dirname $(which erlc))/../releases/RELEASES || true
43+
brew update
44+
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf ninja llvm erlang@${{ matrix.otp }}
45+
wget https://github.com/erlang/rebar3/releases/download/${{ matrix.rebar3_version }}/rebar3
46+
chmod +x rebar3
47+
for bin_dir in {/usr/local,/opt/homebrew}/opt/erlang@25/bin/ ; do
48+
if [ -e ${bin_dir} ]; then
49+
sudo cp rebar3 ${bin_dir}
50+
fi
51+
done
52+
echo PATH="/usr/local/opt/erlang@${{ matrix.otp }}/bin:/opt/homebrew/opt/erlang@${{ matrix.otp }}/bin:$PATH" >> $GITHUB_ENV
53+
54+
- name: "Install deps"
55+
if: startsWith(matrix.os, 'ubuntu-')
56+
run: |
57+
sudo apt install -y make git gcc-14 g++-14 cmake gperf zlib1g-dev libmbedtls-dev ninja-build
4058
4159
# Setup OTP
4260
- name: "Setup OTP"
61+
if: startsWith(matrix.os, 'ubuntu-')
4362
uses: erlef/setup-beam@v1
4463
with:
4564
otp-version: ${{ matrix.otp }}
4665
rebar3-version: ${{ matrix.rebar3_version }}
4766

67+
- name: "System info"
68+
run: |
69+
echo "**uname:**"
70+
uname -a
71+
echo "**OTP version:**"
72+
cat $(dirname $(which erlc))/../releases/RELEASES || true
73+
4874
# Checkout AtomVM
4975
- name: "Checkout AtomVM"
5076
uses: actions/checkout@v5
@@ -53,18 +79,14 @@ jobs:
5379
path: 'atomvm'
5480
submodules: 'recursive'
5581

56-
- name: "Install deps"
57-
run: |
58-
sudo apt install -y make git gcc-14 g++-14 cmake gperf zlib1g-dev libmbedtls-dev ninja-build
59-
6082
- name: "Install AtomVM"
6183
working-directory: 'atomvm'
6284
run: |
6385
mkdir build
6486
cd build
6587
cmake -DAVM_BUILD_RUNTIME_ONLY=ON -G Ninja ..
66-
ninja
67-
sudo ninja install
88+
cmake --build .
89+
sudo cmake --build . -t install
6890
atomvm -v
6991
7092
# Setup

src/atomvm_escriptize_provider.erl

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,32 +235,24 @@ find_atomvm_binary() ->
235235

236236
%% @private
237237
resolve_atomvm_binary(Path) ->
238-
% Try to read the file to see if it's a shell script
239-
case file:read_file(Path) of
240-
{ok, Content} ->
241-
case binary:part(Content, 0, 9) of
242-
<<"#!/bin/sh">> ->
243-
% It's a shell script, parse it to find the actual binary
244-
% The standard wrapper is at /prefix/bin/atomvm
245-
% The actual binary is at /prefix/lib/atomvm/AtomVM
246-
Dir = filename:dirname(Path),
247-
Prefix = filename:dirname(Dir),
248-
ActualBinary = filename:join([Prefix, "lib", "atomvm", "AtomVM"]),
249-
case filelib:is_file(ActualBinary) of
250-
true -> {ok, ActualBinary};
251-
false -> {error, not_found}
252-
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;
259-
_ ->
260-
{error, not_a_script}
238+
case string:trim(os:cmd("file -b --mime-type " ++ Path)) of
239+
"text/x-shellscript" ->
240+
% It's a shell script, suppose
241+
% The standard wrapper is at /prefix/bin/atomvm
242+
% The actual binary is at /prefix/lib/atomvm/AtomVM
243+
Dir = filename:dirname(Path),
244+
Prefix = filename:dirname(Dir),
245+
ActualBinary = filename:join([Prefix, "lib", "atomvm", "AtomVM"]),
246+
case filelib:is_file(ActualBinary) of
247+
true -> {ok, ActualBinary};
248+
false -> {error, not_found}
261249
end;
262-
{error, Reason} ->
263-
{error, Reason}
250+
"application/x-mach-binary" ->
251+
{ok, Path};
252+
"application/x-elf" ->
253+
{ok, Path};
254+
Other ->
255+
{error, {unexpected, Other}}
264256
end.
265257

266258
%% @private

0 commit comments

Comments
 (0)