summaryrefslogtreecommitdiff
path: root/Lib/sysconfig.py
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2012-07-27 12:06:55 +0100
committerRichard Oudkerk <shibturn@gmail.com>2012-07-27 12:06:55 +0100
commit95c9f9b7b108f52e0be13429acc679186ced8742 (patch)
tree1f91cc383eb085a45f88314ba3fd42e3de95ac4b /Lib/sysconfig.py
parent4d22f64721ee307f0acfc8bd54d0909f091e0e30 (diff)
downloadcpython-95c9f9b7b108f52e0be13429acc679186ced8742.tar.gz
Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Diffstat (limited to 'Lib/sysconfig.py')
-rw-r--r--Lib/sysconfig.py38
1 files changed, 16 insertions, 22 deletions
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index 79828936e6..ba4024fe88 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -533,28 +533,22 @@ def get_config_vars(*args):
# the init-function.
_CONFIG_VARS['userbase'] = _getuserbase()
- if 'srcdir' not in _CONFIG_VARS:
- _CONFIG_VARS['srcdir'] = _PROJECT_BASE
- else:
- _CONFIG_VARS['srcdir'] = _safe_realpath(_CONFIG_VARS['srcdir'])
-
- # Convert srcdir into an absolute path if it appears necessary.
- # Normally it is relative to the build directory. However, during
- # testing, for example, we might be running a non-installed python
- # from a different directory.
- if _PYTHON_BUILD and os.name == "posix":
- base = _PROJECT_BASE
- try:
- cwd = os.getcwd()
- except OSError:
- cwd = None
- if (not os.path.isabs(_CONFIG_VARS['srcdir']) and
- base != cwd):
- # srcdir is relative and we are not in the same directory
- # as the executable. Assume executable is in the build
- # directory and make srcdir absolute.
- srcdir = os.path.join(base, _CONFIG_VARS['srcdir'])
- _CONFIG_VARS['srcdir'] = os.path.normpath(srcdir)
+ # Always convert srcdir to an absolute path
+ srcdir = _CONFIG_VARS.get('srcdir', _PROJECT_BASE)
+ if os.name == 'posix':
+ if _PYTHON_BUILD:
+ # If srcdir is a relative path (typically '.' or '..')
+ # then it should be interpreted relative to the directory
+ # containing Makefile.
+ base = os.path.dirname(get_makefile_filename())
+ srcdir = os.path.join(base, srcdir)
+ else:
+ # srcdir is not meaningful since the installation is
+ # spread about the filesystem. We choose the
+ # directory containing the Makefile since we know it
+ # exists.
+ srcdir = os.path.dirname(get_makefile_filename())
+ _CONFIG_VARS['srcdir'] = _safe_realpath(srcdir)
# OS X platforms require special customization to handle
# multi-architecture, multi-os-version installers