Debian Codegraph @

HACKING

raw
1 Hacking on libvirt perl
2 =======================
3
4 The libvirt Perl release versions are tied directly to the libvirt C
5 library release versions. ie Sys::Virt 1.2.10 will require libvirt
6 version 1.2.10 or newer in order to build. We do not aim to support
7 conditional compilation against versions of libvirt that are older
8 than the version of Sys::Virt.
9
10
11 General changes for new APIs
12 ----------------------------
13
14 Additions to the libvirt C API will require changes to a minimum
15 of two parts of the Sys::Virt codebase.
16
17 - Virt.xs - this provides the C glue code to access the libvirt C
18 library APIs and constants from the Perl interpreter. As a general
19 rule, every new function and header file constant/enum requires an
20 addition to this file. The exceptions are functions that are only
21 provided for the benefit of language bindings and not intended for
22 use by application code. For example the reference counting APIs
23 don't need exposing to Perl applications
24
25 - lib/ - this directory contains the pure Perl part of the binding.
26 There are separate files for each core libvirt object type
27
28 - lib/Sys/Virt.pm - mapping for virConnectPtr
29 - lib/Sys/Virt/Domain.pm - mapping for virDomainPtr
30 - lib/Sys/Virt/Error.pm - mapping for virErrorPtr
31 - lib/Sys/Virt/Event.pm - mapping for virEventPtr
32 - lib/Sys/Virt/Interface.pm - mapping for virInterfacePtr
33 - lib/Sys/Virt/Network.pm - mapping for virNetworkPtr
34 - lib/Sys/Virt/NodeDevice.pm - mapping for virNodeDevicePtr
35 - lib/Sys/Virt/NWFilter.pm - mapping for virNWFilterPtr
36 - lib/Sys/Virt/Secret.pm - mapping for virSecretPtr
37 - lib/Sys/Virt/StoragePool.pm - mapping for virStoragePoolPtr
38 - lib/Sys/Virt/StorageVol.pm - mapping for virStorageVolPtr
39 - lib/Sys/Virt/Stream.pm - mapping for virStreamPtr
40
41 There is rarely a need to write Perl code in the .pm modules, as
42 the mapping in the Virt.xs file is usually sufficient. As such
43 the primary purpose of the .pm modules is to hold the POD inline
44 documentation. Every function and constants is required to have
45 full API documentation provided
46
47 There are a number of unit tests available in the t/ directory which
48 assist in creation of new APIs.
49
50 - t/010-pod-coverage.t - ensures that every Perl method and constant
51 has POD documentation present
52 - t/030-api-coverage.t - ensures that every C library method/constant
53 in the libvirt-api.xml file has corresponding code in the Virt.xs.
54 Certain functions can be blacklisted in t/030-api-coverage.t as not
55 needed mapping to Perl. This only runs if TEST_MAINTAINER=1 is set.
56 - t/*.t - the other files mostly do functional testing against the
57 test:///default API - if the new function has support in the test
58 driver, then suitable additions should be made
59
60 If use of the API is not obvious, it is often worth providing a small
61 example program in the examples/ directory. These examples are also
62 useful when adding APIs to ensure that they are operating correctly,
63 if it wasn't possible to unit test them with test:///default.
64
65 Every addition / change to the API must be documented in the Changes
66 file.
67
68
69 New API addition workflow
70 -------------------------
71
72 When the libvirt C library is changed, the following workflow is an
73 effective way to update the Perl binding.
74
75 - Build the libvirt C library
76
77 # cd $HOME/src/libvirt
78 # ./autogen.sh --system
79 # make
80
81 - Configure & build the Sys::Virt module to build against the just
82 built libvirt library
83
84 # cd $HOME/src/libvirt-perl
85 # ../libvirt/run perl Build.PL
86 # ../libvirt/run ./Build
87
88 - Run the test suite to identify which new functions/constants need
89 handling
90
91 # TEST_MAINTAINER=1 ../libvirt/run ./Build test
92
93 - For each missing item reported in the test suite...
94
95 - Edit Virt.xs to add the C binding
96 - Edit lib/*.pm to add the POD documentation (and occasionally Perl glue code)
97 - Edit Changes to document the addition
98 - Run the test suite (without maintainer mode) to verify POD docs
99 # ../libvirt/run make test
100 - Optionally add to one of the t/*.t test cases
101 - Optionally add demo to examples/
102 - Commit the changes to GIT
103
104
105 Understanding Virt.xs glue layer
106 --------------------------------
107
108 The Perl XS glue (Virt.xs) is a pretty bizarre language, that mostly
109 looks like C but is actually run through a Perl specific preprocessor
110 to turn it into real C code. Learning and understanding XS code well
111 is a really difficult task, but fortunately such knowledge is rarely
112 required in order to add new APIs to the Perl Sys::Virt code.
113
114 When adding constants just look for the REGISTER_CONSTANT() macro
115 at the end of Virt.xs. Make sure that the constant is registered against
116 the correct Sys::Virt::XXXX object namespace - look for the adjacent
117 'gv_stashpv' calls to see which namespace is currently in effect.
118
119 When adding methods, you must again make sure they are put in the
120 correct object namespace. For methods, look for the statements
121 that look like:
122
123 MODULE = Sys::Virt::NWFilter PACKAGE = Sys::Virt::NWFilter
124
125 these indicate the start of a namespace for the object in question.
126 When implementing the binding for a method, if not already familiar
127 with XS code, the best technique is to just do cut+paste programming.
128 Find an existing libvirt API call that has the same kind of API
129 signature as the new API. Then just copy the XS code for that method
130 and tweak the parameter names as needed.
131
132 Async event callbacks have a little bit of special handling too. The
133 callbacks are all implemented as static methods at the very top of
134 the Virt.XS file. Look for method names like _domain_event_pmsuspend_callback
135 and just copy the code for an existing callback method that has a similar
136 set of parameters to the new callback.
137
138 Once the callback is implemented look for the domain_event_register_any()
139 or network_event_register_any() methods and extend the switch() statement
140 so that it maps the event ID constant to your new callback.
141
142
143 Making new releases
144 -------------------
145
146 The Sys::Virt releases are hosted on the Perl project CPAN infrastructure
147 rather than libvirt.org
148
149 1. Build the new release of libvirt as an RPM and install it on the
150 local machine.
151
152 2. Set the release date in the Changes file and commit the change
153
154 3. Tag the release with a GPG signed tag using vX.Y.Z syntax for
155 the tag name
156
157 git tag -s -m 'Release 1.2.14' v1.2.14
158
159 4. Clone the repository or run 'git clean -x -f -d' to ensure a
160 100% pristine state
161
162 5. Run autobuild.sh to test the full test suite and generate local
163 RPMs. This results in Sys-Virt-1.2.14.tar.gz file being created
164
165 6. Take the src.rpm file that was just generated by autobuild.sh
166 and run a scratch build against Fedora rawhide
167
168 # cd $HOME/src/fedora/perl-Sys-Virt
169 # fedpkg scratch-build --srpm /path/to/src/rpm/file
170
171 7. Push the Changes commit and tag to GIT master
172
173 # git push
174 # git push origin v1.2.14
175
176 If there is a failure at any step then this must be corrected
177 as follows
178
179 a. Delete the signed release tag
180
181 git tag -d v1.2.14
182
183 b. Fix whatever the problem was and update the Changes file
184 if appropriate
185
186 c. Go to release process step 3 again.
187
188
189 Assuming the release has now been made, the Sys-Virt-1.2.14.tar.gz
190 file should be uploaded to CPAN using https://pause.cpan.org form.
191 The upload is currently done by Daniel Berrange (username DANBERR).
192
193 Now open the tree for the next release version by editing the files
194 lib/Sys/Virt.pm, README, Build.PL to update the version number
195 listed. Also edit Changes to add a placeholder entry for the new
196 release number. Run 'make test' to ensure Changes file is syntax
197 valid.