Skip to content

Commit 1bc25ba

Browse files
committed
xml_generator_configuration_t should not try to look for castxml or gccxml (#65)
You can use utils.find_xml_generator to help you finding the path to the xml generator, or set it manually. It is now mandatory to pass a valid xml_generator and xml_generator_path to the configuration.
1 parent becda00 commit 1bc25ba

File tree

4 files changed

+105
-30
lines changed

4 files changed

+105
-30
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Changes
22
=======
33

4+
5+
Version 1.8.2 (Not yet released)
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

pygccxml/parser/config.py

Lines changed: 15 additions & 29 deletions
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):

unittests/test_all.py

Lines changed: 3 additions & 1 deletion
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

Lines changed: 77 additions & 0 deletions
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)