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

Yaws now properly compiles even with erl_interface not being copied #39

Merged
merged 7 commits into from
Feb 1, 2012
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ rel/nitrogen
TAGS
builds
Quickstart/static/nitrogen
Quickstart/static/doc
Quickstart/static/doc
*~
.*.sw?
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ package_yaws: rel_yaws
# SHARED

rel_inner:
@(cd rel; ./rebar generate)
@(cd rel; ./rebar generate; escript copy_erl_interface.escript)
@(cd rel/nitrogen; make)
@printf "Nitrogen Version:\n${NITROGEN_VERSION}\n\n" > rel/nitrogen/BuildInfo.txt
@echo "Built On (uname -v):" >> rel/nitrogen/BuildInfo.txt
Expand Down
Binary file modified rebar
Binary file not shown.
188 changes: 188 additions & 0 deletions rel/copy_erl_interface.escript
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname copy_erl_interface
%%
%% Coyright 2012 - Jesse Gumm
%% MIT License
%%
%% The purpoose of this file is due to a behavior or bug in Erlang's reltool
%% functionality, where the erl_interface directory is not copied using reltool.
%% This is a workaround for that shortcoming particularly for building Yaws
%% with Nitrogen, as Yaws requires erl_interface to compile.
%%
%% Much of this file has been straight up copied from rebar, most of it is
%% overkill for what it's doing, and can probably be stripped to its bare bones,
%% especially for whenever that shortcoming gets fixed.
%%
%% So for now, this serves a simple purpose which will likely be rendered
%% unnecessary in the future.

-define(CONSOLE(Str,Args), io:format(Str,Args)).
-define(FMT(Str,Args), lists:flatten(io_lib:format(Str,Args))).

main([]) ->
Path = code:lib_dir(erl_interface),
To = filename:join([get_cwd(), "nitrogen", "lib", filename:basename(Path)]),

?CONSOLE("~s~n",["Copying " ++ Path]),
cp_r([Path],To),
ok.


%% Copied from Rebar
cp_r(Sources, Dest) ->
case os:type() of
{unix, _} ->
EscSources = [escape_spaces(Src) || Src <- Sources],
SourceStr = string:join(EscSources, " "),
{ok, []} = sh(?FMT("cp -R ~s \"~s\"",
[SourceStr, Dest]),
[{use_stdout, false}, return_on_error]),
ok;
{win32, _} ->
lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources),
ok
end.


%% Windows stuff
xcopy_win32(Source,Dest)->
{ok, R} = sh(
?FMT("xcopy \"~s\" \"~s\" /q /y /e 2> nul",
[filename:nativename(Source), filename:nativename(Dest)]),
[{use_stdout, false}, return_on_error]),
case length(R) > 0 of
%% when xcopy fails, stdout is empty and and error message is printed
%% to stderr (which is redirected to nul)
true -> ok;
false ->
{error, lists:flatten(
io_lib:format("Failed to xcopy from ~s to ~s~n",
[Source, Dest]))}
end.

cp_r_win32({true, SourceDir}, {true, DestDir}) ->
%% from directory to directory
SourceBase = filename:basename(SourceDir),
ok = case file:make_dir(filename:join(DestDir, SourceBase)) of
{error, eexist} -> ok;
Other -> Other
end,
ok = xcopy_win32(SourceDir, filename:join(DestDir, SourceBase));
cp_r_win32({false, Source} = S,{true, DestDir}) ->
%% from file to directory
cp_r_win32(S, {false, filename:join(DestDir, filename:basename(Source))});
cp_r_win32({false, Source},{false, Dest}) ->
%% from file to file
{ok,_} = file:copy(Source, Dest),
ok;
cp_r_win32(Source,Dest) ->
Dst = {filelib:is_dir(Dest), Dest},
lists:foreach(fun(Src) ->
ok = cp_r_win32({filelib:is_dir(Src), Src}, Dst)
end, filelib:wildcard(Source)),
ok.

%% Shell Command Stuff (from rebar_utils)
sh(Command0, Options0) ->
% ?CONSOLE("sh info:\n\tcwd: ~p\n\tcmd: ~s\n", [get_cwd(), Command0]),
% ?DEBUG("\topts: ~p\n", [Options0]),

DefaultOptions = [use_stdout, abort_on_error],
Options = [expand_sh_flag(V)
|| V <- proplists:compact(Options0 ++ DefaultOptions)],

ErrorHandler = proplists:get_value(error_handler, Options),
OutputHandler = proplists:get_value(output_handler, Options),

Command = patch_on_windows(Command0, proplists:get_value(env, Options, [])),
PortSettings = proplists:get_all_values(port_settings, Options) ++
[exit_status, {line, 16384}, use_stdio, stderr_to_stdout, hide],
Port = open_port({spawn, Command}, PortSettings),

case sh_loop(Port, OutputHandler, []) of
{ok, _Output} = Ok ->
Ok;
{error, {_Rc, _Output}=Err} ->
ErrorHandler(Command, Err)
end.

get_cwd() ->
{ok,Dir} = file:get_cwd(),
Dir.

patch_on_windows(Cmd, Env) ->
case os:type() of
{win32,nt} ->
"cmd /q /c "
++ lists:foldl(fun({Key, Value}, Acc) ->
expand_env_variable(Acc, Key, Value)
end, Cmd, Env);
_ ->
Cmd
end.

expand_env_variable(InStr, VarName, RawVarValue) ->
case string:chr(InStr, $$) of
0 ->
%% No variables to expand
InStr;
_ ->
VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", [global]),
%% Use a regex to match/replace:
%% Given variable "FOO": match $FOO\s | $FOOeol | ${FOO}
RegEx = io_lib:format("\\\$(~s(\\s|$)|{~s})", [VarName, VarName]),
ReOpts = [global, {return, list}],
re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts)
end.

sh_loop(Port, Fun, Acc) ->
receive
{Port, {data, {eol, Line}}} ->
sh_loop(Port, Fun, Fun(Line ++ "\n", Acc));
{Port, {data, {noeol, Line}}} ->
sh_loop(Port, Fun, Fun(Line, Acc));
{Port, {exit_status, 0}} ->
{ok, lists:flatten(lists:reverse(Acc))};
{Port, {exit_status, Rc}} ->
{error, {Rc, lists:flatten(lists:reverse(Acc))}}
end.

escape_spaces(Str) ->
re:replace(Str, " ", "\\\\ ", [global, {return, list}]).


log_and_abort(Message) ->
?CONSOLE("Aborting: ~s ~n",[Message]).



expand_sh_flag(return_on_error) ->
{error_handler,
fun(_Command, Err) ->
{error, Err}
end};
expand_sh_flag({abort_on_error, Message}) ->
{error_handler,
fun(Cmd,Err) ->
log_and_abort({Message,{Cmd,Err}})
end};
expand_sh_flag(abort_on_error) ->
expand_sh_flag({abort_on_error, error});
expand_sh_flag(use_stdout) ->
{output_handler,
fun(Line, Acc) ->
?CONSOLE("~s", [Line]),
[Line | Acc]
end};
expand_sh_flag({use_stdout, false}) ->
{output_handler,
fun(Line, Acc) ->
[Line | Acc]
end};
expand_sh_flag({cd, _CdArg} = Cd) ->
{port_settings, Cd};
expand_sh_flag({env, _EnvArg} = Env) ->
{port_settings, Env}.


Binary file modified rel/overlay/common/rebar
Binary file not shown.
2 changes: 1 addition & 1 deletion rel/overlay/inets/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deps"
]}.

{require_otp_vsn, "R13B04|R14"}.
{require_otp_vsn, "R13B04|R14|R15"}.

{cover_enabled, true}.

Expand Down
4 changes: 2 additions & 2 deletions rel/overlay/mochiweb/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deps"
]}.

{require_otp_vsn, "R13B04|R14"}.
{require_otp_vsn, "R13B04|R14|R15"}.

{cover_enabled, true}.

Expand All @@ -12,7 +12,7 @@
{deps_dir, ["lib"]}.

{deps, [
{mochiweb, "1.5.*", {git, "git://github.com/mochi/mochiweb.git", {tag, "1.5.0"}}},
{mochiweb, "2.3.*", {git, "git://github.com/mochi/mochiweb.git", {tag, "v2.3.0"}}},

{nitrogen_core, "2.1.*", {git, "git://github.com/nitrogen/nitrogen_core", "HEAD"}},
{nprocreg, "0.2.*", {git, "git://github.com/nitrogen/nprocreg", "HEAD"}},
Expand Down
4 changes: 2 additions & 2 deletions rel/overlay/webmachine/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deps"
]}.

{require_otp_vsn, "R13B04|R14"}.
{require_otp_vsn, "R13B04|R14|R15"}.

{cover_enabled, true}.

Expand All @@ -12,7 +12,7 @@
{deps_dir, ["lib"]}.

{deps, [
{webmachine, "1.8.*", {git, "git://github.com/basho/webmachine.git", {tag, "webmachine-1.8.0"}}},
{webmachine, "1.8.*", {git, "git://github.com/basho/webmachine.git", {tag, "webmachine-1.8.1"}}},

{nitrogen_core, "2.1.*", {git, "git://github.com/nitrogen/nitrogen_core", "HEAD"}},
{nprocreg, "0.2.*", {git, "git://github.com/nitrogen/nprocreg", "HEAD"}},
Expand Down
16 changes: 14 additions & 2 deletions rel/overlay/yaws/etc/yaws.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ logdir = ./log
<server mydomain.org>
port = 8000
listen = 127.0.0.1

#the static code to be served directly by yaws is found in ./site/static
docroot = ./site/static
appmods = </, nitrogen_yaws>
</server>

# tell yaws to pass control to the nitrogen_yaws module
# (specifically nitrogen_yaws:out/1) for all requests except for any request
# that starts with "images/", "nitrogen/", "css/", or "/js".
# Bear in mind, however, the caveat to this performance improvement:
# this means that you cannot have any pages called "nitrogen_xxx" or "css_yyy" because
# the yaws config will see the "exclude_paths" rule below and completely ignore nitrogen.
# Should you wish to have yaws handle any more static files, for example, if you added
# a videos directory in site/static/, you can simply add "videos" to the end of the list
# Ex: appmods = </, nitrogen_yaws exclude_paths images nitrogen css js videos>
appmods = </, nitrogen_yaws exclude_paths images nitrogen css js>
</server>
4 changes: 3 additions & 1 deletion rel/overlay/yaws/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deps"
]}.

{require_otp_vsn, "R13B04|R14"}.
{require_otp_vsn, "R13B04|R14|R15"}.

{cover_enabled, true}.

Expand All @@ -12,6 +12,8 @@
{deps_dir, ["lib"]}.

{deps, [
{yaws, "1.*", {git, "git://github.com/klacke/yaws",{tag, "yaws-1.92"}}},

{nitrogen_core, "2.1.*", {git, "git://github.com/nitrogen/nitrogen_core", "HEAD"}},
{nprocreg, "0.2.*", {git, "git://github.com/nitrogen/nprocreg", "HEAD"}},
{simple_bridge, "1.2.*", {git, "git://github.com/nitrogen/simple_bridge", "HEAD"}},
Expand Down
Binary file modified rel/rebar
Binary file not shown.
3 changes: 2 additions & 1 deletion rel/reltool_mochiweb.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"^bin/.*",
"^erts.*/bin/(dialyzer|typer)"
]},

{app, sasl, [{incl_cond, include}]},
{app, eunit, [{incl_cond, include}]}
]}.
Expand All @@ -36,4 +37,4 @@

%% Copy Mochiweb files...
{copy, "overlay/mochiweb/*"}
]}.
]}.
2 changes: 1 addition & 1 deletion rel/reltool_webmachine.config
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@

%% Copy Webmachine files...
{copy, "overlay/webmachine/*"}
]}.
]}.
2 changes: 1 addition & 1 deletion rel/reltool_yaws.config
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@

%% Copy Yaws files...
{copy, "overlay/yaws/*"}
]}.
]}.