Jump to: | OMake Home • Guide Home • Guide (single-page) • Contents (short) • Contents (long) | |
Index: | All • Variables • Functions • Objects • Targets • Options |
Pervasives
defines the objects that are defined in all
programs. The following objects are defined.Object
object is the root object.
Every class is a subclass of Object
.$(o.object-length)
: the number of fields and methods in the object.
$(o.object-mem <var>)
: returns true
iff the <var>
is a field
or method of the object.
$(o.object-add <var>, <value>)
: adds the field to the object,
returning a new object.
$(o.object-find <var>)
: fetches the field or method from the object;
it is equivalent to $(o.<var>)
, but the variable can be non-constant.
$(o.object-map <fun>)
: maps a function over the object. The function
should take two arguments; the first is a field name, the second is the
value of that field. The result is a new object constructed from the
values returned by the function.
o.object-foreach
: the foreach
form is equivalent to map
,
but with altered syntax.
o.foreach(<var1>, <var2>) <body>For example, the following function prints all the fields of an object
o
.
PrintObject(o) = o.foreach(v, x) println($(v) = $(x))The
export
form is valid in a foreach
body. The following
function collects just the field names of an object.
FieldNames(o) = names = o.foreach(v, x) names += $(v) export return $(names)
Object
.Map
object is a dictionary from values to values. The <key>
values are restricted to simple values: integers, floating-point numbers,
strings, files, directories, and arrays of simple values.$(o.mem <key>)
: returns true
iff the <key>
is defined
in the map.
$(o.add <key>, <value>)
: adds the field to the map,
returning a new map.
$(o.find <key>)
: fetches the field from the map.
$(o.map <fun>)
: maps a function over the map. The function
should take two arguments; the first is a field name, the second is the
value of that field. The result is a new object constructed from the
values returned by the function.
o.foreach
: the foreach
form is equivalent to map
,
but with altered syntax.
o.foreach(<var1>, <var2>) <body>For example, the following function prints all the fields of an object
o
.
PrintObject(o) = o.foreach(v, x) println($(v) = $(x))The
export
form is valid in a foreach
body. The following
function collects just the field names of the map.
FieldNames(o) = names = o.foreach(v, x) names += $(v) export return $(names)
$|key|
(the number of pipe symbols |
is allowed to vary).
$|key 1| = value1 $||key1|key2|| = value2 # The key is key1|key2 X = $|key 1| # Define X to be the value of field $|key 1|The usual modifiers are also allowed. The expression
$`|key|
represents
lazy evaluation of the key, and $,|key|
is normal evaluation.Object
.Number
object is the parent object for integers
and floating-point numbers.
Number
.Int
object represents integer values.
Number
.Float
object represents floating-point numbers.
Object
.Sequence
object represents a generic object containing
sequential elements. It provides the following methods.
$(s.length)
: the number of elements in the sequence.
$(s.map <fun>)
: maps a function over the fields in the sequence.
The function should take one argument. The result is a new sequence
constructed from the values returned by the function.
s.foreach
: the foreach
form is equivalent to map
,
but with altered syntax.
s.foreach(<var>) <body>For example, the following function prints all the elements of the sequence.
PrintSequence(s) = s.foreach(x) println(Elem = $(x))The
export
form is valid in a foreach
body. The following
function counts the number of zeros in the sequence.
Zeros(s) = count = $(int 0) s.foreach(v) if $(equal $(v), 0) count = $(add $(count), 1) export export return $(count)
Sequence
.Array
is a random-access sequence.
It provides the following additional methods.
$(s.nth <i>)
: returns element i
of the sequence.
$(s.rev <i>)
: returns the reversed sequence.
Array
.
Object
.Fun
object provides the following methods.
$(f.arity)
: the arity if the function.
Object
.Rule
object represents a build rule.
It does not currently have any methods.
Object
.Target
object contains information collected for
a specific target file.
target
: the target file.
effects
: the files that may be modified by a
side-effect when this target is built.
scanner_deps
: static dependencies that must be built
before this target can be scanned.
static-deps
: statically-defined build dependencies
of this target.
build-deps
: all the build dependencies for the target,
including static and scanned dependencies.
build-values
: all the value dependencies associated
with the build.
build-commands
: the commands to build the target.
output-file
: if output was diverted to a file,
with one of the --output-*
options A,
this field names that file. Otherwise it is false
.
find(file)
: returns a Target object for the given file.
Raises a RuntimeException
if the specified target is
not part of the project.
find-optional(file)
: returns a Target
object
for the given file, or false
if the file is not
part of the project.
Target
object for a node will
contain different values in different contexts. The easiest way
to make sure that the Target
information is complete is
to compute it within a rule body, where the rule depends on
the target file, or the dependencies of the target file.
Object
.Node
object is the parent object for files and directories.
It supports the following operations.
$(node.stat)
: returns a stat
object for the file. If the
file is a symbolic link, the stat
information is for the destination of
the link, not the link itself.$(node.lstat)
: returns a stat
object for the file or symbolic link.
$(node.unlink)
: removes the file.
$(node.rename <file>)
: renames the file.
$(node.link <file>)
: creates a hard link <dst>
to this file.
$(node.symlink <file>)
: create a symbolic link <dst>
to this file.
$(node.chmod <perm>)
: change the permission of this file.
$(node.chown <uid>, <gid>)
: change the owner and group id of this file.
Node
.Node
.Dir
object represents the name of a directory.
Object
.Channel
is a generic IO channel.
It provides the following methods.
$(o.close)
: close the channel.
Channel
.InChannel
is an input channel. The variable stdin
is the
standard input channel.$(InChannel.fopen <file>)
: open a new input channel.
$(InChannel.of-string <string>)
: open a new input channel,
using a string as input.
Channel
.OutChannel
is an output channel. The variables stdout
and stderr
are the standard output and error channels.$(OutChannel.fopen <file>)
: open a new output channel.
$(OutChannel.string)
: open a new output channel,
writing to a string.
$(OutChannel.to-string)
: get the current string of
output, for an output channel created as OutChannel.open-string
.
$(OutChannel.append <file>)
: opens a new output channel,
appending to the file.
$(c.flush)
: flush the output channel.
$(c.print <string>)
: print a string to the channel.
$(c.println <string>)
: print a string to the channel,
followed by a line terminator.
Location
.Location
object represents a location in a file.
Position
.Position
object represents a stack trace.
Object
.Exception
object is used as the base object for exceptions.
It has no fields.
Exception
.RuntimeException
object represents an exception from the
runtime system. It has the following fields.
position
: a string representing the location where the
exception was raised.
message
: a string containing the exception message.
Exception
.UnbuildableException
object should be used to signal that a target
is not buildable. It will be caught by functions such as
target-exists
9.3.1.
This exception has the following fields:
target
: indicates which target is not buildable.
message
: a string containing the exception message.
Object
.Shell
object contains the collection of builtin functions
available as shell commands.echo
echo
function prints its arguments to the standard output channel.
jobs
jobs
method prints the status of currently running commands.
cd
cd
function changes the current directory.
Note that the current directory follows the usual scoping
rules. For example, the following program lists the
files in the foo
directory, but the current
directory is not changed.
section echo Listing files in the foo directory... cd foo ls echo Listing files in the current directory... ls
bg
bg
method places a job in the background.
The job is resumed if it has been suspended.
fg
fg
method brings a job to the foreground.
The job is resumed if it has been suspended.
stop
stop
method suspends a running job.
wait
wait
function waits for a running job to terminate.
It is not possible to wait for a suspended job.wait
is interrupted, the job continues to run in the background.
kill
kill
function signal a job.kill [signal] <pid...>
.exit
exit
function terminates the current session.
which
, where
rehash
ln-or-cp
src dstln-or-cp
would first
delete the dst file (unless it is a directory), if it exists. Next it would try to create
a symbolic link dst poiting to src (it will make all the necessary adjustmnents of
relative paths). If symbolic link can not be created (e.g. the OS or the filesystem does
not support symbolic links), it will try to create a hard link. If that fails too, it will try
to forcibly copy src to dst.
history
digest
cmd.exe
.
The following functions are defined on Win32 and only on Win32.
On other systems, it is expected that these programs already
exist.
grep
grep [-q] [-n] pattern files...The
grep
function calls the omake
grep
function.
cp
, mv
, cat
, rm
, mkdir
, chmod
,
test
, find
.
If you really want to use the standard system versions of these
commands, set the USE_SYSTEM_COMMANDS
as one of the first
definitions in your OMakeroot
file.
mkdir
mkdir [-m <mode>] [-p] filesThe
mkdir
function is used to create directories.
The -verb+-m+ option can be used to specify the permission
mode of the created directory. If the -p
option
is specified, the full path is created.
cp
mv
cp [-f] [-i] [-v] src dst cp [-f] [-i] [-v] files dst mv [-f] [-i] [-v] src dst mv [-f] [-i] [-v] files dstThe
cp
function copies a src
file to
a dst
file, overwriting it if it already exists.
If more than one source file is specified, the final file
must be a directory, and the source files are copied
into the directory.
rm
rm [-f] [-i] [-v] [-r] files rmdir [-f] [-i] [-v] [-r] dirsThe
rm
function removes a set of files.
No warnings are issued if the files do not exist, or if
they cannot be removed.chmod
chmod [-r] [-v] [-f] mode filesThe
chmod
function changes the permissions on a set of
files or directories. This function does nothing on Win32.
The mode
may be specified as an octal number,
or in symbolic form [ugoa]*[
-=][rwxXstugo]+.
See the man page for chmod
for details.cat
cat files...The
cat
function prints the contents of the files to stdout
test
test
expression[
expression +]+[ --help
[ --version
test
function (Section 9.7.1).find
find \emph{expression}See the documentation for the
find
function (Section 9.7.2).Jump to: | OMake Home • Guide Home • Guide (single-page) • Contents (short) • Contents (long) | |
Index: | All • Variables • Functions • Objects • Targets • Options |