Skip to content

Commit f979b97

Browse files
rmsdsadamjstewart
authored andcommitted
GDL: python integration fixes (#9936)
* GDL: python integration fixes * renamed python-related variants to follow the convention * building the Python module requires patches currently targetting 0.9.8 othwerwise asking for the Python module *only* builds the Pyhton module * building the python module also requires patching the vendored (with the GDL) antlr to be built as a shared library * Typo Co-Authored-By: rmsds <[email protected]> * Rename embed-python variant to embed_python
1 parent a02cf10 commit f979b97

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From: Ricardo Silva <[email protected]>
2+
Date: Wed, 3 Oct 2018 13:42:25 +0200
3+
Subject: [PATCH] Always build antlr as shared library
4+
5+
---
6+
src/antlr/CMakeLists.txt | 8 ++------
7+
1 file changed, 2 insertions(+), 6 deletions(-)
8+
9+
diff --git a/src/antlr/CMakeLists.txt b/src/antlr/CMakeLists.txt
10+
index 26a38e3..083e50d 100644
11+
--- a/src/antlr/CMakeLists.txt
12+
+++ b/src/antlr/CMakeLists.txt
13+
@@ -2,9 +2,5 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} ANTLRSOURCES)
14+
list(REMOVE_ITEM ANTLRSOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dll.cpp)
15+
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/antlr)
16+
17+
-if(PYTHON_MODULE)
18+
- add_library(antlr SHARED ${ANTLRSOURCES})
19+
- install(TARGETS antlr DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
20+
-else(PYTHON_MODULE)
21+
- add_library(antlr STATIC ${ANTLRSOURCES})
22+
-endif(PYTHON_MODULE)
23+
+add_library(antlr SHARED ${ANTLRSOURCES})
24+
+install(TARGETS antlr DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
25+
--
26+
1.8.3.1
27+

var/spack/repos/builtin/packages/gdl/package.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Spack Project Developers. See the top-level COPYRIGHT file for details.
33
#
44
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
5-
5+
import os
66
from spack import *
77

88

@@ -27,7 +27,8 @@ class Gdl(CMakePackage):
2727
variant('hdf5', default=True, description='Enable HDF5')
2828
variant('openmp', default=True, description='Enable OpenMP')
2929
variant('proj', default=True, description='Enable LIBPROJ4')
30-
variant('python', default=False, description='Enable Python')
30+
variant('embed_python', default=False, description='Ability to embed Python within GDL')
31+
variant('python', default=False, description='Build the GDL Python module')
3132
variant('wx', default=False, description='Enable WxWidgets')
3233
variant('x11', default=False, description='Enable X11')
3334

@@ -41,8 +42,8 @@ class Gdl(CMakePackage):
4142
depends_on('plplot+wx+wxold', when='[email protected]:')
4243
depends_on('plplot~wx', when='~wx')
4344
depends_on('proj', when='+proj')
44-
depends_on('py-numpy', type=('build', 'run'), when='+python')
45-
depends_on('[email protected]:2.8', type=('build', 'run'), when='+python')
45+
depends_on('py-numpy', type=('build', 'run'), when='+embed_python')
46+
depends_on('[email protected]:2.8', type=('build', 'run'), when='+embed_python')
4647
depends_on('wx', when='+wx')
4748

4849
depends_on('eigen')
@@ -57,6 +58,21 @@ class Gdl(CMakePackage):
5758
depends_on('pslib')
5859
depends_on('readline')
5960

61+
conflicts('+python', when='~embed_python')
62+
63+
# Building the Python module requires patches currently targetting 0.9.8
64+
# othwerwise asking for the Python module *only* builds the Python module
65+
conflicts('+python', when='@:0.9.7,0.9.9:')
66+
67+
# Allows building gdl as a shared library to in turn allow building
68+
# both the executable and the Python module
69+
patch('https://sources.debian.org/data/main/g/gnudatalanguage/0.9.8-7/debian/patches/Create-a-shared-library.patch',
70+
sha256='bb380394c8ea2602404d8cd18047b93cf00fdb73b83d389f30100dd4b0e1a05c',
71+
when='@0.9.8')
72+
patch('Always-build-antlr-as-shared-library.patch',
73+
sha256='f40c06e8a8f1977780787f58885590affd7e382007cb677d2fb4723aaadd415c',
74+
when='@0.9.8')
75+
6076
def cmake_args(self):
6177
args = []
6278

@@ -92,11 +108,16 @@ def cmake_args(self):
92108
else:
93109
args += ['-DLIBPROJ4=OFF']
94110

95-
if '+python' in self.spec:
111+
if '+embed_python' in self.spec:
96112
args += ['-DPYTHON=ON']
97113
else:
98114
args += ['-DPYTHON=OFF']
99115

116+
if '+python' in self.spec:
117+
args += ['-DPYTHON_MODULE=ON']
118+
else:
119+
args += ['-DPYTHON_MODULE=OFF']
120+
100121
if '+wx' in self.spec:
101122
args += ['-DWXWIDGETS=ON']
102123
else:
@@ -108,3 +129,19 @@ def cmake_args(self):
108129
args += ['-DX11=OFF']
109130

110131
return args
132+
133+
@run_after('install')
134+
def post_install(self):
135+
if '+python' in self.spec:
136+
# gdl installs the python module into prefix/lib/site-python
137+
# move it to the standard location
138+
src = os.path.join(
139+
self.spec.prefix.lib,
140+
'site-python')
141+
dst = site_packages_dir
142+
if os.path.isdir(src):
143+
if not os.path.isdir(dst):
144+
mkdirp(dst)
145+
for f in os.listdir(src):
146+
os.rename(os.path.join(src, f),
147+
os.path.join(dst, f))

0 commit comments

Comments
 (0)