First published version.
[goaljobs.git] / NOTES
1 Like 'make' except:
2  - Predicates can be based on arbitrary expressions, not just
3    "file X is older than file Y".
4  - Rules are more flexible and encourage structuring and reuse
5    through functions.
6  - Goals can be parameterized.
7  - Program can run continuously to implement business rules.
8
9 Differences from 'whenjobs':
10  - Goals instead of variables.
11  - Persistent (across session) variables exist, but are not central.
12  - Doesn't use <<..>> for shell scripts (has a function 'sh' instead).
13
14 Similarities to 'whenjobs':
15  - Each shell script runs in its own temporary directory.
16
17 Example Makefile rule and translation to goaljobs language:
18
19   %.o: %.c
20     cc -c $< -o $@
21
22   let goal compile c_file =
23     require (file_exists c_file);
24     let o_file = replace_substring ".c" ".o" c_file in
25     target (file_exists o_file && file_newer o_file c_file);
26     sh "cc -c %s -o %s" c_file o_file
27
28 Example program:
29
30   let package = "foo"
31
32   let rec goal website_updated version =
33     let tarfile = sprintf "%s-%s.tar.gz" package version in
34     let tarpath = getenv "HOME" // "html" // tarfile in
35     let url = sprintf "http://example.com/%s" tarfile in
36
37     target (url_exists url);
38
39     require (tarball_exists version);
40     require (tarball_tested version);
41
42     sh "rsync %s example.com:/html/" tarpath
43
44   and goal tarball_tested version =
45     let tarfile = sprintf "%s-%s.tar.gz" package version in
46     let tarpath = getenv "HOME" // "html" // tarfile in
47     let memkey = package ^ "_tested_" ^ version in
48
49     target (memory_exists memkey);
50
51     require (tarball_exists version);
52
53     sh "
54       tar zxf %s
55       cd %s-%s
56       ./configure
57       make
58       make check
59     " tarpath package version;
60
61     memory_set memkey "1"
62
63   and goal tarball_exists version =
64     let tarpath = getenv "HOME" // "html" // tarfile in
65     target (file_exists tarpath);
66     sh "
67       cd $HOME/repos/%s
68       git fetch
69       git archive --prefix %s-%s/ v%s | gzip > %s-t
70       mv %s-t %s
71     " package package version version tarpath tarpath tarpath
72
73   every 1 hour =
74     let version = shout "
75       cd $HOME/repos/%s
76       git fetch
77       git describe --tags --abbrev=0 --match='v*'
78     " package in
79     require (website_updated version)