From e82ef746a626f767dae4bd592caf7e0f643ffd3c Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 24 Feb 2017 12:42:18 -0500 Subject: Windows escripts get cmd autogenerated This also patches up a problem for hooks when dealing with directories with spaces in them, and reduces complexity of bootstrap file. --- src/rebar_prv_escriptize.erl | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_escriptize.erl b/src/rebar_prv_escriptize.erl index 7ee20c2..5c0c989 100644 --- a/src/rebar_prv_escriptize.erl +++ b/src/rebar_prv_escriptize.erl @@ -130,9 +130,15 @@ escriptize(State0, App) -> throw(?PRV_ERROR({escript_creation_failed, AppName, EscriptError})) end, - %% Finally, update executable perms for our script - {ok, #file_info{mode = Mode}} = file:read_file_info(Filename), - ok = file:change_mode(Filename, Mode bor 8#00111), + %% Finally, update executable perms for our script on *nix or write out + %% script files on win32 + case os:type() of + {unix, _} -> + {ok, #file_info{mode = Mode}} = file:read_file_info(Filename), + ok = file:change_mode(Filename, Mode bor 8#00111); + {win32, _} -> + write_windows_script(Filename) + end, {ok, State}. -spec format_error(any()) -> iolist(). @@ -258,3 +264,11 @@ def(Rm, State, Key, Default) -> rm_newline(String) -> [C || C <- String, C =/= $\n]. + +write_windows_script(Target) -> + CmdScript= + "@echo off\r\n" + "setlocal\r\n" + "set rebarscript=%~f0\r\n" + "escript.exe \"%rebarscript:.cmd=%\" %*\r\n", + ok = file:write_file(Target ++ ".cmd", CmdScript). -- cgit v1.1