Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: Lib/sysconfig.py

Issue 3871: cross and native build of python for mingw32 with distutils
Patch Set: Created 7 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/plat-generic/regen ('k') | Lib/test/test_capi.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Access to Python's configuration information.""" 1 """Access to Python's configuration information."""
2 2
3 import os 3 import os
4 import re 4 import re
5 import sys 5 import sys
6 from os.path import pardir, realpath 6 from os.path import pardir, realpath
7 7
8 __all__ = [ 8 __all__ = [
9 'get_config_h_filename', 9 'get_config_h_filename',
10 'get_config_var', 10 'get_config_var',
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return _is_python_source_dir(_sys_home) 159 return _is_python_source_dir(_sys_home)
160 return _is_python_source_dir(_PROJECT_BASE) 160 return _is_python_source_dir(_PROJECT_BASE)
161 161
162 _PYTHON_BUILD = is_python_build(True) 162 _PYTHON_BUILD = is_python_build(True)
163 163
164 if _PYTHON_BUILD: 164 if _PYTHON_BUILD:
165 for scheme in ('posix_prefix', 'posix_home'): 165 for scheme in ('posix_prefix', 'posix_home'):
166 _INSTALL_SCHEMES[scheme]['include'] = '{srcdir}/Include' 166 _INSTALL_SCHEMES[scheme]['include'] = '{srcdir}/Include'
167 _INSTALL_SCHEMES[scheme]['platinclude'] = '{projectbase}/.' 167 _INSTALL_SCHEMES[scheme]['platinclude'] = '{projectbase}/.'
168 168
169 # GCC(mingw) use posix build system
170 if os.name == "nt" and sys.version.upper().find('GCC') >= 0:
171 _INSTALL_SCHEMES['nt']['include'] = '{srcdir}/Include'
172 _INSTALL_SCHEMES['nt']['platinclude'] = '{projectbase}/.'
169 173
170 def _subst_vars(s, local_vars): 174 def _subst_vars(s, local_vars):
171 try: 175 try:
172 return s.format(**local_vars) 176 return s.format(**local_vars)
173 except KeyError: 177 except KeyError:
174 try: 178 try:
175 return s.format(**os.environ) 179 return s.format(**os.environ)
176 except KeyError as var: 180 except KeyError as var:
177 raise AttributeError('{%s}' % var) 181 raise AttributeError('{%s}' % var)
178 182
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 msg = "invalid Python installation: unable to open %s" % config_h 387 msg = "invalid Python installation: unable to open %s" % config_h
384 if hasattr(e, "strerror"): 388 if hasattr(e, "strerror"):
385 msg = msg + " (%s)" % e.strerror 389 msg = msg + " (%s)" % e.strerror
386 raise IOError(msg) 390 raise IOError(msg)
387 # On AIX, there are wrong paths to the linker scripts in the Makefile 391 # On AIX, there are wrong paths to the linker scripts in the Makefile
388 # -- these paths are relative to the Python source, but when installed 392 # -- these paths are relative to the Python source, but when installed
389 # the scripts are in another directory. 393 # the scripts are in another directory.
390 if _PYTHON_BUILD: 394 if _PYTHON_BUILD:
391 vars['LDSHARED'] = vars['BLDSHARED'] 395 vars['LDSHARED'] = vars['BLDSHARED']
392 396
393 # There's a chicken-and-egg situation on OS X with regards to the 397 destfile = os.path.join(os.path.dirname(__file__), '_sysconfigdata.py')
394 # _sysconfigdata module after the changes introduced by #15298:
395 # get_config_vars() is called by get_platform() as part of the
396 # `make pybuilddir.txt` target -- which is a precursor to the
397 # _sysconfigdata.py module being constructed. Unfortunately,
398 # get_config_vars() eventually calls _init_posix(), which attempts
399 # to import _sysconfigdata, which we won't have built yet. In order
400 # for _init_posix() to work, if we're on Darwin, just mock up the
401 # _sysconfigdata module manually and populate it with the build vars.
402 # This is more than sufficient for ensuring the subsequent call to
403 # get_platform() succeeds.
404 name = '_sysconfigdata'
405 if 'darwin' in sys.platform:
406 import imp
407 module = imp.new_module(name)
408 module.build_time_vars = vars
409 sys.modules[name] = module
410
411 pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
412 if hasattr(sys, "gettotalrefcount"):
413 pybuilddir += '-pydebug'
414 os.makedirs(pybuilddir, exist_ok=True)
415 destfile = os.path.join(pybuilddir, name + '.py')
416 398
417 with open(destfile, 'w', encoding='utf8') as f: 399 with open(destfile, 'w', encoding='utf8') as f:
418 f.write('# system configuration generated and used by' 400 f.write('# system configuration generated and used by'
419 ' the sysconfig module\n') 401 ' the sysconfig module\n')
420 f.write('build_time_vars = ') 402 f.write('build_time_vars = ')
421 pprint.pprint(vars, stream=f) 403 pprint.pprint(vars, stream=f)
422
423 # Create file used for sys.path fixup -- see Modules/getpath.c
424 with open('pybuilddir.txt', 'w', encoding='ascii') as f:
425 f.write(pybuilddir)
426 404
427 def _init_posix(vars): 405 def _init_posix(vars):
428 """Initialize the module as appropriate for POSIX systems.""" 406 """Initialize the module as appropriate for POSIX systems."""
429 # _sysconfigdata is generated at build time, see _generate_posix_vars() 407 # _sysconfigdata is generated at build time, see _generate_posix_vars()
430 from _sysconfigdata import build_time_vars 408 from _sysconfigdata import build_time_vars
431 vars.update(build_time_vars) 409 vars.update(build_time_vars)
432 410
433 def _init_non_posix(vars): 411 def _init_non_posix(vars):
434 """Initialize the module as appropriate for NT""" 412 """Initialize the module as appropriate for NT"""
435 # set basic install directories 413 # set basic install directories
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 else: 451 else:
474 m = undef_rx.match(line) 452 m = undef_rx.match(line)
475 if m: 453 if m:
476 vars[m.group(1)] = 0 454 vars[m.group(1)] = 0
477 return vars 455 return vars
478 456
479 457
480 def get_config_h_filename(): 458 def get_config_h_filename():
481 """Return the path of pyconfig.h.""" 459 """Return the path of pyconfig.h."""
482 if _PYTHON_BUILD: 460 if _PYTHON_BUILD:
483 if os.name == "nt": 461 # GCC(mingw): os.name is "nt" but build system is posix
462 if os.name == "nt" and sys.version.upper().find('GCC') < 0:
484 inc_dir = os.path.join(_sys_home or _PROJECT_BASE, "PC") 463 inc_dir = os.path.join(_sys_home or _PROJECT_BASE, "PC")
485 else: 464 else:
486 inc_dir = _sys_home or _PROJECT_BASE 465 inc_dir = _sys_home or _PROJECT_BASE
487 else: 466 else:
488 inc_dir = get_path('platinclude') 467 inc_dir = get_path('platinclude')
489 return os.path.join(inc_dir, 'pyconfig.h') 468 return os.path.join(inc_dir, 'pyconfig.h')
490 469
491 470
492 def get_scheme_names(): 471 def get_scheme_names():
493 """Return a tuple containing the schemes names.""" 472 """Return a tuple containing the schemes names."""
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 _CONFIG_VARS['base'] = _PREFIX 523 _CONFIG_VARS['base'] = _PREFIX
545 _CONFIG_VARS['installed_platbase'] = _BASE_EXEC_PREFIX 524 _CONFIG_VARS['installed_platbase'] = _BASE_EXEC_PREFIX
546 _CONFIG_VARS['platbase'] = _EXEC_PREFIX 525 _CONFIG_VARS['platbase'] = _EXEC_PREFIX
547 _CONFIG_VARS['projectbase'] = _PROJECT_BASE 526 _CONFIG_VARS['projectbase'] = _PROJECT_BASE
548 try: 527 try:
549 _CONFIG_VARS['abiflags'] = sys.abiflags 528 _CONFIG_VARS['abiflags'] = sys.abiflags
550 except AttributeError: 529 except AttributeError:
551 # sys.abiflags may not be defined on all platforms. 530 # sys.abiflags may not be defined on all platforms.
552 _CONFIG_VARS['abiflags'] = '' 531 _CONFIG_VARS['abiflags'] = ''
553 532
554 if os.name in ('nt', 'os2'): 533 # GCC(mingw) use posix build system
534 posix_build = False
535 if os.name == 'posix':
536 posix_build = True
537 else:
538 if os.name == 'nt' and sys.version.upper().find('GCC') >= 0:
539 posix_build = True
540 if os.name in ('nt', 'os2') and not posix_build:
555 _init_non_posix(_CONFIG_VARS) 541 _init_non_posix(_CONFIG_VARS)
556 if os.name == 'posix': 542 if posix_build:
557 _init_posix(_CONFIG_VARS) 543 _init_posix(_CONFIG_VARS)
558 # Setting 'userbase' is done below the call to the 544 # Setting 'userbase' is done below the call to the
559 # init function to enable using 'get_config_var' in 545 # init function to enable using 'get_config_var' in
560 # the init-function. 546 # the init-function.
561 _CONFIG_VARS['userbase'] = _getuserbase() 547 _CONFIG_VARS['userbase'] = _getuserbase()
562 548
563 # Always convert srcdir to an absolute path 549 # Always convert srcdir to an absolute path
564 srcdir = _CONFIG_VARS.get('srcdir', _PROJECT_BASE) 550 srcdir = _CONFIG_VARS.get('srcdir', _PROJECT_BASE)
565 if os.name == 'posix': 551 if posix_build:
566 if _PYTHON_BUILD: 552 if _PYTHON_BUILD:
567 # If srcdir is a relative path (typically '.' or '..') 553 # If srcdir is a relative path (typically '.' or '..')
568 # then it should be interpreted relative to the directory 554 # then it should be interpreted relative to the directory
569 # containing Makefile. 555 # containing Makefile.
570 base = os.path.dirname(get_makefile_filename()) 556 base = os.path.dirname(get_makefile_filename())
571 srcdir = os.path.join(base, srcdir) 557 srcdir = os.path.join(base, srcdir)
572 else: 558 else:
573 # srcdir is not meaningful since the installation is 559 # srcdir is not meaningful since the installation is
574 # spread about the filesystem. We choose the 560 # spread about the filesystem. We choose the
575 # directory containing the Makefile since we know it 561 # directory containing the Makefile since we know it
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 print('Python version: "%s"' % get_python_version()) 697 print('Python version: "%s"' % get_python_version())
712 print('Current installation scheme: "%s"' % _get_default_scheme()) 698 print('Current installation scheme: "%s"' % _get_default_scheme())
713 print() 699 print()
714 _print_dict('Paths', get_paths()) 700 _print_dict('Paths', get_paths())
715 print() 701 print()
716 _print_dict('Variables', get_config_vars()) 702 _print_dict('Variables', get_config_vars())
717 703
718 704
719 if __name__ == '__main__': 705 if __name__ == '__main__':
720 _main() 706 _main()
OLDNEW
« no previous file with comments | « Lib/plat-generic/regen ('k') | Lib/test/test_capi.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+