Generate files replacing parts of it
This module allow to generate files using template. Each template files is split into three parts: an header, a body and a footer. We target at changing the body part. If target file already exists, we load the header and the footer from it. We merge the three parts and repalce the target files.
There are some safety limits:
The whole module is not exported.
Comment definition.
#
fn
| : OASISUnixPath.host_filename | ; | |||
#
comment
| : comment | ; | |||
#
header
| : line list | ; | |||
#
body
| : body | ; | |||
: line list | ; | ||||
#
perm
| : int | ; | |||
#
important
| : bool | ; | (* | Determine if should be kept in dynamic mode. | *) |
#
disable_oasis_section
| : bool | ; | (* | Determine if OASIS section comments and digest should be omitted. | *) |
template_make fn cmt header body footer
Create a template for which
target file is fn
.
template_of_string_list ~ctxt ~template ~pure fn cmt lst
Split the list
lst
into a header, body and footer, using comment cmt
to determine each
part. Set ~template
if this is an embedded template (i.e. not a file
loaded from disk). If ~disable_oasis_section
is set, then the list is
processed on the assumption that there is no header and footer. See
template_make for other options.
template_of_ml_file fn
Create an OCaml file template taking into account
subtleties, like line modifier. See template_make for other options.
(* | Create fn , fn is the target file, nothing exists before | *) | |
(* | Change (fn, bak) , bak is the backup file, an existing file
has been changed. | *) | |
#
| NoChange
| (* | Nothing done, the file doesn't need to be updated | *) |
Describe what has been done to generate a file out of a template.
Reset to pristine a generated file.
Generate a file using a template. Only the part between OASIS_START and
OASIS_STOP will be really replaced if the file exists. If the file doesn't
exist use the whole template. If ~remove
is true
, then an existing file
will be deleted iff the template body is []
and the header and footer of
the file match the template's (used by the -remove option for setup-clean).
Set of templates.
No generated template files with the given set of files with the OASIS section disabled.
Remove a generated template file.