rbm_templates.asc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. rbm_templates(7)
  2. ================
  3. NAME
  4. ----
  5. rbm_templates - A description of the rbm templates
  6. DESCRIPTION
  7. -----------
  8. All configuration options are actually templates. So you can use
  9. template directives in any of the option. There are a few exceptions
  10. however, for the options that are needed to process templates, so they
  11. can't be templated themself. The following options are not templated :
  12. - projects_dir
  13. If you want to make other options not templated, add them to the
  14. +notmpl+ config option, which is an array. All the other options are
  15. automatically processed as template.
  16. The template are made using perl Template Toolkit. You can read more
  17. about the syntax on the http://www.template-toolkit.org/[Template
  18. Toolkit website].
  19. From any template, it is possible to include other template files using
  20. the +INCLUDE+ directive. The template files are added to the directory
  21. +projects_dir/project+ where +projects_dir+ is the projects directory
  22. (the default is +projects+) and +project+ the name of the project. Other
  23. template files can be added in the directory +projects_dir/common+, to
  24. be included from any of the other templates.
  25. There are different template files :
  26. By default, the following template files are used :
  27. - the rpm spec file template, named +project.spec+ (replacing +project+
  28. with the project's name). This is used when you use the +rpmspec+,
  29. +srpm+ +rpm+, or +build+ commands. This creates the +rpmspec+ option.
  30. If you don't want to use this file, just replace the +rpmspec+ option
  31. by something else.
  32. - the build script template, named +build+. This template is used to
  33. create a build script, that is executed when you use the +build+
  34. command. This creates the +build+ option.
  35. The following variables can be used in the template files :
  36. config::
  37. contains all the configuration. You can view the content with
  38. `rbm showconf`.
  39. c::
  40. This variable is a function reference. Instead of accessing the
  41. +config+ variable directly, you can use the +c+ function which
  42. will look at the command line parameters, the project specific
  43. configuration then the global configuration and return the first
  44. defined one. The syntax to use this function is `c('option-name')`.
  45. Optionally it can take as a second argument a hash table
  46. containing options to override temporarily (in template processing).
  47. Additionally the 2nd argument can contain the following options :
  48. - 'no_tmpl' :
  49. set this to 1 if you want to disable template processing
  50. for this option lookup.
  51. - 'error_if_undef' :
  52. set this to 1 (for default error message) or a string
  53. containing an error message if you want to exit with an
  54. error when the selected option is undefined.
  55. - 'as_array' :
  56. if set to 1, then return all matching results as an
  57. array reference, instead of only the first one.
  58. pc::
  59. This variable is a function reference. It is the same as +c+,
  60. except that it takes a project name as its first argument. This
  61. is useful if you want to access the config value of an other
  62. project than the current one. The command line options are not
  63. used in this lookup. The current +target+ is used, unless an
  64. other +target+ option is defined in the options argument. The
  65. current project name is available to the requested option in
  66. the +origin_project+ option.
  67. project::
  68. The name of the project for which we are processing a template.
  69. p::
  70. The project's configuration. This is a shortcut for the value
  71. of `config.projects.$project`.
  72. dest_dir::
  73. The destination directory, where the resulting files will be
  74. stored at the end of the build. This is mainly useful in build
  75. script templates, and probably not useful in package template
  76. files.
  77. exit_error::
  78. A function that you can use to exit with an error. The first
  79. argument is an error message. The second argument is an optional
  80. exit code (default is 1).
  81. exec::
  82. A function taking a command line as argument, to be executed in
  83. the sources tree. The output of the command is returned, if the
  84. exit code was 0. If the argument starts with '#', then it is
  85. considered to be a script, which will be written to a temporary
  86. file and executed. The second argument of the exec function is
  87. an optional $options hash, used to override values of 'git_url',
  88. 'hg_url', 'fetch', 'git_hash' or 'hg_hash'.
  89. path::
  90. A function to return an absolute path. It takes a path as first
  91. argument. If the path is already an absolute path, then it
  92. returns the same thing. If the path is a relative path, it
  93. returns the path concatenated with +basedir+ which is the
  94. directory where the main configuration file is located.
  95. Optionally it can take a second argument to set an other value
  96. for the +basedir+.
  97. tmpl::
  98. A function taking a template text as argument, and returning it
  99. processed.
  100. shell_quote::
  101. A function to quote strings to use them as argument in command
  102. lines. This is the function from String::ShellQuote perl module.
  103. versioncmp::
  104. A function to compare two version numbers. It returns -1, 0, or
  105. 1 depending on whether the first argument is less than, equal
  106. to, or greater than the second argument. This is the function
  107. from the Sort::Versions perl module.
  108. sha256::
  109. A function returning the sha256 digest of its argument as an
  110. hexadecimal string.
  111. sha256file::
  112. A function returning the sha256 digest of a file as an hexadecimal
  113. string. If the file does not exist, an empty string is returned.
  114. fileparse::
  115. A function to parse a path. Returns an array containing the
  116. filename, and the directory path. This is the fileparse routine
  117. from File::Basename.
  118. ENV::
  119. A hash containing all the process environment variables.
  120. EXAMPLES
  121. --------
  122. You want to use the version number somewhere in a template for a rpm or
  123. debian package :
  124. ----
  125. Version: [% c('version') %]
  126. ----
  127. You want to exit with an error if the distribution option is undefined :
  128. ----
  129. %description
  130. This package is built for distribution [%
  131. c('distribution', { error_if_undef => 1 }) %]
  132. ----
  133. You know that the 'remote_ssh' option uses the 'ssh_host' option,
  134. and you want to change the value of 'ssh_host' just for the lookup of
  135. 'remote_ssh' in step 'deb_src'. You can temporarily override the
  136. 'ssh_host' option like this :
  137. ----
  138. ssh_host: some_hostname
  139. steps:
  140. deb_src:
  141. remote_exec: "[% c('remote_ssh',
  142. { ssh_host => 'some_other_hostname' }) %]"
  143. ----
  144. You want to be able to define the package revision number using a file
  145. in the sources tree of your software. In the 'config' file, you can use
  146. the 'exec' function like this :
  147. ----
  148. pkg_rel: "[% exec('cat package_revision_number.txt') %]"
  149. ----
  150. In your rpm spec file, you want to add a build require, but only for
  151. versions higher than 0.3, so you add this to your rpm spec template file :
  152. ----
  153. [% IF versioncmp(c('version'), '0.3') > 0 -%]
  154. BuildRequires: some_buildrequire
  155. [% END -%]
  156. ----
  157. SEE ALSO
  158. --------
  159. link:rbm.html[rbm(1)],
  160. link:rbm_config.html[rbm_config(7)]