annotate bitten/build/ctools.py @ 909:2c82cf261d9e

Typo in `ctools.configure` handling of `prefix` argument. Fixes #671, thanks to Wang Diancheng.
author osimons
date Mon, 09 May 2011 21:26:52 +0000
parents 7c80375d4817
children
rev   line source
379
0df178e07fdb Use UTF-8 as encoding of source files.
cmlenz
parents: 313
diff changeset
1 # -*- coding: utf-8 -*-
5
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
2 #
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 379
diff changeset
3 # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
832
7c80375d4817 Updated copyright to 2010.
osimons
parents: 677
diff changeset
4 # Copyright (C) 2007-2010 Edgewall Software
163
634be6cbb808 Flip the switch: Bitten is now BSD-licensed.
cmlenz
parents: 150
diff changeset
5 # All rights reserved.
5
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
6 #
163
634be6cbb808 Flip the switch: Bitten is now BSD-licensed.
cmlenz
parents: 150
diff changeset
7 # This software is licensed as described in the file COPYING, which
634be6cbb808 Flip the switch: Bitten is now BSD-licensed.
cmlenz
parents: 150
diff changeset
8 # you should have received as part of this distribution. The terms
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 379
diff changeset
9 # are also available at http://bitten.edgewall.org/wiki/License.
5
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
10
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
11 """Recipe commands for build tasks commonly used for C/C++ projects."""
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
12
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 105
diff changeset
13 import logging
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
14 import re
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
15 import os
605
c94481bc4646 0.6dev: Reverting [677] as many of these paths are also used for URLs, and hadn't considered this change enough. No major point in changing code that already works well, so simply reverting seems the best idea...
osimons
parents: 603
diff changeset
16 import posixpath
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
17 import shlex
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 105
diff changeset
18
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
19 from bitten.build import CommandLine, FileSet
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 105
diff changeset
20 from bitten.util import xmlio
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents:
diff changeset
21
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 105
diff changeset
22 log = logging.getLogger('bitten.build.ctools')
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 105
diff changeset
23
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
24 __docformat__ = 'restructuredtext en'
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
25
507
1c4fbefeda3a Handle `with` being a reserved word in Python 2.5 - fixes #217 (patch by mgood)
dfraser
parents: 503
diff changeset
26 def configure(ctxt, file_='configure', enable=None, disable=None, with_=None,
526
6435da25eaae Add `prefix` parameter (see #134)
dfraser
parents: 507
diff changeset
27 without=None, cflags=None, cxxflags=None, prefix=None, **kw):
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
28 """Run a ``configure`` script.
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
29
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
30 :param ctxt: the build context
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
31 :type ctxt: `Context`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
32 :param file\_: name of the configure script
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
33 :param enable: names of the features to enable, seperated by spaces
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
34 :param disable: names of the features to disable, separated by spaces
677
639e5c466c96 0.6dev: Documentation fixes for all `build_doc` errors and warnings.
osimons
parents: 605
diff changeset
35 :param with\_: names of external packages to include
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
36 :param without: names of external packages to exclude
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
37 :param cflags: ``CFLAGS`` to pass to the configure script
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
38 :param cxxflags: ``CXXFLAGS`` to pass to the configure script
526
6435da25eaae Add `prefix` parameter (see #134)
dfraser
parents: 507
diff changeset
39 :param prefix: install prefix to pass to the configure script, will be postfixed by the machine name from the build
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
40 """
238
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
41 args = []
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
42 if enable:
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
43 args += ['--enable-%s' % feature for feature in enable.split()]
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
44 if disable:
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
45 args += ['--disable-%s' % feature for feature in disable.split()]
507
1c4fbefeda3a Handle `with` being a reserved word in Python 2.5 - fixes #217 (patch by mgood)
dfraser
parents: 503
diff changeset
46 # since 'with' is a reserved word in python, we need to handle the argument carefully
1c4fbefeda3a Handle `with` being a reserved word in Python 2.5 - fixes #217 (patch by mgood)
dfraser
parents: 503
diff changeset
47 with_ = kw.pop('with', with_)
1c4fbefeda3a Handle `with` being a reserved word in Python 2.5 - fixes #217 (patch by mgood)
dfraser
parents: 503
diff changeset
48 for key in kw:
1c4fbefeda3a Handle `with` being a reserved word in Python 2.5 - fixes #217 (patch by mgood)
dfraser
parents: 503
diff changeset
49 raise TypeError("configure() got an unexpected keyword argument '%s'" % key)
1c4fbefeda3a Handle `with` being a reserved word in Python 2.5 - fixes #217 (patch by mgood)
dfraser
parents: 503
diff changeset
50 if with_:
1c4fbefeda3a Handle `with` being a reserved word in Python 2.5 - fixes #217 (patch by mgood)
dfraser
parents: 503
diff changeset
51 for pkg in with_.split():
238
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
52 pkg_path = pkg + '.path'
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
53 if pkg_path in ctxt.config:
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
54 args.append('--with-%s=%s' % (pkg, ctxt.config[pkg_path]))
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
55 else:
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
56 args.append('--with-%s' % pkg)
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
57 if without:
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
58 args += ['--without-%s' % pkg for pkg in without.split()]
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
59 if cflags:
242
372d1de2e3ec * Fixes to the `<c:configure>` command added in [247]: Set current directory when invoking the script, and correctly pass `CFLAGS` and `CXXFLAGS`.
cmlenz
parents: 238
diff changeset
60 args.append('CFLAGS=%s' % cflags)
238
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
61 if cxxflags:
242
372d1de2e3ec * Fixes to the `<c:configure>` command added in [247]: Set current directory when invoking the script, and correctly pass `CFLAGS` and `CXXFLAGS`.
cmlenz
parents: 238
diff changeset
62 args.append('CXXFLAGS=%s' % cxxflags)
526
6435da25eaae Add `prefix` parameter (see #134)
dfraser
parents: 507
diff changeset
63 if prefix:
909
2c82cf261d9e Typo in `ctools.configure` handling of `prefix` argument.
osimons
parents: 832
diff changeset
64 args.append('--prefix=%s' % prefix)
238
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
65
258
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 242
diff changeset
66 from bitten.build import shtools
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 242
diff changeset
67 returncode = shtools.execute(ctxt, file_=file_, args=args)
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 242
diff changeset
68 if returncode != 0:
273
4b6abf75a930 Fix a couple of bad refs that crept in in [268].
cmlenz
parents: 269
diff changeset
69 ctxt.error('configure failed (%s)' % returncode)
238
832e64330c31 Add a `<c:configure>` recipe command for running configure scripts. Closes #57.
cmlenz
parents: 221
diff changeset
70
478
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
71 def autoreconf(ctxt, file_='configure', force=None, install=None, symlink=None,
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
72 warnings=None, prepend_include=None, include =None):
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
73 """Run the autotoll ``autoreconf``.
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
74
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
75 :param ctxt: the build context
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
76 :type ctxt: `Context`
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
77 :param force: consider all files obsolete
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
78 :param install: copy missing auxiliary files
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
79 :param symlink: install symbolic links instead of copies
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
80 :param warnings: report the warnings falling in CATEGORY
677
639e5c466c96 0.6dev: Documentation fixes for all `build_doc` errors and warnings.
osimons
parents: 605
diff changeset
81 :param prepend_include: prepend directories to search path
639e5c466c96 0.6dev: Documentation fixes for all `build_doc` errors and warnings.
osimons
parents: 605
diff changeset
82 :param include: append directories to search path
478
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
83
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
84 """
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
85 args = []
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
86 if install:
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
87 args.append('--install')
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
88 if symlink:
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
89 args.append('--symlink')
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
90 if force:
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
91 args.append('--force')
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
92 if warnings:
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
93 args.append('--warnings=%s' % warnings)
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
94
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
95 if include:
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
96 args += ['--include=%s' % inc for inc in include.split()]
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
97 if prepend_include:
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
98 args += ['--prepend-include=%s' % pinc for pinc in prepend_include.split()]
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
99
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
100 from bitten.build import shtools
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
101 returncode = shtools.execute(ctxt, 'autoreconf', args=args)
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
102 if returncode != 0:
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
103 ctxt.error('autoreconf failed (%s)' % returncode)
6718f9a5c1f1 Applying Thomas Mueller's patch for the autoreconf command. Closes #59
wbell
parents: 436
diff changeset
104
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
105 def make(ctxt, target=None, file_=None, keep_going=False, directory=None, jobs=None, args=None):
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
106 """Execute a Makefile target.
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
107
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
108 :param ctxt: the build context
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
109 :type ctxt: `Context`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
110 :param file\_: name of the Makefile
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
111 :param keep_going: whether make should keep going when errors are
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
112 encountered
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
113 :param directory: directory in which to build; defaults to project source directory
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
114 :param jobs: number of concurrent jobs to run
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
115 :param args: command-line arguments to pass to the script
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
116 """
294
cb9af0adb365 Allow configuration of the path to the make executable. See #66.
cmlenz
parents: 273
diff changeset
117 executable = ctxt.config.get_filepath('make.path') or 'make'
cb9af0adb365 Allow configuration of the path to the make executable. See #66.
cmlenz
parents: 273
diff changeset
118
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
119 if directory is None:
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
120 directory = ctxt.basedir
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
121
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
122 margs = ['--directory', directory]
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
123
146
affd91b4c6fb Add a `<python:exec>` recipe command so that things like Pylint can be executed without using a Makefile.
cmlenz
parents: 131
diff changeset
124 if file_:
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
125 margs += ['--file', ctxt.resolve(file_)]
60
055a6c666fa8 * Pass a {{{Context}}} object to recipe commands as the first argument. Currently this only has the basedir, but will be extended to also provide output recording etc.
cmlenz
parents: 57
diff changeset
126 if keep_going:
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
127 margs.append('--keep-going')
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 105
diff changeset
128 if target:
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
129 margs.append(target)
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
130 if jobs:
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
131 margs += ['--jobs', jobs]
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
132
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
133 if args:
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
134 if isinstance(args, basestring):
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
135 margs += shlex.split(args)
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 105
diff changeset
136
258
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 242
diff changeset
137 from bitten.build import shtools
487
fbd5bc3c2a48 At long last, applying patch supplied by Xavier Duret for #207. Closes #207. Thanks for the patch.
wbell
parents: 478
diff changeset
138 returncode = shtools.execute(ctxt, executable=executable, args=margs)
258
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 242
diff changeset
139 if returncode != 0:
273
4b6abf75a930 Fix a couple of bad refs that crept in in [268].
cmlenz
parents: 269
diff changeset
140 ctxt.error('make failed (%s)' % returncode)
269
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
141
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
142 def cppunit(ctxt, file_=None, srcdir=None):
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
143 """Collect CppUnit XML data.
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
144
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
145 :param ctxt: the build context
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
146 :type ctxt: `Context`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
147 :param file\_: path of the file containing the CppUnit results; may contain
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
148 globbing wildcards to match multiple files
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
149 :param srcdir: name of the directory containing the source files, used to
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
150 link the test results to the corresponding files
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
151 """
269
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
152 assert file_, 'Missing required attribute "file"'
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
153
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
154 try:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
155 fileobj = file(ctxt.resolve(file_), 'r')
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
156 try:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
157 total, failed = 0, 0
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
158 results = xmlio.Fragment()
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
159 for group in xmlio.parse(fileobj):
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
160 if group.name not in ('FailedTests', 'SuccessfulTests'):
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
161 continue
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
162 for child in group.children():
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
163 test = xmlio.Element('test')
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
164 name = child.children('Name').next().gettext()
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
165 if '::' in name:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
166 parts = name.split('::')
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
167 test.attr['fixture'] = '::'.join(parts[:-1])
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
168 name = parts[-1]
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
169 test.attr['name'] = name
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
170
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
171 for location in child.children('Location'):
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
172 for file_elem in location.children('File'):
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
173 filepath = file_elem.gettext()
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
174 if srcdir is not None:
605
c94481bc4646 0.6dev: Reverting [677] as many of these paths are also used for URLs, and hadn't considered this change enough. No major point in changing code that already works well, so simply reverting seems the best idea...
osimons
parents: 603
diff changeset
175 filepath = posixpath.join(srcdir, filepath)
269
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
176 test.attr['file'] = filepath
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
177 break
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
178 for line_elem in location.children('Line'):
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
179 test.attr['line'] = line_elem.gettext()
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
180 break
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
181 break
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
182
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
183 if child.name == 'FailedTest':
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
184 for message in child.children('Message'):
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
185 test.append(xmlio.Element('traceback')[
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
186 message.gettext()
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
187 ])
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
188 test.attr['status'] = 'failure'
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
189 failed += 1
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
190 else:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
191 test.attr['status'] = 'success'
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
192
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
193 results.append(test)
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
194 total += 1
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
195
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
196 if failed:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
197 ctxt.error('%d of %d test%s failed' % (failed, total,
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
198 total != 1 and 's' or ''))
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
199
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
200 ctxt.report('test', results)
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
201
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
202 finally:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
203 fileobj.close()
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
204
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
205 except IOError, e:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
206 log.warning('Error opening CppUnit results file (%s)', e)
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
207 except xmlio.ParseError, e:
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
208 print e
51580a463e3e Add `<c:cppunit>` recipe command, based on patch by Chandler Carruth and examples by Akos Maroy.
cmlenz
parents: 258
diff changeset
209 log.warning('Error parsing CppUnit results file (%s)', e)
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
210
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
211 def cunit (ctxt, file_=None, srcdir=None):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
212 """Collect CUnit XML data.
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
213
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
214 :param ctxt: the build context
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
215 :type ctxt: `Context`
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
216 :param file\_: path of the file containing the CUnit results; may contain
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
217 globbing wildcards to match multiple files
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
218 :param srcdir: name of the directory containing the source files, used to
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
219 link the test results to the corresponding files
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
220 """
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
221 assert file_, 'Missing required attribute "file"'
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
222
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
223 try:
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
224 fileobj = file(ctxt.resolve(file_), 'r')
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
225 try:
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
226 total, failed = 0, 0
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
227 results = xmlio.Fragment()
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
228 log_elem = xmlio.Fragment()
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
229 def info (msg):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
230 log.info (msg)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
231 log_elem.append (xmlio.Element ('message', level='info')[msg])
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
232 def warning (msg):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
233 log.warning (msg)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
234 log_elem.append (xmlio.Element ('message', level='warning')[msg])
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
235 def error (msg):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
236 log.error (msg)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
237 log_elem.append (xmlio.Element ('message', level='error')[msg])
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
238 for node in xmlio.parse(fileobj):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
239 if node.name != 'CUNIT_RESULT_LISTING':
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
240 continue
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
241 for suiteRun in node.children ('CUNIT_RUN_SUITE'):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
242 for suite in suiteRun.children():
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
243 if suite.name not in ('CUNIT_RUN_SUITE_SUCCESS', 'CUNIT_RUN_SUITE_FAILURE'):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
244 warning ("Unknown node: %s" % suite.name)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
245 continue
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
246 suiteName = suite.children ('SUITE_NAME').next().gettext()
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
247 info ("%s [%s]" % ("*" * (57 - len (suiteName)), suiteName))
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
248 for record in suite.children ('CUNIT_RUN_TEST_RECORD'):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
249 for result in record.children():
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
250 if result.name not in ('CUNIT_RUN_TEST_SUCCESS', 'CUNIT_RUN_TEST_FAILURE'):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
251 continue
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
252 testName = result.children ('TEST_NAME').next().gettext()
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
253 info ("Running %s..." % testName);
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
254 test = xmlio.Element('test')
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
255 test.attr['fixture'] = suiteName
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
256 test.attr['name'] = testName
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
257 if result.name == 'CUNIT_RUN_TEST_FAILURE':
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
258 error ("%s(%d): %s"
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
259 % (result.children ('FILE_NAME').next().gettext(),
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
260 int (result.children ('LINE_NUMBER').next().gettext()),
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
261 result.children ('CONDITION').next().gettext()))
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
262 test.attr['status'] = 'failure'
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
263 failed += 1
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
264 else:
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
265 test.attr['status'] = 'success'
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
266
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
267 results.append(test)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
268 total += 1
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
269
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
270 if failed:
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
271 ctxt.error('%d of %d test%s failed' % (failed, total,
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
272 total != 1 and 's' or ''))
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
273
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
274 ctxt.report('test', results)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
275 ctxt.log (log_elem)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
276
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
277 finally:
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
278 fileobj.close()
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
279
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
280 except IOError, e:
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
281 log.warning('Error opening CUnit results file (%s)', e)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
282 except xmlio.ParseError, e:
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
283 print e
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
284 log.warning('Error parsing CUnit results file (%s)', e)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
285
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
286 def gcov(ctxt, include=None, exclude=None, prefix=None, root=""):
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
287 """Run ``gcov`` to extract coverage data where available.
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
288
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
289 :param ctxt: the build context
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
290 :type ctxt: `Context`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
291 :param include: patterns of files and directories to include
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
292 :param exclude: patterns of files and directories that should be excluded
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
293 :param prefix: optional prefix name that is added to object files by the
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
294 build system
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
295 :param root: optional root path in which the build system puts the object
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
296 files
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 302
diff changeset
297 """
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
298 file_re = re.compile(r'^File (?:\'|\`)(?P<file>[^\']+)\'\s*$')
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
299 lines_re = re.compile(r'^Lines executed:(?P<cov>\d+\.\d+)\% of (?P<num>\d+)\s*$')
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
300
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
301 files = []
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
302 for filename in FileSet(ctxt.basedir, include, exclude):
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
303 if os.path.splitext(filename)[1] in ('.c', '.cpp', '.cc', '.cxx'):
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
304 files.append(filename)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
305
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
306 coverage = xmlio.Fragment()
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
307 log_elem = xmlio.Fragment()
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
308 def info (msg):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
309 log.info (msg)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
310 log_elem.append (xmlio.Element ('message', level='info')[msg])
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
311 def warning (msg):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
312 log.warning (msg)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
313 log_elem.append (xmlio.Element ('message', level='warning')[msg])
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
314 def error (msg):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
315 log.error (msg)
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
316 log_elem.append (xmlio.Element ('message', level='error')[msg])
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
317
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
318 for srcfile in files:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
319 # Determine the coverage for each source file by looking for a .gcno
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
320 # and .gcda pair
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
321 info ("Getting coverage info for %s" % srcfile)
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
322 filepath, filename = os.path.split(srcfile)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
323 stem = os.path.splitext(filename)[0]
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
324 if prefix is not None:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
325 stem = prefix + '-' + stem
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
326
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
327 objfile = os.path.join (root, filepath, stem + '.o')
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
328 if not os.path.isfile(ctxt.resolve(objfile)):
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
329 warning ('No object file found for %s at %s' % (srcfile, objfile))
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
330 continue
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
331 if not os.path.isfile (ctxt.resolve (os.path.join (root, filepath, stem + '.gcno'))):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
332 warning ('No .gcno file found for %s at %s' % (srcfile, os.path.join (root, filepath, stem + '.gcno')))
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
333 continue
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
334 if not os.path.isfile (ctxt.resolve (os.path.join (root, filepath, stem + '.gcda'))):
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
335 warning ('No .gcda file found for %s at %s' % (srcfile, os.path.join (root, filepath, stem + '.gcda')))
302
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
336 continue
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
337
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
338 num_lines, num_covered = 0, 0
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
339 skip_block = False
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
340 cmd = CommandLine('gcov', ['-b', '-n', '-o', objfile, srcfile],
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
341 cwd=ctxt.basedir)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
342 for out, err in cmd.execute():
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
343 if out == '': # catch blank lines, reset the block state...
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
344 skip_block = False
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
345 elif out and not skip_block:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
346 # Check for a file name
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
347 match = file_re.match(out)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
348 if match:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
349 if os.path.isabs(match.group('file')):
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
350 skip_block = True
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
351 continue
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
352 else:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
353 # check for a "Lines executed" message
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
354 match = lines_re.match(out)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
355 if match:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
356 lines = float(match.group('num'))
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
357 cov = float(match.group('cov'))
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
358 num_covered += int(lines * cov / 100)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
359 num_lines += int(lines)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
360 if cmd.returncode != 0:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
361 continue
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
362
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
363 module = xmlio.Element('coverage', name=os.path.basename(srcfile),
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
364 file=srcfile.replace(os.sep, '/'),
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
365 lines=num_lines, percentage=0)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
366 if num_lines:
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
367 percent = int(round(num_covered * 100 / num_lines))
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
368 module.attr['percentage'] = percent
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
369 coverage.append(module)
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
370
fe966b950424 * Add a `<c:gcov>` command based on patch by Chandler Carruth. Closes #72.
cmlenz
parents: 294
diff changeset
371 ctxt.report('coverage', coverage)
503
a7c795920c4a Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents: 487
diff changeset
372 ctxt.log (log_elem)
Copyright (C) 2012-2017 Edgewall Software