Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add powershell script generation option for escriptize on windows; use for rebar3 itself #2293

Merged
merged 3 commits into from
May 23, 2020
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ jobs:
- name: Install Erlang
run: choco install erlang
- name: Compile
run: cmd.exe /c 'bootstrap.bat'
run: .\bootstrap.ps1
- name: CT tests
run: cmd.exe /c 'rebar3.cmd ct'
run: .\rebar3.ps1 ct
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ _checkouts
.rebar3
rebar3
rebar3.cmd
rebar3.ps1
_build
.depsolver_plt
*.beam
Expand Down
1 change: 1 addition & 0 deletions bootstrap.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
& escript.exe bootstrap @args
1 change: 1 addition & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
]}.

{escript_name, rebar3}.
{escript_wrappers_windows, ["cmd", "powershell"]}.
{escript_comment, "%%Rebar3 3.14.0-rc1\n"}.
{escript_emu_args, "%%! +sbtu +A1\n"}.
%% escript_incl_extra is for internal rebar-private use only.
Expand Down
2 changes: 2 additions & 0 deletions rebar.config.sample
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
{escript_main_app, application}.
%% Name of the resulting escript executable
{escript_name, "application"}.
%% Wrapper type(s) for escript executable on windows
{escript_wrappers_windows, ["cmd","powershell"]}.
%% apps (other than main and deps) to be included
{escript_incl_apps, []}.
%% Executable escript lines
Expand Down
12 changes: 10 additions & 2 deletions src/rebar_prv_escriptize.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ escriptize(State0, App) ->
{ok, #file_info{mode = Mode}} = file:read_file_info(Filename),
ok = file:change_mode(Filename, Mode bor 8#00111);
{win32, _} ->
write_windows_script(Filename)
write_windows_scripts(Filename, rebar_state:get(State, escript_wrappers_windows, ["cmd"]))
end,
{ok, State}.

Expand Down Expand Up @@ -272,9 +272,17 @@ def(Rm, State, Key, Default) ->
rm_newline(String) ->
[C || C <- String, C =/= $\n].

write_windows_script(Target) ->
write_windows_scripts(Target, Wrappers) ->
lists:foreach(fun(Wrapper) -> write_windows_script(Target, Wrapper) end, Wrappers).

write_windows_script(Target, "powershell") ->
CmdPath = unicode:characters_to_list(Target) ++ ".ps1",
CmdScript="& escript.exe \"$PSScriptRoot\\$((Get-Item $PSCommandPath).Basename)\" @args\r\n",
ok = file:write_file(CmdPath, CmdScript);
write_windows_script(Target, _) ->
CmdPath = unicode:characters_to_list(Target) ++ ".cmd",
CmdScript=
"@echo off\r\n"
"escript.exe \"%~dpn0\" %*\r\n",
ok = file:write_file(CmdPath, CmdScript).