Wed Feb 2 10:25:37 2011 UTC ()
Document that patch file names should contain the path and file name.
E.g. for lib/bar/foo_bar.c the patch file name should be
patch-lib_bar_foo__bar.c
The previous convention is still mentioned.

While here, give more good hints about how to handle patches:
* always add comments
* when sent upstream, note bug reporting URL


(wiz)
diff -r1.41 -r1.42 pkgsrc/doc/guide/files/components.xml

cvs diff -r1.41 -r1.42 pkgsrc/doc/guide/files/components.xml (expand / switch to unified diff)

--- pkgsrc/doc/guide/files/components.xml 2010/06/07 16:06:58 1.41
+++ pkgsrc/doc/guide/files/components.xml 2011/02/02 10:25:36 1.42
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1<!-- $NetBSD: components.xml,v 1.41 2010/06/07 16:06:58 tnn Exp $ --> 1<!-- $NetBSD: components.xml,v 1.42 2011/02/02 10:25:36 wiz Exp $ -->
2 2
3<chapter id="components"> <?dbhtml filename="components.html"?> 3<chapter id="components"> <?dbhtml filename="components.html"?>
4<title>Package components - files, directories and contents</title> 4<title>Package components - files, directories and contents</title>
5 5
6<para>Whenever you're preparing a package, there are a number of 6<para>Whenever you're preparing a package, there are a number of
7files involved which are described in the following 7files involved which are described in the following
8sections.</para> 8sections.</para>
9 9
10<sect1 id="components.Makefile"> 10<sect1 id="components.Makefile">
11 <title><filename>Makefile</filename></title> 11 <title><filename>Makefile</filename></title>
12 12
13 <para>Building, installation and creation of a binary package are all 13 <para>Building, installation and creation of a binary package are all
14 controlled by the package's <filename>Makefile</filename>. 14 controlled by the package's <filename>Makefile</filename>.
@@ -218,104 +218,105 @@ converters games mbone  @@ -218,104 +218,105 @@ converters games mbone
218 218
219<sect1 id="components.patches"> 219<sect1 id="components.patches">
220 <title>patches/*</title> 220 <title>patches/*</title>
221 221
222 <para>Many packages still don't work out-of-the box on the various 222 <para>Many packages still don't work out-of-the box on the various
223 platforms that are supported by pkgsrc. Therefore, a number of custom 223 platforms that are supported by pkgsrc. Therefore, a number of custom
224 patch files are needed to make the package work. These patch files are 224 patch files are needed to make the package work. These patch files are
225 found in the <filename>patches/</filename> directory.</para> 225 found in the <filename>patches/</filename> directory.</para>
226 226
227 <para>In the <emphasis>patch</emphasis> phase, these patches are 227 <para>In the <emphasis>patch</emphasis> phase, these patches are
228 applied to the files in <varname>WRKSRC</varname> directory after 228 applied to the files in <varname>WRKSRC</varname> directory after
229 extracting them, in <ulink 229 extracting them, in <ulink
230 url="http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13_03">alphabetic 230 url="http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13_03">alphabetic
231 order</ulink>, so <filename>patch-aa</filename> is applied before 231 order</ulink>.</para>
232 <filename>patch-ab</filename>, etc.</para> 
233 232
234<sect2 id="components.patch.structure"> 233<sect2 id="components.patch.structure">
235<title>Structure of a single patch file</title> 234<title>Structure of a single patch file</title>
236 235
237 <para>The <filename>patch-*</filename> files should be in 236 <para>The <filename>patch-*</filename> files should be in
238 <command>diff -bu</command> format, and apply without a fuzz to avoid 237 <command>diff -bu</command> format, and apply without a fuzz to avoid
239 problems. (To force patches to apply with fuzz you can set 238 problems. (To force patches to apply with fuzz you can set
240 <varname>PATCH_FUZZ_FACTOR=-F2</varname>). Furthermore, each patch 239 <varname>PATCH_FUZZ_FACTOR=-F2</varname>). Furthermore, each patch
241 should contain only changes for a single file, and no file should be 240 should contain only changes for a single file, and no file should be
242 patched by more than one patch file. This helps to keep future 241 patched by more than one patch file. This helps to keep future
243 modifications simple.</para> 242 modifications simple.</para>
244 243
245 <para>Each patch file is structured as follows: In the first line, 244 <para>Each patch file is structured as follows: In the first line,
246 there is the RCS Id of the patch itself. The second line should be 245 there is the RCS Id of the patch itself. The second line should be
247 empty for aesthetic reasons. After that, there should be a comment for 246 empty for aesthetic reasons. After that, there should be a comment for
248 each change that the patch does. There are a number of standard 247 each change that the patch does. There are a number of standard
249 cases:</para> 248 cases:</para>
250 249
251 <itemizedlist> 250 <itemizedlist>
252 251
253 <listitem><para>Patches that replace the <literal>==</literal> 
254 operator for &man.test.1; with <literal>=</literal> in shell scripts 
255 are so common that they don't need a comment at all.</para></listitem> 
256 
257 <listitem><para>Patches for commonly known vulnerabilities should 252 <listitem><para>Patches for commonly known vulnerabilities should
258 mention the vulnerability ID (CAN, CVE).</para></listitem> 253 mention the vulnerability ID (CAN, CVE).</para></listitem>
259 254
260 <listitem><para>Patches that change source code should mention the 255 <listitem><para>Patches that change source code should mention the
261 platform and other environment (for example, the compiler) that the 256 platform and other environment (for example, the compiler) that the
262 patch is needed for.</para></listitem> 257 patch is needed for.</para></listitem>
263 258
264 </itemizedlist> 259 </itemizedlist>
265 260
266 <para>In all other cases, the patch should be commented so that any 261 <para>In all, the patch should be commented so that any
267 developer who knows the code of the application can make some use of 262 developer who knows the code of the application can make some use of
268 the patch. Special care should be taken for the upstream developers, 263 the patch. Special care should be taken for the upstream developers,
269 since we generally want that they accept our patches, so we have less 264 since we generally want that they accept our patches, so we have less
270 work in the future.</para> 265 work in the future.</para>
271 266
272</sect2> 267</sect2>
273<sect2 id="components.patches.caveats"> 268<sect2 id="components.patches.caveats">
274<title>Creating patch files</title> 269<title>Creating patch files</title>
275 270
276 <para>One important thing to mention is to pay attention that no RCS 271 <para>One important thing to mention is to pay attention that no RCS
277 IDs get stored in the patch files, as these will cause problems when 272 IDs get stored in the patch files, as these will cause problems when
278 later checked into the &os; CVS tree. Use the 273 later checked into the &os; CVS tree. Use the
279 <command>pkgdiff</command> command from the <filename 274 <command>pkgdiff</command> command from the <filename
280 role="pkg">pkgtools/pkgdiff</filename> package to avoid these 275 role="pkg">pkgtools/pkgdiff</filename> package to avoid these
281 problems.</para> 276 problems.</para>
282 277
283 <para>For even more automation, we recommend using 278 <para>For even more automation, we recommend using
284 <command>mkpatches</command> from the same package to make a 279 <command>mkpatches</command> from the same package to make a
285 whole set of patches. You just have to backup files before you 280 whole set of patches. You just have to backup files before you
286 edit them to <filename>filename.orig</filename>, e.g. with 281 edit them to <filename>filename.orig</filename>, e.g. with
287 <command>cp -p filename filename.orig</command> or, easier, by 282 <command>cp -p filename filename.orig</command> or, easier, by
288 using <command>pkgvi</command> again from the same package. If 283 using <command>pkgvi</command> again from the same package. If
289 you upgrade a package this way, you can easily compare the new 284 you upgrade a package this way, you can easily compare the new
290 set of patches with the previously existing one with 285 set of patches with the previously existing one with
291 <command>patchdiff</command>. Copy the patches you want to use 286 <command>patchdiff</command>. The files in <filename>patches</filename>
292 or update from the <filename>work/.newpatches</filename> 287 are replaced by new files, so carefully check if you want to take all
293 directory to <filename>patches/</filename>.</para> 288 the changes.</para>
294 289
295 <para>When you have finished a package, remember to generate 290 <para>When you have finished a package, remember to generate
296 the checksums for the patch files by using the <command>make 291 the checksums for the patch files by using the <command>make
297 makepatchsum</command> command, see <xref 292 makepatchsum</command> command, see <xref
298 linkend="components.distinfo"/>.</para> 293 linkend="components.distinfo"/>.</para>
299 294
300 <para>When adding a patch that corrects a problem in the 295 <para>When adding a patch that corrects a problem in the
301 distfile (rather than e.g. enforcing pkgsrc's view of where 296 distfile (rather than e.g. enforcing pkgsrc's view of where
302 man pages should go), send the patch as a bug report to the 297 man pages should go), send the patch as a bug report to the
303 maintainer. This benefits non-pkgsrc users of the package, 298 maintainer. This benefits non-pkgsrc users of the package,
304 and usually makes it possible to remove the patch in future 299 and usually makes it possible to remove the patch in future
305 version.</para> 300 version.</para>
306 301
307 <para>The file names of the patch files are usually of the form 302 <para>The file names of the patch files are usually of the form
308 <filename>patch-<replaceable>[a-z][a-z]</replaceable></filename>.</para> 303 <filename>patch-<replaceable>path_to_file__with__underscores.c</replaceable></filename>.
 304 Many packages still use the previous convention
 305 <filename>patch-<replaceable>[a-z][a-z]</replaceable></filename>,
 306 but new patches should be of the form containing the filename.
 307 <command>mkpatches</command> included in <filename
 308 role="pkg">pkgtools/pkgdiff</filename> takes care of the name
 309 automatically.</para>
309 310
310</sect2> 311</sect2>
311<sect2 id="components.patches.sources"> 312<sect2 id="components.patches.sources">
312<title>Sources where the patch files come from</title> 313<title>Sources where the patch files come from</title>
313 314
314 <para>If you want to share patches between multiple packages 315 <para>If you want to share patches between multiple packages
315 in pkgsrc, e.g. because they use the same distfiles, set 316 in pkgsrc, e.g. because they use the same distfiles, set
316 <varname>PATCHDIR</varname> to the path where the patch files 317 <varname>PATCHDIR</varname> to the path where the patch files
317 can be found, e.g.:</para> 318 can be found, e.g.:</para>
318<programlisting> 319<programlisting>
319PATCHDIR= ${.CURDIR}/../xemacs/patches 320PATCHDIR= ${.CURDIR}/../xemacs/patches
320</programlisting> 321</programlisting>
321 322
@@ -473,26 +474,29 @@ monitor_file(...) @@ -473,26 +474,29 @@ monitor_file(...)
473 and to ensure that future versions can be built out-of-the box on 474 and to ensure that future versions can be built out-of-the box on
474 NetBSD. Furthermore, any user that gets newer distfiles will get 475 NetBSD. Furthermore, any user that gets newer distfiles will get
475 the fixes straight from the packaged code.</para> 476 the fixes straight from the packaged code.</para>
476 477
477 <para>This generally involves cleaning up the patches 478 <para>This generally involves cleaning up the patches
478 (because sometimes the patches that are 479 (because sometimes the patches that are
479 added to pkgsrc are quick hacks), filling bug reports in the 480 added to pkgsrc are quick hacks), filling bug reports in the
480 appropriate trackers for the projects and working with the 481 appropriate trackers for the projects and working with the
481 mainstream authors to accept your changes. It is 482 mainstream authors to accept your changes. It is
482 <emphasis>extremely important</emphasis> that you do it so that 483 <emphasis>extremely important</emphasis> that you do it so that
483 the packages in pkgsrc are kept simple and thus further changes 484 the packages in pkgsrc are kept simple and thus further changes
484 can be done without much hassle.</para> 485 can be done without much hassle.</para>
485 486
 487 <para>When you have done this, please add a URL to the upstream
 488 bug report to the patch comment.</para>
 489
486 <para>Support the idea of free software!</para> 490 <para>Support the idea of free software!</para>
487 491
488 </sect2> 492 </sect2>
489 493
490 </sect1> 494 </sect1>
491 495
492 <sect1 id="other-mandatory-files"> 496 <sect1 id="other-mandatory-files">
493 <title>Other mandatory files</title> 497 <title>Other mandatory files</title>
494 498
495 <variablelist> 499 <variablelist>
496 <varlistentry> 500 <varlistentry>
497 <term><filename>DESCR</filename></term> 501 <term><filename>DESCR</filename></term>
498 502