Skip to content

5. Rules ​

A project has chores besides building: running the program, packing a release, generating the documentation. A rule is a named list of shell commands in the fobos, run by fobis rule --execute NAME:

ini
[rule-smoke]
help = The last line of the program's output
rule = ./build/release/integrate | tail -n 1

[rule-errors]
help = The table of errors, from the release build
rule = fobis run --mode release

[rule-dist]
help     = A source archive
rule_rm  = rm -f quad-0.1.0.tar.gz
rule_tar = tar czf quad-0.1.0.tar.gz fobos src test

Every key starting with rule is a command, run in the order written (the keys of a section must differ: rule_rm, rule_tar).

console
$ fobis rule --list
The fobos file defines the following rules:
  - "smoke" The last line of the program's output
       Command => ./build/release/integrate | tail -n 1
  - "errors" The table of errors, from the release build
       Command => fobis run --mode release
  - "dist" A source archive
       Command => rm -f quad-0.1.0.tar.gz
       Command => tar czf quad-0.1.0.tar.gz fobos src test
console
$ fobis rule --execute dist && tar tzf quad-0.1.0.tar.gz | sort
Executing rule "dist"
   Command => rm -f quad-0.1.0.tar.gz
   Command => tar czf quad-0.1.0.tar.gz fobos src test
fobos
src/
src/integrands.F90
src/integrate.F90
src/integrate_mpi.F90
src/quad_rules.F90
src/sweep.F90
test/
test/polynomials.F90
test/test_exactness.F90
test/test_order.F90

Hooks ​

A mode can run rules before and after its build: pre_build = NAMES, post_build = NAMES (after a successful build only). The release mode now runs smoke, so every release build ends by running the program:

ini
[release]
help          = Optimised
template      = template-gnu
build_profile = release
cflags        = -c
post_build    = smoke
console
$ fobis build --mode release --quiet

Building src/integrate.F90
Compiling src/quad_rules.F90 serially
Compiling src/integrands.F90 serially
Compiling src/integrate.F90 serially
Linking build/release/integrate
Target src/integrate.F90 has been successfully built
Executing rule "smoke"
   Command => ./build/release/integrate | tail -n 1
Simpson, 64 intervals: 2.0000000645300013

Intrinsic rules ​

FoBiS has a few rules of its own: --ford PROJECT builds the documentation with FORD, --gcov-analyzer summarises gcov files, and three questions about the compiler:

console
$ fobis rule --is-float128-kind-supported
Building build/debug/float128_kind_introspection.f90
Compiling build/debug/float128_kind_introspection.f90 serially
Linking build/debug/float128_kind_introspection
Target build/debug/float128_kind_introspection.f90 has been successfully built
Compiler 'gnu' support float128 kind: True

(--is-ascii-kind-supported and --is-ucs4-kind-supported ask about character kinds.)

Parallel compiling ​

Not a rule, but a chore that grows with the project: --jobs N compiles independent files at the same time. Files of the same level of the dependency tree are compiled together:

console
$ fobis build --mode release --force-compile --jobs 4 --quiet

Building src/integrate.F90
Compiling .fobis_deps/penf/src/lib/penf_global_parameters_variables.F90 serially
Compiling .fobis_deps/penf/src/lib/penf_b_size.F90 serially
Compiling .fobis_deps/penf/src/lib/penf_stringify.F90 serially
Compiling src/quad_rules.F90 .fobis_deps/penf/src/lib/penf_allocatable_memory.F90 using 2 concurrent processes
Compiling src/integrands.F90 .fobis_deps/penf/src/lib/penf.F90 using 2 concurrent processes
Compiling src/integrate.F90 serially
Linking build/release/integrate
Target src/integrate.F90 has been successfully built
Executing rule "smoke"
   Command => ./build/release/integrate | tail -n 1
Simpson, 64 intervals: 2.0000000645300013

What you learned

[rule-NAME], fobis rule --list and --execute, pre_build/post_build hooks, intrinsic rules, --jobs. Reference: rules, intrinsic rules, rule.

Next: 6. Continuous integration.