Skip to content

Commit 1124d08

Browse files
committed
Backport extra patches in GeosLibrary from develop branch
1 parent 5b879d4 commit 1124d08

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

packages/basemap/utils/GeosLibrary.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import io
2222
import os
23+
import sys
2324
import ssl
2425
import glob
2526
import shutil
@@ -126,8 +127,7 @@ def extract(self, overwrite=True):
126127
if os.path.exists(zipfold):
127128
if not overwrite:
128129
raise OSError("folder '{0}' already exists".format(zipfold))
129-
else:
130-
shutil.rmtree(zipfold)
130+
shutil.rmtree(zipfold)
131131

132132
# Decompress zip file.
133133
with contextlib.closing(ZipFile(zippath, "r")) as fd:
@@ -156,6 +156,27 @@ def extract(self, overwrite=True):
156156
for line in lines:
157157
fd.write(line.replace(oldtext, newtext).encode())
158158

159+
# Apply specific patches for 3.6.0 <= GEOS < 3.7.0 on Windows.
160+
if (3, 6, 0) <= self.version_tuple < (3, 7, 0) and os.name == "nt":
161+
autogen_file = os.path.join(zipfold, "autogen.bat")
162+
subprocess.call([autogen_file], cwd=zipfold)
163+
cppfile = os.path.join(zipfold, "src", "geomgraph", "DirectedEdgeStar.cpp")
164+
with io.open(cppfile, "r", encoding="utf-8") as fd:
165+
lines = fd.readlines()
166+
with io.open(cppfile, "wb") as fd:
167+
oldtext = "DirectedEdgeStar::print() const"
168+
newtext = oldtext.replace(" const", "")
169+
for line in lines:
170+
fd.write(line.replace(oldtext, newtext).encode())
171+
hfile = os.path.join(zipfold, "include", "geos", "geomgraph", "DirectedEdgeStar.h")
172+
with io.open(hfile, "r", encoding="utf-8") as fd:
173+
lines = fd.readlines()
174+
with io.open(hfile, "wb") as fd:
175+
oldtext = "virtual std::string print() const;"
176+
newtext = oldtext.replace(" const", "")
177+
for line in lines:
178+
fd.write(line.replace(oldtext, newtext).encode())
179+
159180
# Patch CMakeLists to link shared geos_c with static geos.
160181
if self.version_tuple < (3, 8, 0):
161182
cmakefile = os.path.join(zipfold, "capi", "CMakeLists.txt")
@@ -221,16 +242,17 @@ def build(self, installdir=None, njobs=1):
221242

222243
# Define custom configure and build options.
223244
if os.name == "nt":
224-
if version < (3, 6, 0):
245+
if version >= (3, 6, 0) and sys.version_info[:2] >= (3, 3):
246+
build_opts = ["-j", "{0:d}".format(njobs)] + build_opts
247+
else:
225248
win64 = (8 * struct.calcsize("P") == 64)
226249
config_opts = ["-G", "NMake Makefiles"] + config_opts
227250
build_opts.extend([
228251
"--",
229252
"WIN64={0}".format("YES" if win64 else "NO"),
230253
"BUILD_BATCH={0}".format("YES" if njobs > 1 else "NO"),
254+
"MSVC_VER=1400",
231255
])
232-
else:
233-
build_opts = ["-j", "{0:d}".format(njobs)] + build_opts
234256
else:
235257
build_env["MAKEFLAGS"] = "-j {0:d}".format(njobs)
236258
if version >= (3, 7, 0):

0 commit comments

Comments
 (0)