3.6. Applying Commands to Packages of a Project

Some of the most powerful operations provided by prjm are the application of user defined actions to all packages of your project. This is done by the commands

  prjm -apply <action>
  prjm -ordapply <action>
The first form is used if the order of packages is irrelevant to your action, the second form uses the order implied by a topological sort of the import relation. (You can view this order with the command prjm -updatesequence, as mentioned above.) The designated action may be any sequence of commands that is understood by the somewhat minimalistic shell built into prjm. This shell knows about input and output redirection from and to files, and the operators && and ||. If you want something more sophisticated, you may specifiy the command interpreter that is to be used via the -shell option, for example -shell /usr/local/bin/perl.

Let's continue with a simple but useful example. The command

  prjm -m -k -nodep -apply "pkgvm -udiff"
utilizes the ComPact Version Control Manager to produce a unified context diff that describes the modifications in all packages that you have changed in your workspace.

A more elaborate example might be

  prjm -sh /bin/sh -k -apply "wc inc/*.h src/*.c"
which produces some statistics about the size of all the C header files and C source files in your project. (As a simple exercise, you might try to filter the output of this command through awk to sum up all the values :-)

If you are not interested in the output of actions applied to your packages, but rather want to apply them as predicates to select a number of packages, this can be easily achieved, too.

  prjm -selectby <cmd>
    prjm -ordselectby <cmd>
The exit code of the command is used in either case to determine if the package it is applied to will be part of the result list.

If you want to explicitly apply some of the actions defined in the backend configuration file (see Chapter 4 by their symbolic names, you can do this with the commands

  prjm -applyaction <symbolic name>
  prjm -orderedapplyaction <symbolic name>