Permalink
Browse files

Makes filenames relative not from cwd but from toadie's dirname

Closes #4
  • Loading branch information...
1 parent 3bb48e8 commit 5115762e092d41fa7545fc1a3a772d762b8bffe6 Yurii Rashkovskii committed Feb 3, 2012
View
@@ -4,8 +4,9 @@
{esupervisor, ".*", {git, "https://github.com/spawngrid/esupervisor.git", {branch, "master"}}},
{seresye, ".*", {git, "https://github.com/spawngrid/seresye.git", {branch, "alterline"}}},
{getopt, ".*", {git, "https://github.com/jcomellas/getopt.git", {branch, "master"}}},
- {dynamic_compile, ".*", {git, "https://github.com/JacobVorreuter/dynamic_compile", {branch, "master"}}},
- {erlydtl, ".*", {git, "https://github.com/evanmiller/erlydtl.git", {branch, "master"}}}
+ {dynamic_compile, ".*", {git, "https://github.com/spawngrid/dynamic_compile", {branch, "master"}}},
+ {erlydtl, ".*", {git, "https://github.com/evanmiller/erlydtl.git", {branch, "master"}}},
+ {parse_trans, ".*", {git, "https://github.com/esl/parse_trans.git", {branch, "master"}}}
]
}.
{erl_opts, [nowarn_unused_record]}.
@@ -12,7 +12,8 @@
getopt,
sasl,
dynamic_compile,
- erlydtl
+ erlydtl,
+ parse_trans
]},
{mod, { htoad_app, []}},
{env, [
@@ -168,9 +168,12 @@ load_file(File) ->
Source =
"-module('" ++ atom_to_list(Module) ++ "').\n"
"-include(\"stdlib.hrl\").\n"
- "-compile(export_all).\n"
+ "-htoad_absname(\"" ++ File ++ "\").\n"
"-import(htoad_utils, [" ++ Utils ++ "]).\n" ++ S ++ "\n \n",
- {Module, Binary} = dynamic_compile:from_string(Source, [return_errors, debug_info, {i, code:lib_dir(htoad,include)},{i, htoad_utils:file(".")}]),
+ {Module, Binary} = dynamic_compile:from_string(Source, [export_all,
+ return_errors, debug_info,
+ {parse_transform, htoad_transform},
+ {i, code:lib_dir(htoad,include)},{i, htoad_utils:file(".")}]),
code:load_binary(Module, htoad_utils:file(File ++ ".beam"), Binary),
{Module, Binary}.
@@ -0,0 +1,42 @@
+-module(htoad_transform).
+-export([parse_transform/2]).
+
+-record(state,{
+ options,
+ absname
+ }).
+
+parse_transform(Forms, Options) ->
+ {Forms1, _State} = parse_trans:transform(fun do_transform/4,
+ #state{ options = Options },
+ Forms, Options),
+ Result = parse_trans:revert(Forms1),
+ Result.
+
+do_transform(attribute,{attribute, _, htoad_absname, AbsName} = Attr, _Context, #state{} = State) ->
+ {Attr, false, State#state{ absname = AbsName }};
+
+do_transform(application,{call, Line, {atom, Line1, load}, [File]}, _Context,
+ #state{ absname = AbsName } = State) ->
+ {{call, Line, {atom, Line1, load}, [
+ {call, Line, {remote, Line,
+ {atom, Line, filename},
+ {atom, Line, join}},
+ [list_to_cons([
+ {call, Line, {remote, Line,
+ {atom, Line, filename},
+ {atom, Line, dirname}},
+ [{string, Line, AbsName}]},
+ File
+ ], Line)]}
+ ]}, true, State};
+
+
+do_transform(_Type, Form, _Context, State) ->
+ {Form, true, State}.
+
+
+list_to_cons([],Line) ->
+ {nil,Line};
+list_to_cons([H|T],Line) ->
+ {cons, Line, H, list_to_cons(T, Line)}.
View
@@ -7,14 +7,14 @@ build_server() ->
},
on([ {operating_system_name, darwin},
{package_manager, brew} ],
- #package{ name = "git" })
+ #package{ name = "git1" })
].
main() ->
[
- load("examples/base.htd"),
+ load("base.htd"),
on({host, "spawn.local"}, {role, build_server}),
on({role, build_server}, build_server())
].
View
@@ -33,7 +33,8 @@
{app, seresye, [{incl_cond, include}]},
{app, erlware_commons, [{incl_cond, include}]},
{app, dynamic_compile, [{incl_cond, include}]},
- {app, erlydtl, [{incl_cond, include}]}
+ {app, erlydtl, [{incl_cond, include}]},
+ {app, parse_trans, [{incl_cond, include}]}
]}.
{target_dir, "htoad"}.

0 comments on commit 5115762

Please sign in to comment.