Targets
Details on what targets are and how to use them
Targets are the fundamental building block of bu. The are a group of dependent tasks with multiple options. The syntax is fundamentally similar to how make does things, and many make scripts will run in bu.
Your first target
Let’s look at the simplest target.
demo:
echo hello bu world 𝄽
17:06 I ● [<command line>:demo] "echo hello bu world 𝄽"
hello bu world 𝄽
17:06 I ● 0 [<command line>:demo]
As you can see bu executes the shell script and displays the output. A target definition looks like this.
<target name>: [target dependencies...] [?file dependencies] [!type] [>outfile] [<infile] [|pipe] [^watch]
<script body>
Note that the body must be indented, but unlike Make, tabs or spaces are fine.
Dependencies
All dependencies of a target must be met for it to run.
Target dependencies
A target can depend on another target by name.
t1:
echo I am depended on by demo
demo: t1
echo I depend on t1
17:06 I ● [<command line>:t1] "echo I am depended on by demo"
I am depended on by demo
17:06 I ● 0 [<command line>:t1]
17:06 I ● [<command line>:demo] "echo I depend on t1"
I depend on t1
17:06 I ● 0 [<command line>:demo]
File Dependencies
A target may explicitly depend on the existence of a file or directory.
make:
echo Blah > my_file.txt
demo: make ?my_file.txt
cat my_file.txt
rm my_file.txt
17:06 I ● [<command line>:make] "echo Blah > my_file.txt"
17:06 I ● 0 [<command line>:make]
17:06 I ● [<command line>:demo] "cat my_file.txt\nrm my_file.txt"
Blah
17:06 I ● 0 [<command line>:demo]
Web dependencies
A target can depend on a web page being present and returning 200. The page will be polled until it can be contacted.
demo: @example.com
echo example.com is up
17:06 I ● [<command line>:demo] "echo example.com is up"
example.com is up
17:06 I ● 0 [<command line>:demo]
Pipes
Targets can be piped into eachother.
count:
wc -c
hex:
wcalc -h
demo: | count | hex
echo piped
echo banana
17:06 I ● [<command line>:demo] "echo piped\necho banana" | "wc -c" | "wcalc -h"
= 0xd
17:06 I ● 0 | 0 | 0 [<command line>:demo]
Here the output of the pipe target is piped into the count target and then the
hex target. Of course, all dependencies will be first run.
Watches
Targets can be restarted based on watching a file for modification. This is probably only useful for long-running targets.
a_dep:
echo hello
demo: a_dep ^example.bu
sleep 0
17:06 I ● [<command line>:a_dep] "echo hello"
hello
17:06 I ● 0 [<command line>:a_dep]
17:06 I ● [<command line>:demo] "sleep 0"
17:06 I ● 0 [<command line>:demo]
Will restart the watch target every time example.bu file is modified. It
will handle stopping the running process.
Redirects
Target output can be redirected to a file. This is useful when using shells that don’t have redirection, like Python.
demo: >my_file.txt !py
print "Save me in a file"
17:06 I ● [<command line>:demo] "print \"Save me in a file\""
17:06 I ● 0 [<command line>:demo]
Similarly a file can be used for input on standard input.
make: >my_file.txt
print "Save me in a file"
demo: <my_file.txt !py
import sys
print sys.stdin.read()
17:06 I ● [<command line>:demo] "import sys\nprint sys.stdin.read()"
Save me in a file
17:06 I ● 0 [<command line>:demo]
Shell types
Currently only shell and python are supported. Shell (bash) is the default, so no type
is required to be passed explicitly. For a Python target, add the type as !py,
look:
demo: !py
print "hello bu world 𝄽"
17:06 I ● [<command line>:demo] "print \"hello bu world 𝄽\""
hello bu world 𝄽
17:06 I ● 0 [<command line>:demo]
Indentation and whitespace
Target bodies must be indented by any whitespace, tab or space. Indentation must be consistent for Python scripts since Python is sensitive to this.
demo: !py
for i in range(5):
print i
17:06 I ● [<command line>:demo] "for i in range(5):\nprint i"
File "<string>", line 2
print i
^
IndentationError: expected an indented block
17:06 E ● exit status 1 [<command line>:demo]