Skip to content

Commit fe3beb5

Browse files
committed
Merge branch 'hotfix/v1.8.2'
2 parents becda00 + 36cfcc8 commit fe3beb5

File tree

8 files changed

+124
-47
lines changed

8 files changed

+124
-47
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Changes
22
=======
33

4+
5+
Version 1.8.2
6+
-------------
7+
8+
1. ```xml_generator_configuration_t``` will no more try to find
9+
castxml or gccxml. You can use ```utils.find_xml_generator``` to help you
10+
finding the path to the xml generator, or set it manually.
11+
It is now mandatory to pass a valid ```xml_generator``` and
12+
```xml_generator_path``` to the configuration (#65).
13+
414
Version 1.8.1
515
-------------
616

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
# built documents.
5656
#
5757
# The short X.Y version.
58-
version = '1.8.1'
58+
version = '1.8.2'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '1.8.1'
60+
release = '1.8.2'
6161

6262
# The language for content autogenerated by Sphinx. Refer to documentation
6363
# for a list of supported languages.

pygccxml/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
# TODO:
4141
# 1. Add "explicit" property for constructors
4242

43-
__version__ = '1.8.1'
43+
__version__ = '1.8.2'

pygccxml/parser/config.py

+15-29
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
undefine_symbols=None,
4646
cflags="",
4747
compiler=None,
48-
xml_generator="castxml",
48+
xml_generator=None,
4949
keep_xml=False,
5050
compiler_path=None,
5151
flags=None):
@@ -187,11 +187,16 @@ def __ensure_dir_exists(self, dir_path, meaning):
187187
(meaning, dir_path))
188188

189189
def raise_on_wrong_settings(self):
190-
"""validates the configuration settings and raises RuntimeError on
191-
error"""
190+
"""
191+
Validates the configuration settings and raises RuntimeError on error
192+
"""
192193
self.__ensure_dir_exists(self.working_directory, 'working directory')
193194
for idir in self.include_paths:
194195
self.__ensure_dir_exists(idir, 'include directory')
196+
if self.__xml_generator not in ["castxml", "gccxml"]:
197+
msg = ('xml_generator("%s") should either be ' +
198+
'"castxml" or "gccxml".') % self.xml_generator
199+
raise RuntimeError(msg)
195200

196201

197202
class xml_generator_configuration_t(parser_configuration_t):
@@ -215,7 +220,7 @@ def __init__(
215220
ignore_gccxml_output=False,
216221
cflags="",
217222
compiler=None,
218-
xml_generator="castxml",
223+
xml_generator=None,
219224
keep_xml=False,
220225
compiler_path=None,
221226
flags=None):
@@ -277,31 +282,12 @@ def ignore_gccxml_output(self, val=True):
277282

278283
def raise_on_wrong_settings(self):
279284
super(xml_generator_configuration_t, self).raise_on_wrong_settings()
280-
if os.path.isfile(self.xml_generator_path):
281-
return
282-
if os.name == 'nt':
283-
gccxml_name = 'gccxml' + '.exe'
284-
environment_var_delimiter = ';'
285-
elif os.name == 'posix':
286-
gccxml_name = 'gccxml'
287-
environment_var_delimiter = ':'
288-
else:
289-
raise RuntimeError(
290-
'unable to find out location of the xml generator')
291-
may_be_gccxml = os.path.join(self.xml_generator_path, gccxml_name)
292-
if os.path.isfile(may_be_gccxml):
293-
self.xml_generator_path = may_be_gccxml
294-
else:
295-
for path in os.environ['PATH'].split(environment_var_delimiter):
296-
xml_generator_path = os.path.join(path, gccxml_name)
297-
if os.path.isfile(xml_generator_path):
298-
self.xml_generator_path = xml_generator_path
299-
break
300-
else:
301-
msg = (
302-
'xml_generator_path("%s") should exists or to be a ' +
303-
'valid file name.') % self.xml_generator_path
304-
raise RuntimeError(msg)
285+
if self.xml_generator_path is None or \
286+
not os.path.isfile(self.xml_generator_path):
287+
msg = (
288+
'xml_generator_path("%s") should be set and exist.') \
289+
% self.xml_generator_path
290+
raise RuntimeError(msg)
305291

306292

307293
class _StringDeprecationWrapper(str):

pygccxml/parser/source_reader.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,20 @@ def create_xml_file(self, source_file, destination=None):
300300
utils.remove_file_no_raise(xml_file, self.__config)
301301
else:
302302
xml_file = utils.create_temp_file_name(suffix='.xml')
303-
try:
304-
ffname = source_file
305-
if not os.path.isabs(ffname):
306-
ffname = self.__file_full_name(source_file)
307-
command_line = self.__create_command_line(ffname, xml_file)
308-
309-
process = subprocess.Popen(
310-
args=command_line,
311-
shell=True,
312-
stdin=subprocess.PIPE,
313-
stdout=subprocess.PIPE)
314-
process.stdin.close()
315303

304+
ffname = source_file
305+
if not os.path.isabs(ffname):
306+
ffname = self.__file_full_name(source_file)
307+
command_line = self.__create_command_line(ffname, xml_file)
308+
309+
process = subprocess.Popen(
310+
args=command_line,
311+
shell=True,
312+
stdin=subprocess.PIPE,
313+
stdout=subprocess.PIPE)
314+
process.stdin.close()
315+
316+
try:
316317
gccxml_reports = []
317318
while process.poll() is None:
318319
line = process.stdout.readline()
@@ -344,10 +345,11 @@ def create_xml_file(self, source_file, destination=None):
344345
"Error occurred while running " +
345346
self.__config.xml_generator.upper() +
346347
": %s status:%s" % (gccxml_msg, exit_status))
347-
348348
except Exception:
349349
utils.remove_file_no_raise(xml_file, self.__config)
350350
raise
351+
finally:
352+
process.stdout.close()
351353
return xml_file
352354

353355
def create_xml_file_from_string(self, content, destination=None):

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from setuptools import setup
88

99
setup(name="pygccxml",
10-
version="1.8.1",
10+
version="1.8.2",
1111
author="Roman Yakovenko",
1212
author_email="roman yakovenko at gmail com",
1313
maintainer="Michka Popoff and the Insight Software Consortium",

unittests/test_all.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import test_pattern_parser
7676
import test_function_pointer
7777
import test_directory_cache
78+
import test_config
7879

7980
testers = [
8081
# , demangled_tester # failing right now
@@ -142,7 +143,8 @@
142143
test_smart_pointer,
143144
test_pattern_parser,
144145
test_function_pointer,
145-
test_directory_cache
146+
test_directory_cache,
147+
test_config
146148
]
147149

148150
if 'posix' in os.name:

unittests/test_config.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2014-2016 Insight Software Consortium.
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# See http://www.boost.org/LICENSE_1_0.txt
4+
5+
import sys
6+
import os
7+
import unittest
8+
9+
sys.path.insert(1, os.path.join(os.curdir, '..'))
10+
sys.path.insert(1, "../pygccxml")
11+
12+
from pygccxml import parser # nopep8
13+
from pygccxml import utils # nopep8
14+
15+
16+
class Test(unittest.TestCase):
17+
18+
def test_config(self):
19+
"""Test config setup with wrong xml generator setups."""
20+
21+
# Some code to parse for the example
22+
code = "int a;"
23+
24+
# Find the location of the xml generator (castxml or gccxml)
25+
generator_path, name = utils.find_xml_generator()
26+
27+
# No xml generator path
28+
config = parser.xml_generator_configuration_t(xml_generator=name)
29+
self.assertRaises(
30+
RuntimeError, lambda: parser.parse_string(code, config))
31+
32+
# Invalid path
33+
config = parser.xml_generator_configuration_t(
34+
xml_generator_path="wrong/path",
35+
xml_generator=name)
36+
self.assertRaises(
37+
RuntimeError, lambda: parser.parse_string(code, config))
38+
39+
# None path
40+
config = parser.xml_generator_configuration_t(
41+
xml_generator_path=None,
42+
xml_generator=name)
43+
self.assertRaises(
44+
RuntimeError, lambda: parser.parse_string(code, config))
45+
46+
# No name
47+
config = parser.xml_generator_configuration_t(
48+
xml_generator_path=generator_path)
49+
self.assertRaises(
50+
RuntimeError, lambda: parser.parse_string(code, config))
51+
52+
# Random name
53+
config = parser.xml_generator_configuration_t(
54+
xml_generator_path=generator_path,
55+
xml_generator="not_a_generator")
56+
self.assertRaises(
57+
RuntimeError, lambda: parser.parse_string(code, config))
58+
59+
# None name
60+
config = parser.xml_generator_configuration_t(
61+
xml_generator_path=generator_path,
62+
xml_generator=None)
63+
self.assertRaises(
64+
RuntimeError, lambda: parser.parse_string(code, config))
65+
66+
67+
def create_suite():
68+
suite = unittest.TestSuite()
69+
suite.addTest(unittest.makeSuite(Test))
70+
return suite
71+
72+
73+
def run_suite():
74+
unittest.TextTestRunner(verbosity=2).run(create_suite())
75+
76+
if __name__ == "__main__":
77+
run_suite()

0 commit comments

Comments
 (0)