Minor man page fixes: one typo, and missing control directory
[sgt/utils] / buildrun / buildrun.but
CommitLineData
31f0fd76 1\cfg{man-identity}{buildrun}{1}{2012-08-01}{Simon Tatham}{Simon Tatham}
2
92dccb8d 3\define{dash} \u2013{-}
4
31f0fd76 5\title Man page for \cw{buildrun}
6
7\U NAME
8
92dccb8d 9\cw{buildrun} \dash run one program after another has completed successfully
31f0fd76 10
11\U SYNOPSIS
12
13\c buildrun -w control-directory command1 [ argument... ]
14\e bbbbbbbb bb iiiiiiiiiiiiiiiii iiiiiiii iiiiiiii
15\c buildrun -r control-directory [ command2 [ argument... ] ]
16\e bbbbbbbb bb iiiiiiiiiiiiiiiii iiiiiiii iiiiiiii
17
18\U DESCRIPTION
19
20\cw{buildrun} is a utility which you can use to wrap two separate
21commands, and it will wait to run the second command until the first
22command is not currently running and its last run completed
23successfully. This includes waiting while the first one runs several
24times (if the first few runs fail), and also includes not waiting at
25all if it's \e{already} true that the most recent run of the first
26command was successful.
27
28You might use \cw{buildrun} in situations where you want to run two
29commands in succession, but (for one reason or another) you'd rather
30have them run in separate shell sessions and therefore you don't want
31to take the obvious approach of simply issuing a compound command
32using the shell's \cw{&&} operator.
33
34A typical scenario involves the first command being a software build
35process (a compile command, or \cw{make}, or similar), and the second
36being some attempt to run the resulting program or its test suite or a
37debugger. You might want to run your build and test commands in
38separate shell sessions for several reasons: if it's convenient to
39give them different working directories, or in order to separate the
40shell command-recall histories (so that the build terminal has all the
41commands related to editing and searching source files, and the test
42terminal has the ones related to adjusting the test environment), or
43in order to separate their output (so that successive test runs appear
44adjacent to each other in the test terminal and can be easily
45compared, while the output from build commands is available for
46checking if it's needed but doesn't keep scrolling the test output off
47the screen).
48
49To use \cw{buildrun}, you must first decide on a location for a
50\e{control directory} which the two \cw{buildrun} processes can use to
51communicate between themselves. Then, in one window, you run the
52command you want to run first (e.g. the compile operation), prefixed
53with a \cw{buildrun -w} command giving the pathname of the control
54directory. For instance, you might run
55
56\c buildrun -w /tmp/controldir make
57\e bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
58
59Then, in another window, run the second command (e.g. a test or
60debugging command) prefixed with a similar \cw{buildrun -r} command,
61for example
62
63\c buildrun -r /tmp/controldir ./test.sh
64\e bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
65
66The instance of \cw{buildrun} run with \cw{-w} will immediately run
67its command; the instance run with \cw{-r} will wait for the \cw{-w}
68command to complete, and then run its own command. If the first
69command fails, the \cw{buildrun -r} process will continue to sleep;
70you can then correct the problem and re-run the compile, and
71\cw{buildrun -r} will only wake up once an instance of \cw{buildrun
72-w}'s command completes successfully.
73
74If you then immediately re-run \cw{buildrun -r} without starting
75another build, it will run its command instantly without waiting. So
76you can repeat your testing or debugging, or run several different
77test runs, by simply recalling the same test command \e{including} the
78\cw{buildrun -r} prefix.
79
80(The option names \cw{-w} and \cw{-r} are intended to imply that the
81first command is writing some kind of resource, such as a compiled
82program or data file, and that the second command intends to read that
83resource and hence needs the first command to have written it
84correctly.)
85
86\U OPTIONS
87
88You must specify one of \cw{-w} and \cw{-r}.
89
90\dt \cw{-w}
91
92\dd Runs \cw{buildrun} in write mode. You must provide a command line;
93\cw{buildrun -w} will run that command, and use the control directory
94to signal to any waiting \cw{buildrun -r} instances when it has
95completed successfully.
96
97\dt \cw{-r}
98
99\dd Runs \cw{buildrun} in read mode. If a command wrapped by
100\cw{buildrun -w} is currently in progress, or if the last such command
101failed, then \cw{buildrun -r} will wait until one succeeds before
102doing anything. However, if no \cw{buildrun -w} is currently running
103and the last one completed successfully, \cw{buildrun -r} will not
104wait at all.
105
106\lcont{
107
108If a command line is provided, \cw{buildrun -r} will run that command
109after it finishes waiting. If no command line is provided,
110\cw{buildrun -r} will simply return success when it finishes waiting.
111
112}
113
114\U ARGUMENTS
115
116\dt \e{control-directory}
117
118\dd This argument is mandatory in both \cw{-w} and \cw{-r} modes. It
119must give the pathname of a directory which the two instances of
120\cw{buildrun} will use to communicate with each other.
121
122\lcont{
123
124You need not create the control directory; \cw{buildrun -w} will
125create it the first time it runs. It will also be deleted every time
126\cw{buildrun -w}'s command completes successfully, because that's how
127success is communicated to \cw{buildrun -r}. (A side effect of that is
128that if \cw{buildrun -r} is run before \e{ever} running \cw{buildrun
129-w}, it will behave as if there had been a successful \cw{-w} run.)
130
131The control directory should not be on a network-mounted filesystem,
132since network filesystems sometimes diverge from the normal Unix
133behaviour which \cw{buildrun} relies on. Using a directory in
134\cw{/tmp} is recommended.
135
136Of course, instances of \cw{buildrun} using different control
137directories will be completely independent of each other. So you can
138simultaneously run two or more pairs of commands each linked by their
f17839e1 139own pair of \cw{buildrun}s, and as long as each pair has a separate
31f0fd76 140control directory, they won't interfere with each other.
141
142}
143
144\dt \e{command} (and optional arguments)
145
146\dd The first word on \cw{buildrun}'s command line which is not an
147option or the control directory name will be treated as a command to
148be run by \cw{buildrun}, and anything following that word will be
149treated as arguments to that command. The command will be run directly
150using the \cw{execvp}(\e{3}) function, so shell syntax (pipes,
151redirections etc) is not supported. If you need your command to
152contain things like that, you can achieve it by explicitly invoking a
153shell, e.g.
154
155\lcont{
156
f17839e1 157\c buildrun -w /tmp/ctldir sh -c '(cmd1; cmd2 | cmd3) > outfile'
158\e bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
31f0fd76 159
160In \cw{buildrun -r} mode, an alternative to doing that is simply not
161to provide a command at all, and instead tell your shell to run a
162complex command \e{after} \cw{buildrun}, e.g.
163
f17839e1 164\c buildrun -r /tmp/ctldir && (cmd1; cmd2 | cmd3) > outfile
165\e bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
31f0fd76 166
167(This alternative is not available with \cw{buildrun -w}, since that
168has to run its command as a subprocess so that it can wait for it to
169finish and see whether it worked.)
170
171}
172
173\U LICENCE
174
175\cw{buildrun} is free software, distributed under the MIT licence.
176Type \cw{buildrun --licence} to see the full licence text.
177
178\versionid $Id$