1 %%%-------------------------------------------------------------------
2 %%% File : compile_hook.erl
6 %%% Created : 25 Mar 2011 by <>
7 %%%-------------------------------------------------------------------
13 -include("makerl.hrl").
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 %% RULE EXPANSION CALLBACKS
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 -spec
expand_rule(options_type(), options_type()) -> [task_ast_type()].
19 expand_rule([{template
, Template
},
20 {target
, Target
}], ExpandOptions
) ->
21 Root
= options:unsafe_get(ExpandOptions
, '*root*'),
22 Rebased
= filename:absname("ebin/*.beam", Root
),
23 Files
= filelib:wildcard(Rebased
),
24 RelFiles
= [ filestuff:strip_prefix(F
, Root
) || F
<- Files
],
25 [{task
, app
, Target
, [Template
, "compile" | RelFiles
], [{'*root*', Root
},
26 {template
, Template
}]},
27 {task
, file
, Template
, [], [{'*root*', Root
}]}
28 %% | [{task, file, Beam, [], [{'*root*', Root}]} || Beam <- RelFiles ]
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %% TASK EXECUTION CALLBACKS
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %% What are the dependencies for this task? The .src file for sure, but...
39 %% how to tell the that it actually depends on the *name* of the compiled modules?
40 %% contents of ebin dir?
42 -spec
get_status(string(), [string()], options_type()) -> status_type().
43 get_status(Target
, PreReqs
, _Options
) ->
44 outdate_check:by_date(Target
, PreReqs
).
46 -spec
build(string(), [string()], options_type()) -> build_result().
47 build(Target
, PreReqs
, Options
) ->
48 ModNames
= get_beams(PreReqs
), % Test that Target and SRC have the same file stem
49 SrcFile
= options:unsafe_get(Options
, template
),
50 Root
= options:unsafe_get(Options
, '*root*'),
51 SrcRebased
= filestuff:rebase(SrcFile
, Root
),
52 {ok
, [AppTerm
]} = file:consult(SrcRebased
),
53 AppTermWithModules
= append_modules(AppTerm
, ModNames
),
54 TargetRebased
= filestuff:rebase(Target
, Root
),
55 file:write_file(TargetRebased
, io_lib:fwrite("~p.\n", [AppTermWithModules
])),
56 {ok
, AppTermWithModules
}.
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 -spec
get_beams([string()]) -> [string()].
63 {Beams
, _
} = lists:partition(fun(F
) ->
64 filename:extension(F
) == ".beam"
69 -spec
append_modules(tuple(), [string()]) -> tuple().
70 append_modules(AppTerm
, ModFileNames
) ->
71 {application
, Name
, Opts
} = AppTerm
,
72 ModuleNames
= [ list_to_atom(filename:basename(X
, ".beam")) || X
<- ModFileNames
],
73 NewOpts
= lists:foldl(fun({modules
, _
}, Acc
) ->
78 [{modules
, ModuleNames
}],
80 {application
, Name
, NewOpts
}.