ccompiler.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. from __future__ import division, absolute_import, print_function
  2. import os
  3. import re
  4. import sys
  5. import types
  6. from copy import copy
  7. from distutils import ccompiler
  8. from distutils.ccompiler import *
  9. from distutils.errors import DistutilsExecError, DistutilsModuleError, \
  10. DistutilsPlatformError
  11. from distutils.sysconfig import customize_compiler
  12. from distutils.version import LooseVersion
  13. from numpy.distutils import log
  14. from numpy.distutils.compat import get_exception
  15. from numpy.distutils.exec_command import exec_command
  16. from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, \
  17. quote_args, get_num_build_jobs
  18. def replace_method(klass, method_name, func):
  19. if sys.version_info[0] < 3:
  20. m = types.MethodType(func, None, klass)
  21. else:
  22. # Py3k does not have unbound method anymore, MethodType does not work
  23. m = lambda self, *args, **kw: func(self, *args, **kw)
  24. setattr(klass, method_name, m)
  25. # Using customized CCompiler.spawn.
  26. def CCompiler_spawn(self, cmd, display=None):
  27. """
  28. Execute a command in a sub-process.
  29. Parameters
  30. ----------
  31. cmd : str
  32. The command to execute.
  33. display : str or sequence of str, optional
  34. The text to add to the log file kept by `numpy.distutils`.
  35. If not given, `display` is equal to `cmd`.
  36. Returns
  37. -------
  38. None
  39. Raises
  40. ------
  41. DistutilsExecError
  42. If the command failed, i.e. the exit status was not 0.
  43. """
  44. if display is None:
  45. display = cmd
  46. if is_sequence(display):
  47. display = ' '.join(list(display))
  48. log.info(display)
  49. s, o = exec_command(cmd)
  50. if s:
  51. if is_sequence(cmd):
  52. cmd = ' '.join(list(cmd))
  53. try:
  54. print(o)
  55. except UnicodeError:
  56. # When installing through pip, `o` can contain non-ascii chars
  57. pass
  58. if re.search('Too many open files', o):
  59. msg = '\nTry rerunning setup command until build succeeds.'
  60. else:
  61. msg = ''
  62. raise DistutilsExecError('Command "%s" failed with exit status %d%s' % (cmd, s, msg))
  63. replace_method(CCompiler, 'spawn', CCompiler_spawn)
  64. def CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
  65. """
  66. Return the name of the object files for the given source files.
  67. Parameters
  68. ----------
  69. source_filenames : list of str
  70. The list of paths to source files. Paths can be either relative or
  71. absolute, this is handled transparently.
  72. strip_dir : bool, optional
  73. Whether to strip the directory from the returned paths. If True,
  74. the file name prepended by `output_dir` is returned. Default is False.
  75. output_dir : str, optional
  76. If given, this path is prepended to the returned paths to the
  77. object files.
  78. Returns
  79. -------
  80. obj_names : list of str
  81. The list of paths to the object files corresponding to the source
  82. files in `source_filenames`.
  83. """
  84. if output_dir is None:
  85. output_dir = ''
  86. obj_names = []
  87. for src_name in source_filenames:
  88. base, ext = os.path.splitext(os.path.normpath(src_name))
  89. base = os.path.splitdrive(base)[1] # Chop off the drive
  90. base = base[os.path.isabs(base):] # If abs, chop off leading /
  91. if base.startswith('..'):
  92. # Resolve starting relative path components, middle ones
  93. # (if any) have been handled by os.path.normpath above.
  94. i = base.rfind('..')+2
  95. d = base[:i]
  96. d = os.path.basename(os.path.abspath(d))
  97. base = d + base[i:]
  98. if ext not in self.src_extensions:
  99. raise UnknownFileError("unknown file type '%s' (from '%s')" % (ext, src_name))
  100. if strip_dir:
  101. base = os.path.basename(base)
  102. obj_name = os.path.join(output_dir, base + self.obj_extension)
  103. obj_names.append(obj_name)
  104. return obj_names
  105. replace_method(CCompiler, 'object_filenames', CCompiler_object_filenames)
  106. def CCompiler_compile(self, sources, output_dir=None, macros=None,
  107. include_dirs=None, debug=0, extra_preargs=None,
  108. extra_postargs=None, depends=None):
  109. """
  110. Compile one or more source files.
  111. Please refer to the Python distutils API reference for more details.
  112. Parameters
  113. ----------
  114. sources : list of str
  115. A list of filenames
  116. output_dir : str, optional
  117. Path to the output directory.
  118. macros : list of tuples
  119. A list of macro definitions.
  120. include_dirs : list of str, optional
  121. The directories to add to the default include file search path for
  122. this compilation only.
  123. debug : bool, optional
  124. Whether or not to output debug symbols in or alongside the object
  125. file(s).
  126. extra_preargs, extra_postargs : ?
  127. Extra pre- and post-arguments.
  128. depends : list of str, optional
  129. A list of file names that all targets depend on.
  130. Returns
  131. -------
  132. objects : list of str
  133. A list of object file names, one per source file `sources`.
  134. Raises
  135. ------
  136. CompileError
  137. If compilation fails.
  138. """
  139. # This method is effective only with Python >=2.3 distutils.
  140. # Any changes here should be applied also to fcompiler.compile
  141. # method to support pre Python 2.3 distutils.
  142. if not sources:
  143. return []
  144. # FIXME:RELATIVE_IMPORT
  145. if sys.version_info[0] < 3:
  146. from .fcompiler import FCompiler, is_f_file, has_f90_header
  147. else:
  148. from numpy.distutils.fcompiler import (FCompiler, is_f_file,
  149. has_f90_header)
  150. if isinstance(self, FCompiler):
  151. display = []
  152. for fc in ['f77', 'f90', 'fix']:
  153. fcomp = getattr(self, 'compiler_'+fc)
  154. if fcomp is None:
  155. continue
  156. display.append("Fortran %s compiler: %s" % (fc, ' '.join(fcomp)))
  157. display = '\n'.join(display)
  158. else:
  159. ccomp = self.compiler_so
  160. display = "C compiler: %s\n" % (' '.join(ccomp),)
  161. log.info(display)
  162. macros, objects, extra_postargs, pp_opts, build = \
  163. self._setup_compile(output_dir, macros, include_dirs, sources,
  164. depends, extra_postargs)
  165. cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
  166. display = "compile options: '%s'" % (' '.join(cc_args))
  167. if extra_postargs:
  168. display += "\nextra options: '%s'" % (' '.join(extra_postargs))
  169. log.info(display)
  170. def single_compile(args):
  171. obj, (src, ext) = args
  172. self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  173. if isinstance(self, FCompiler):
  174. objects_to_build = list(build.keys())
  175. f77_objects, other_objects = [], []
  176. for obj in objects:
  177. if obj in objects_to_build:
  178. src, ext = build[obj]
  179. if self.compiler_type=='absoft':
  180. obj = cyg2win32(obj)
  181. src = cyg2win32(src)
  182. if is_f_file(src) and not has_f90_header(src):
  183. f77_objects.append((obj, (src, ext)))
  184. else:
  185. other_objects.append((obj, (src, ext)))
  186. # f77 objects can be built in parallel
  187. build_items = f77_objects
  188. # build f90 modules serial, module files are generated during
  189. # compilation and may be used by files later in the list so the
  190. # ordering is important
  191. for o in other_objects:
  192. single_compile(o)
  193. else:
  194. build_items = build.items()
  195. jobs = get_num_build_jobs()
  196. if len(build) > 1 and jobs > 1:
  197. # build parallel
  198. import multiprocessing.pool
  199. pool = multiprocessing.pool.ThreadPool(jobs)
  200. pool.map(single_compile, build_items)
  201. pool.close()
  202. else:
  203. # build serial
  204. for o in build_items:
  205. single_compile(o)
  206. # Return *all* object filenames, not just the ones we just built.
  207. return objects
  208. replace_method(CCompiler, 'compile', CCompiler_compile)
  209. def CCompiler_customize_cmd(self, cmd, ignore=()):
  210. """
  211. Customize compiler using distutils command.
  212. Parameters
  213. ----------
  214. cmd : class instance
  215. An instance inheriting from `distutils.cmd.Command`.
  216. ignore : sequence of str, optional
  217. List of `CCompiler` commands (without ``'set_'``) that should not be
  218. altered. Strings that are checked for are:
  219. ``('include_dirs', 'define', 'undef', 'libraries', 'library_dirs',
  220. 'rpath', 'link_objects')``.
  221. Returns
  222. -------
  223. None
  224. """
  225. log.info('customize %s using %s' % (self.__class__.__name__,
  226. cmd.__class__.__name__))
  227. def allow(attr):
  228. return getattr(cmd, attr, None) is not None and attr not in ignore
  229. if allow('include_dirs'):
  230. self.set_include_dirs(cmd.include_dirs)
  231. if allow('define'):
  232. for (name, value) in cmd.define:
  233. self.define_macro(name, value)
  234. if allow('undef'):
  235. for macro in cmd.undef:
  236. self.undefine_macro(macro)
  237. if allow('libraries'):
  238. self.set_libraries(self.libraries + cmd.libraries)
  239. if allow('library_dirs'):
  240. self.set_library_dirs(self.library_dirs + cmd.library_dirs)
  241. if allow('rpath'):
  242. self.set_runtime_library_dirs(cmd.rpath)
  243. if allow('link_objects'):
  244. self.set_link_objects(cmd.link_objects)
  245. replace_method(CCompiler, 'customize_cmd', CCompiler_customize_cmd)
  246. def _compiler_to_string(compiler):
  247. props = []
  248. mx = 0
  249. keys = list(compiler.executables.keys())
  250. for key in ['version', 'libraries', 'library_dirs',
  251. 'object_switch', 'compile_switch',
  252. 'include_dirs', 'define', 'undef', 'rpath', 'link_objects']:
  253. if key not in keys:
  254. keys.append(key)
  255. for key in keys:
  256. if hasattr(compiler, key):
  257. v = getattr(compiler, key)
  258. mx = max(mx, len(key))
  259. props.append((key, repr(v)))
  260. lines = []
  261. format = '%-' + repr(mx+1) + 's = %s'
  262. for prop in props:
  263. lines.append(format % prop)
  264. return '\n'.join(lines)
  265. def CCompiler_show_customization(self):
  266. """
  267. Print the compiler customizations to stdout.
  268. Parameters
  269. ----------
  270. None
  271. Returns
  272. -------
  273. None
  274. Notes
  275. -----
  276. Printing is only done if the distutils log threshold is < 2.
  277. """
  278. if 0:
  279. for attrname in ['include_dirs', 'define', 'undef',
  280. 'libraries', 'library_dirs',
  281. 'rpath', 'link_objects']:
  282. attr = getattr(self, attrname, None)
  283. if not attr:
  284. continue
  285. log.info("compiler '%s' is set to %s" % (attrname, attr))
  286. try:
  287. self.get_version()
  288. except:
  289. pass
  290. if log._global_log.threshold<2:
  291. print('*'*80)
  292. print(self.__class__)
  293. print(_compiler_to_string(self))
  294. print('*'*80)
  295. replace_method(CCompiler, 'show_customization', CCompiler_show_customization)
  296. def CCompiler_customize(self, dist, need_cxx=0):
  297. """
  298. Do any platform-specific customization of a compiler instance.
  299. This method calls `distutils.sysconfig.customize_compiler` for
  300. platform-specific customization, as well as optionally remove a flag
  301. to suppress spurious warnings in case C++ code is being compiled.
  302. Parameters
  303. ----------
  304. dist : object
  305. This parameter is not used for anything.
  306. need_cxx : bool, optional
  307. Whether or not C++ has to be compiled. If so (True), the
  308. ``"-Wstrict-prototypes"`` option is removed to prevent spurious
  309. warnings. Default is False.
  310. Returns
  311. -------
  312. None
  313. Notes
  314. -----
  315. All the default options used by distutils can be extracted with::
  316. from distutils import sysconfig
  317. sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS',
  318. 'CCSHARED', 'LDSHARED', 'SO')
  319. """
  320. # See FCompiler.customize for suggested usage.
  321. log.info('customize %s' % (self.__class__.__name__))
  322. customize_compiler(self)
  323. if need_cxx:
  324. # In general, distutils uses -Wstrict-prototypes, but this option is
  325. # not valid for C++ code, only for C. Remove it if it's there to
  326. # avoid a spurious warning on every compilation.
  327. try:
  328. self.compiler_so.remove('-Wstrict-prototypes')
  329. except (AttributeError, ValueError):
  330. pass
  331. if hasattr(self, 'compiler') and 'cc' in self.compiler[0]:
  332. if not self.compiler_cxx:
  333. if self.compiler[0].startswith('gcc'):
  334. a, b = 'gcc', 'g++'
  335. else:
  336. a, b = 'cc', 'c++'
  337. self.compiler_cxx = [self.compiler[0].replace(a, b)]\
  338. + self.compiler[1:]
  339. else:
  340. if hasattr(self, 'compiler'):
  341. log.warn("#### %s #######" % (self.compiler,))
  342. if not hasattr(self, 'compiler_cxx'):
  343. log.warn('Missing compiler_cxx fix for ' + self.__class__.__name__)
  344. return
  345. replace_method(CCompiler, 'customize', CCompiler_customize)
  346. def simple_version_match(pat=r'[-.\d]+', ignore='', start=''):
  347. """
  348. Simple matching of version numbers, for use in CCompiler and FCompiler.
  349. Parameters
  350. ----------
  351. pat : str, optional
  352. A regular expression matching version numbers.
  353. Default is ``r'[-.\\d]+'``.
  354. ignore : str, optional
  355. A regular expression matching patterns to skip.
  356. Default is ``''``, in which case nothing is skipped.
  357. start : str, optional
  358. A regular expression matching the start of where to start looking
  359. for version numbers.
  360. Default is ``''``, in which case searching is started at the
  361. beginning of the version string given to `matcher`.
  362. Returns
  363. -------
  364. matcher : callable
  365. A function that is appropriate to use as the ``.version_match``
  366. attribute of a `CCompiler` class. `matcher` takes a single parameter,
  367. a version string.
  368. """
  369. def matcher(self, version_string):
  370. # version string may appear in the second line, so getting rid
  371. # of new lines:
  372. version_string = version_string.replace('\n', ' ')
  373. pos = 0
  374. if start:
  375. m = re.match(start, version_string)
  376. if not m:
  377. return None
  378. pos = m.end()
  379. while True:
  380. m = re.search(pat, version_string[pos:])
  381. if not m:
  382. return None
  383. if ignore and re.match(ignore, m.group(0)):
  384. pos = m.end()
  385. continue
  386. break
  387. return m.group(0)
  388. return matcher
  389. def CCompiler_get_version(self, force=False, ok_status=[0]):
  390. """
  391. Return compiler version, or None if compiler is not available.
  392. Parameters
  393. ----------
  394. force : bool, optional
  395. If True, force a new determination of the version, even if the
  396. compiler already has a version attribute. Default is False.
  397. ok_status : list of int, optional
  398. The list of status values returned by the version look-up process
  399. for which a version string is returned. If the status value is not
  400. in `ok_status`, None is returned. Default is ``[0]``.
  401. Returns
  402. -------
  403. version : str or None
  404. Version string, in the format of `distutils.version.LooseVersion`.
  405. """
  406. if not force and hasattr(self, 'version'):
  407. return self.version
  408. self.find_executables()
  409. try:
  410. version_cmd = self.version_cmd
  411. except AttributeError:
  412. return None
  413. if not version_cmd or not version_cmd[0]:
  414. return None
  415. try:
  416. matcher = self.version_match
  417. except AttributeError:
  418. try:
  419. pat = self.version_pattern
  420. except AttributeError:
  421. return None
  422. def matcher(version_string):
  423. m = re.match(pat, version_string)
  424. if not m:
  425. return None
  426. version = m.group('version')
  427. return version
  428. status, output = exec_command(version_cmd, use_tee=0)
  429. version = None
  430. if status in ok_status:
  431. version = matcher(output)
  432. if version:
  433. version = LooseVersion(version)
  434. self.version = version
  435. return version
  436. replace_method(CCompiler, 'get_version', CCompiler_get_version)
  437. def CCompiler_cxx_compiler(self):
  438. """
  439. Return the C++ compiler.
  440. Parameters
  441. ----------
  442. None
  443. Returns
  444. -------
  445. cxx : class instance
  446. The C++ compiler, as a `CCompiler` instance.
  447. """
  448. if self.compiler_type in ('msvc', 'intelw', 'intelemw'):
  449. return self
  450. cxx = copy(self)
  451. cxx.compiler_so = [cxx.compiler_cxx[0]] + cxx.compiler_so[1:]
  452. if sys.platform.startswith('aix') and 'ld_so_aix' in cxx.linker_so[0]:
  453. # AIX needs the ld_so_aix script included with Python
  454. cxx.linker_so = [cxx.linker_so[0], cxx.compiler_cxx[0]] \
  455. + cxx.linker_so[2:]
  456. else:
  457. cxx.linker_so = [cxx.compiler_cxx[0]] + cxx.linker_so[1:]
  458. return cxx
  459. replace_method(CCompiler, 'cxx_compiler', CCompiler_cxx_compiler)
  460. compiler_class['intel'] = ('intelccompiler', 'IntelCCompiler',
  461. "Intel C Compiler for 32-bit applications")
  462. compiler_class['intele'] = ('intelccompiler', 'IntelItaniumCCompiler',
  463. "Intel C Itanium Compiler for Itanium-based applications")
  464. compiler_class['intelem'] = ('intelccompiler', 'IntelEM64TCCompiler',
  465. "Intel C Compiler for 64-bit applications")
  466. compiler_class['intelw'] = ('intelccompiler', 'IntelCCompilerW',
  467. "Intel C Compiler for 32-bit applications on Windows")
  468. compiler_class['intelemw'] = ('intelccompiler', 'IntelEM64TCCompilerW',
  469. "Intel C Compiler for 64-bit applications on Windows")
  470. compiler_class['pathcc'] = ('pathccompiler', 'PathScaleCCompiler',
  471. "PathScale Compiler for SiCortex-based applications")
  472. ccompiler._default_compilers += (('linux.*', 'intel'),
  473. ('linux.*', 'intele'),
  474. ('linux.*', 'intelem'),
  475. ('linux.*', 'pathcc'),
  476. ('nt', 'intelw'),
  477. ('nt', 'intelemw'))
  478. if sys.platform == 'win32':
  479. compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',
  480. "Mingw32 port of GNU C Compiler for Win32"\
  481. "(for MSC built Python)")
  482. if mingw32():
  483. # On windows platforms, we want to default to mingw32 (gcc)
  484. # because msvc can't build blitz stuff.
  485. log.info('Setting mingw32 as default compiler for nt.')
  486. ccompiler._default_compilers = (('nt', 'mingw32'),) \
  487. + ccompiler._default_compilers
  488. _distutils_new_compiler = new_compiler
  489. def new_compiler (plat=None,
  490. compiler=None,
  491. verbose=0,
  492. dry_run=0,
  493. force=0):
  494. # Try first C compilers from numpy.distutils.
  495. if plat is None:
  496. plat = os.name
  497. try:
  498. if compiler is None:
  499. compiler = get_default_compiler(plat)
  500. (module_name, class_name, long_description) = compiler_class[compiler]
  501. except KeyError:
  502. msg = "don't know how to compile C/C++ code on platform '%s'" % plat
  503. if compiler is not None:
  504. msg = msg + " with '%s' compiler" % compiler
  505. raise DistutilsPlatformError(msg)
  506. module_name = "numpy.distutils." + module_name
  507. try:
  508. __import__ (module_name)
  509. except ImportError:
  510. msg = str(get_exception())
  511. log.info('%s in numpy.distutils; trying from distutils',
  512. str(msg))
  513. module_name = module_name[6:]
  514. try:
  515. __import__(module_name)
  516. except ImportError:
  517. msg = str(get_exception())
  518. raise DistutilsModuleError("can't compile C/C++ code: unable to load module '%s'" % \
  519. module_name)
  520. try:
  521. module = sys.modules[module_name]
  522. klass = vars(module)[class_name]
  523. except KeyError:
  524. raise DistutilsModuleError(("can't compile C/C++ code: unable to find class '%s' " +
  525. "in module '%s'") % (class_name, module_name))
  526. compiler = klass(None, dry_run, force)
  527. log.debug('new_compiler returns %s' % (klass))
  528. return compiler
  529. ccompiler.new_compiler = new_compiler
  530. _distutils_gen_lib_options = gen_lib_options
  531. def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
  532. library_dirs = quote_args(library_dirs)
  533. runtime_library_dirs = quote_args(runtime_library_dirs)
  534. r = _distutils_gen_lib_options(compiler, library_dirs,
  535. runtime_library_dirs, libraries)
  536. lib_opts = []
  537. for i in r:
  538. if is_sequence(i):
  539. lib_opts.extend(list(i))
  540. else:
  541. lib_opts.append(i)
  542. return lib_opts
  543. ccompiler.gen_lib_options = gen_lib_options
  544. # Also fix up the various compiler modules, which do
  545. # from distutils.ccompiler import gen_lib_options
  546. # Don't bother with mwerks, as we don't support Classic Mac.
  547. for _cc in ['msvc9', 'msvc', 'bcpp', 'cygwinc', 'emxc', 'unixc']:
  548. _m = sys.modules.get('distutils.' + _cc + 'compiler')
  549. if _m is not None:
  550. setattr(_m, 'gen_lib_options', gen_lib_options)
  551. _distutils_gen_preprocess_options = gen_preprocess_options
  552. def gen_preprocess_options (macros, include_dirs):
  553. include_dirs = quote_args(include_dirs)
  554. return _distutils_gen_preprocess_options(macros, include_dirs)
  555. ccompiler.gen_preprocess_options = gen_preprocess_options
  556. ##Fix distutils.util.split_quoted:
  557. # NOTE: I removed this fix in revision 4481 (see ticket #619), but it appears
  558. # that removing this fix causes f2py problems on Windows XP (see ticket #723).
  559. # Specifically, on WinXP when gfortran is installed in a directory path, which
  560. # contains spaces, then f2py is unable to find it.
  561. import string
  562. _wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
  563. _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
  564. _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
  565. _has_white_re = re.compile(r'\s')
  566. def split_quoted(s):
  567. s = s.strip()
  568. words = []
  569. pos = 0
  570. while s:
  571. m = _wordchars_re.match(s, pos)
  572. end = m.end()
  573. if end == len(s):
  574. words.append(s[:end])
  575. break
  576. if s[end] in string.whitespace: # unescaped, unquoted whitespace: now
  577. words.append(s[:end]) # we definitely have a word delimiter
  578. s = s[end:].lstrip()
  579. pos = 0
  580. elif s[end] == '\\': # preserve whatever is being escaped;
  581. # will become part of the current word
  582. s = s[:end] + s[end+1:]
  583. pos = end+1
  584. else:
  585. if s[end] == "'": # slurp singly-quoted string
  586. m = _squote_re.match(s, end)
  587. elif s[end] == '"': # slurp doubly-quoted string
  588. m = _dquote_re.match(s, end)
  589. else:
  590. raise RuntimeError("this can't happen (bad char '%c')" % s[end])
  591. if m is None:
  592. raise ValueError("bad string (mismatched %s quotes?)" % s[end])
  593. (beg, end) = m.span()
  594. if _has_white_re.search(s[beg+1:end-1]):
  595. s = s[:beg] + s[beg+1:end-1] + s[end:]
  596. pos = m.end() - 2
  597. else:
  598. # Keeping quotes when a quoted word does not contain
  599. # white-space. XXX: send a patch to distutils
  600. pos = m.end()
  601. if pos >= len(s):
  602. words.append(s)
  603. break
  604. return words
  605. ccompiler.split_quoted = split_quoted
  606. ##Fix distutils.util.split_quoted: