Skip to content

Commit

Permalink
Merge pull request #2293 from reganheath/add-powershell-scripts
Browse files Browse the repository at this point in the history
Add powershell script generation option for escriptize on windows; use for rebar3 itself
  • Loading branch information
ferd authored May 23, 2020
2 parents 7c4b1a7 + 7791817 commit 35423c8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
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).

0 comments on commit 35423c8

Please sign in to comment.