You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by tr...@apache.org on 2018/01/29 00:53:54 UTC
svn commit: r1822485 - in /subversion/branches/swig-py3: ./ build/generator/
build/generator/templates/ subversion/bindings/swig/
Author: troycurtisjr
Date: Mon Jan 29 00:53:54 2018
New Revision: 1822485
URL: http://svn.apache.org/viewvc?rev=1822485&view=rev
Log:
On branch swig-py3: Add py3c library support to the Windows build.
* build/generator/templates/vcnet_vcxproj.ezt
(UserMacros): Add template options to define UserMacros.
* build/generator/gen_vcnet_vcproj.py
(Generator.write_project): Include new user macro values in
data passed to the ezt template function.
* build/generator/gen_win_dependencies.py
(UserMacro): Define a new type to use with user macro templates.
(GenDependenciesBase._optional_libraries): Include py3c library.
(GenDependenciesBase.parse_options): Include the py3c library path
option.
(GenDependenciesBase.find_libraries): Add a call to _find_py3c().
(GenDependenciesBase._find_python): Define SWIG_PY_OPTS user macro
based on detected Python version.
(GenDependenciesBase._find_py3c): New method.
(GenDependenciesBase._find_swig,
GenDependenciesBase._find_jdk): Ensure output from subprocess is
properly decoded.
* gen-make.py
(_usage_exit): Add --with-py3c usage.
(my_getopt): Add with-py3c option.
* subversion/bindings/swig/INSTALL
Include py3c in Windows SWIG building instructions.
* build/generator/gen_base.py
(IncludeDependencyInfo._scan_for_includes): Ensure file data is
properly encoded as UTF8.
* build/generator/gen_win.py
(WinGeneratorBase.makeguid): Ensure data input to hashlib is binary
and not Unicode.
(WinGeneratorBase.get_win_includes): Include py3c include directory
in swig compile definition.
Modified:
subversion/branches/swig-py3/build/generator/gen_base.py
subversion/branches/swig-py3/build/generator/gen_vcnet_vcproj.py
subversion/branches/swig-py3/build/generator/gen_win.py
subversion/branches/swig-py3/build/generator/gen_win_dependencies.py
subversion/branches/swig-py3/build/generator/templates/vcnet_vcxproj.ezt
subversion/branches/swig-py3/gen-make.py
subversion/branches/swig-py3/subversion/bindings/swig/INSTALL
Modified: subversion/branches/swig-py3/build/generator/gen_base.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/generator/gen_base.py?rev=1822485&r1=1822484&r2=1822485&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/generator/gen_base.py (original)
+++ subversion/branches/swig-py3/build/generator/gen_base.py Mon Jan 29 00:53:54 2018
@@ -1321,7 +1321,8 @@ class IncludeDependencyInfo:
Return a dictionary with included full file names as keys and None as
values."""
hdrs = { }
- for line in fileinput.input(fname):
+
+ for line in fileinput.FileInput(fname, openhook=fileinput.hook_encoded("utf-8", "surrogateescape")):
match = self._re_include.match(line)
if not match:
continue
Modified: subversion/branches/swig-py3/build/generator/gen_vcnet_vcproj.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/generator/gen_vcnet_vcproj.py?rev=1822485&r1=1822484&r2=1822485&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/generator/gen_vcnet_vcproj.py (original)
+++ subversion/branches/swig-py3/build/generator/gen_vcnet_vcproj.py Mon Jan 29 00:53:54 2018
@@ -120,6 +120,7 @@ class Generator(gen_win.WinGeneratorBase
'instrument_purify_quantify' : self.instrument_purify_quantify,
'version' : self.vcproj_version,
'toolset_version' : 'v' + self.vcproj_version.replace('.',''),
+ 'user_macros': self.user_macros,
}
if self.vcproj_extension == '.vcproj':
Modified: subversion/branches/swig-py3/build/generator/gen_win.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/generator/gen_win.py?rev=1822485&r1=1822484&r2=1822485&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/generator/gen_win.py (original)
+++ subversion/branches/swig-py3/build/generator/gen_win.py Mon Jan 29 00:53:54 2018
@@ -158,6 +158,13 @@ class WinGeneratorBase(gen_win_dependenc
### implement this from scratch using the algorithms described in
### http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt
+ # Ensure data is in byte representation. If it doesn't have an encode
+ # attribute, assume it is already in the correct form.
+ try:
+ data = data.encode('utf8')
+ except AttributeError:
+ pass
+
myhash = hashlib_md5(data).hexdigest()
guid = ("{%s-%s-%s-%s-%s}" % (myhash[0:8], myhash[8:12],
@@ -785,6 +792,10 @@ class WinGeneratorBase(gen_win_dependenc
lang_subdir = 'perl5'
else:
lang_subdir = target.lang
+
+ if target.lang == "python":
+ lib = self._libraries['py3c']
+ fakeincludes.extend(lib.include_dirs)
# After the language specific includes include the generic libdir,
# to allow overriding a generic with a per language include
Modified: subversion/branches/swig-py3/build/generator/gen_win_dependencies.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/generator/gen_win_dependencies.py?rev=1822485&r1=1822484&r2=1822485&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/generator/gen_win_dependencies.py (original)
+++ subversion/branches/swig-py3/build/generator/gen_win_dependencies.py Mon Jan 29 00:53:54 2018
@@ -32,6 +32,7 @@ import fnmatch
import re
import subprocess
import string
+from collections import namedtuple
if sys.version_info[0] >= 3:
# Python >=3.0
@@ -46,6 +47,8 @@ else:
import gen_base
import ezt
+UserMacro = namedtuple('UserMacro', ['name', 'value'])
+
class SVNCommonLibrary:
def __init__(self, name, include_dirs, lib_dir, lib_name, version=None,
@@ -117,6 +120,7 @@ class GenDependenciesBase(gen_base.Gener
'swig',
'perl',
'python',
+ 'py3c',
'ruby',
'java_sdk',
'openssl',
@@ -146,6 +150,7 @@ class GenDependenciesBase(gen_base.Gener
self.jdk_path = None
self.junit_path = None
self.swig_path = None
+ self.py3c_path = None
self.vs_version = '2002'
self.sln_version = '7.00'
self.vcproj_version = '7.00'
@@ -165,6 +170,7 @@ class GenDependenciesBase(gen_base.Gener
self.instrument_purify_quantify = None
self.sasl_path = None
self.cpp_defines = []
+ self.user_macros = []
# NLS options
self.enable_nls = None
@@ -196,6 +202,8 @@ class GenDependenciesBase(gen_base.Gener
self.zlib_path = val
elif opt == '--with-swig':
self.swig_path = val
+ elif opt == '--with-py3c':
+ self.py3c_path = val
elif opt == '--with-sqlite':
self.sqlite_path = val
elif opt == '--with-sasl':
@@ -322,7 +330,9 @@ class GenDependenciesBase(gen_base.Gener
# Swig (optional) dependencies
if self._find_swig(show_warnings):
self._find_perl(show_warnings)
- self._find_python(show_warnings)
+ # py3c is required to build python bindings, show check it first
+ if self._find_py3c(show_warnings):
+ self._find_python(show_warnings)
self._find_ruby(show_warnings)
def _find_apr(self):
@@ -1019,10 +1029,53 @@ class GenDependenciesBase(gen_base.Gener
lib_dir = os.path.join(sysconfig.PREFIX, "libs")
except ImportError:
return
+
+ if sys.version_info[0] >= 3:
+ self.user_macros.append(UserMacro("SWIG_PY_OPTS", "-python -py3"))
+ else:
+ self.user_macros.append(UserMacro("SWIG_PY_OPTS", "-python -classic"))
self._libraries['python'] = SVNCommonLibrary('python', inc_dir, lib_dir, None,
sys.version.split(' ')[0])
+ def _find_py3c(self, show_warnings):
+ "Find the py3c library which is used in SWIG python bindings"
+ show_warnings = True
+ # Assume a default path, unless otherwise specified
+ py3c_path = "py3c"
+
+ if self.py3c_path:
+ py3c_path = self.py3c_path
+
+ py3c_path = os.path.abspath(py3c_path)
+ inc_path = os.path.join(py3c_path, 'include')
+ py3c_hdr_path = os.path.join(inc_path, 'py3c.h')
+
+ pc_path = os.path.join(py3c_path, 'py3c.pc.in')
+
+ if not os.path.isfile(py3c_hdr_path):
+ if show_warnings:
+ print('WARNING: "%s" not found' % py3c_hdr_path)
+ print('Use "--with-py3c" to configure py3c location.')
+ return False
+
+ with open(pc_path) as fp:
+ txt = fp.read()
+
+ ver_match = re.search(r'Version:\s+([0-9.]+)', txt)
+
+ if not ver_match:
+ if show_warnings:
+ print("WARNING: Failed to find version in '%s'" % pc_path)
+ return False
+
+ py3c_version = ver_match.group(1)
+
+ self._libraries['py3c'] = SVNCommonLibrary('py3c', inc_path, None,
+ None, py3c_version)
+
+ return True
+
def _find_jdk(self, show_warnings):
"Find details about an installed jdk"
@@ -1069,7 +1122,7 @@ class GenDependenciesBase(gen_base.Gener
try:
outfp = subprocess.Popen([os.path.join(jdk_path, 'bin', 'javah.exe'),
'-version'], stdout=subprocess.PIPE).stdout
- line = outfp.read()
+ line = outfp.read().decode('utf8')
if line:
vermatch = re.search(r'"(([0-9]+(\.[0-9]+)+)(_[._0-9]+)?)"', line, re.M)
else:
@@ -1127,7 +1180,7 @@ class GenDependenciesBase(gen_base.Gener
try:
fp = subprocess.Popen([self.swig_exe, '-version'],
stdout=subprocess.PIPE).stdout
- txt = fp.read()
+ txt = fp.read().decode('utf8')
if txt:
vermatch = re.search(r'^SWIG\ Version\ (\d+)\.(\d+)\.(\d+)', txt, re.M)
else:
@@ -1155,7 +1208,7 @@ class GenDependenciesBase(gen_base.Gener
try:
fp = subprocess.Popen([self.swig_exe, '-swiglib'],
stdout=subprocess.PIPE).stdout
- lib_dir = fp.readline().strip()
+ lib_dir = fp.readline().decode('utf8').strip()
fp.close()
except OSError:
lib_dir = None
Modified: subversion/branches/swig-py3/build/generator/templates/vcnet_vcxproj.ezt
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/generator/templates/vcnet_vcxproj.ezt?rev=1822485&r1=1822484&r2=1822485&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/generator/templates/vcnet_vcxproj.ezt (original)
+++ subversion/branches/swig-py3/build/generator/templates/vcnet_vcxproj.ezt Mon Jan 29 00:53:54 2018
@@ -43,7 +43,9 @@
[for platforms][for configs] <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='[configs.name]|[platforms]'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
-[end][end] <PropertyGroup Label="UserMacros" />
+[end][end] <PropertyGroup Label="UserMacros">
+[for user_macros] <[user_macros.name]>[user_macros.value]</[user_macros.name]>
+[end] </PropertyGroup>
[for platforms][for configs] <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='[configs.name]|[platforms]'">
<OutDir>$(SolutionDir)[configs.name]\[target.output_dir]\</OutDir>
<IntDir>$(SolutionDir)[configs.name]\obj\[target.intermediate_dir]\[target.proj_name]\</IntDir>
Modified: subversion/branches/swig-py3/gen-make.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/gen-make.py?rev=1822485&r1=1822484&r2=1822485&view=diff
==============================================================================
--- subversion/branches/swig-py3/gen-make.py (original)
+++ subversion/branches/swig-py3/gen-make.py Mon Jan 29 00:53:54 2018
@@ -176,6 +176,8 @@ def _usage_exit(err=None):
print("")
print(" --with-swig=DIR")
print(" look for the swig program in DIR")
+ print(" --with-py3c=DIR")
+ print(" look for the py3c library in DIR")
print("")
print(" --with-sqlite=DIR")
print(" look for sqlite in DIR")
@@ -252,6 +254,7 @@ if __name__ == '__main__':
'with-jdk=',
'with-junit=',
'with-swig=',
+ 'with-py3c=',
'with-sqlite=',
'with-sasl=',
'with-apr_memcache=',
Modified: subversion/branches/swig-py3/subversion/bindings/swig/INSTALL
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/INSTALL?rev=1822485&r1=1822484&r2=1822485&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/INSTALL (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/INSTALL Mon Jan 29 00:53:54 2018
@@ -237,6 +237,9 @@ BUILDING SWIG BINDINGS FOR SVN ON WINDOW
http://www.python.org/
http://www.activestate.com/ActivePerl/
+ If you plan to build python bindings, you will also need to download and
+ extract the py3c library from https://github.com/encukou/py3c/releases.
+
NOTE: Our Python SWIG bindings will currently NOT compile in Debug mode
unless you have python24_d.lib (which binary distributions of
Python do not contain). Therefore, the Python bindings will only
@@ -252,6 +255,11 @@ BUILDING SWIG BINDINGS FOR SVN ON WINDOW
Example:
> gen-make.py <other options> --with-swig="C:\Program Files\SWIG-2.0.2"
+
+ If you are building python bindings, point to the py3c directory as well:
+
+ > gen-make.py <other options> --with-swig="C:\Program Files\SWIG-2.0.2" \
+ --with-py3c="C:\SVN\py3c"
4. If you haven't already built Subversion, you should do so now.
Instructions are in the main INSTALL file.