X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=goaljobs-reference.pod;h=2ca27c7bddbf26d92e2dcafbd74010d7c666f6fa;hb=087ea609510e7c85e1048219f4aa96348d1eaeda;hp=79125689f797576a938210799ea6f3614c80b3f8;hpb=3a572e209c501018d6a19f1533146be1c8b41ced;p=goaljobs.git diff --git a/goaljobs-reference.pod b/goaljobs-reference.pod index 7912568..2ca27c7 100644 --- a/goaljobs-reference.pod +++ b/goaljobs-reference.pod @@ -180,6 +180,85 @@ program: cc %s -o %s " object program +=head1 SPECIAL VALUES INSIDE GOALS + +=head2 goalname + +Inside goals, you can use C to get the name of the goal, ie: + + let goal foo () = + printf "my name is %s\n" goalname + +would print: + + my name is foo + +=head2 goalloc + +Inside goals, you can use C to get a printable source +location of the goal, ie: + + let goal foo () = + printf "%s\n" goalloc + +would print: + + File "source.ml", line 2, characters 13-71 (end at line 3, character 23) + +Note that the actual string format depends on the internal OCaml +function C so it might change in future. + +=head2 onfail, onsuccess, onrun + +Inside goals you can register function(s) which run if the goal +completes successfully (C), if the goal completes +successfully after running to the end (C), or if the goal fails +(C). + +For example: + + let goal built () = + onfail (fun _ -> eprintf "goal '%s' failed\n" goalname); + sh " + cc -o program main.o + " + +If the shell command (or another part of the goal) fails, then this +would print out: + + goal 'built' failed + +The single parameter passed to C is the exception that was +thrown. + +Note that the helper function C is a useful function +to call from an C handler: + + let from = "me@example.com" + let to_ = "you@example.com" + let logfile = log_program_output () + + let goal built () = + onfail (fun _ -> + let subject = sprintf "goal: %s: BUILD FAILED" goalname in + mailto ~from ~subject ~attach:[logfile] to_); + sh " + cc -o program main.o + " + +C and C are slightly different from C and +from each other: + +C functions can be called if a C condition is met +and the rest of the goal is short-circuited. C will only be +called if all the instructions in the goal actually run and succeed. + +The single unit C<()> parameter is passed to the C and +C functions. + +You can register as many functions as you want for each handler. The +order in which the functions are called is not defined. + =head1 PERIODIC JOBS If you want to have a goal that runs when some outside event happens