aboutsummaryrefslogtreecommitdiff
path: root/doc/dev/processor.rst
blob: 640f44cdddd17cc1200267d8735dae3e8edfdec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
.. _processors:

##########
Processors
##########

This page lists all built-in processor types along with descriptions of what they do and which options they take.

.. _process_touch:

*****
Touch
*****

The touch processor is used to create files (similar to ``touch``) or change the mode of existing files (similar to ``chmod``).

:Class: :any:`TouchProcess`
:Input: Content of new file.
:Output:
  The input file as-is, with the following exceptions:

  - If the input is empty, it will be set to an empty (but existent) file.
  - If the ``mode`` option is set, it will be used instead of the input mode.
:Options:
  .. code-block:: yaml

     - id: "touch"
       input: ProcessInputSpec(required=False)
       mode: int(required=False, default=<input mode>)

.. _process_cocci:

**********
Coccinelle
**********

The Coccinelle processor uses Coccinelle to apply patch(es) in the SmPL (Semantic Patch Language) format.

.. important::

   In order to use this processor, Coccinelle must be installed and ``spatch`` must be available in ``$PATH``.

:Class: :any:`CoccinelleProcess`
:Input: Coccinelle's SmPL input.
:Target: File content to apply patch to (current patchspec's target file by default).
:Output: The content of the target file after being processed by Coccinelle (not the diff returned by Coccinelle).
:Options:
  .. code-block:: yaml

     - id: "cocci"
       input: ProcessInputSpec(required=False)
       target: ProcessInputSpec(required=False)


.. _process_jinja:

**************
Jinja template
**************

The Jinja processor passes the input through the Jinja2 templating engine.

:Class: :any:`Jinja2Process`
:Input: Jinja template code.
:Output: The input after being processed by Jinja.
:Options:
  .. code-block:: yaml

     - id: "jinja"
       input: ProcessInputSpec(required=False)

.. note::

   Template variables are generated through the :any:`get_template_vars <Jinja2Process.get_template_vars>` method.
   This method returns an empty dict by default, and is meant to be implemented by implementing a custom class that derives from :any:`Jinja2Process` and registering it through the :ref:`configuration file <ptconfig>`.

.. _process_exe:

**********
Executable
**********

The executable processor passes its input to an executable and returns its standard output.

:Class: :any:`ExecProcess`
:Input: Input passed to the standard input of the command.
:Output: Any content written to the standard output by the executable.
:Options:
  .. code-block:: yaml

     - id: "exec"
       cmd: str() | list[str]()
       input: ProcessInputSpec(required=False)

  .. note::

     If the ``cmd`` option is a string, it is split **using shell syntax rules**.

.. _process_merge:

*****
Merge
*****

The merge processor merges the input with the target file, such that changes are combined with the target instead of replacing the target.

:Class: :any:`MergeProcess`
:Input: Content to merge (A).
:Target: Content to merge (B).
:Output: Merged changes.
:Options:
  .. code-block:: yaml

     - id: "merge"
       strategy: enum() # see below
       input: ProcessInputSpec(required=False)
       target: ProcessInputSpec(required=False)

==========
Strategies
==========

``ignore``
  Appends all lines from *input* to *target*, excluding any lines already present in *target*.