Skip to content

Commit

Permalink
Fix sometimes PCH uninstall issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Jul 19, 2021
1 parent 76f6b30 commit 5461778
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ master: 2.2.0
-------------

* Migrated repos to github/wlav
* Fix sometimes PCH uninstall issue


2021-07-17: 2.1.0
Expand Down
14 changes: 10 additions & 4 deletions python/cppyy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@
import ctypes, os, sys, sysconfig, warnings

if not 'CLING_STANDARD_PCH' in os.environ:
local_pch = os.path.join(os.path.dirname(__file__), 'allDict.cxx.pch')
if os.path.exists(local_pch):
os.putenv('CLING_STANDARD_PCH', local_pch)
os.environ['CLING_STANDARD_PCH'] = local_pch
def _set_pch():
try:
import cppyy_backend as cpb
local_pch = os.path.join(os.path.dirname(__file__), 'allDict.cxx.pch.'+str(cpb.__version__))
if os.path.exists(local_pch):
os.putenv('CLING_STANDARD_PCH', local_pch)
os.environ['CLING_STANDARD_PCH'] = local_pch
except (ImportError, AttributeError):
pass
_set_pch(); del _set_pch

try:
import __pypy__
Expand Down
36 changes: 23 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,39 @@ def find_version(*file_paths):
# customized commands
#
class my_install(_install):
def __init__(self, *args, **kwds):
super(_install, self).__init__(*args, **kwds)
try:
import cppyy_backend as cpb
self._pchname = 'allDict.cxx.pch.' + str(cpb.__version__)
except (ImportError, AttributeError):
self._pchname = None

def run(self):
# base install
_install.run(self)

# force build of the .pch underneath the cppyy package if not available yet
install_path = os.path.join(os.getcwd(), self.install_libbase, 'cppyy')

try:
import cppyy_backend as cpb
if not os.path.exists(os.path.join(cpb.__file__, 'etc', 'allDict.cxx.pch')):
log.info("installing pre-compiled header in %s", install_path)
cpb.loader.set_cling_compile_options(True)
cpb.loader.ensure_precompiled_header(install_path, 'allDict.cxx.pch')
except (ImportError, AttributeError):
# ImportError may occur with wrong pip requirements resolution (unlikely)
# AttributeError will occur with (older) PyPy as it relies on older backends
pass
if self._pchname:
try:
import cppyy_backend as cpb
if not os.path.exists(os.path.join(cpb.__file__, 'etc', self._pchname)):
log.info("installing pre-compiled header in %s", install_path)
cpb.loader.set_cling_compile_options(True)
cpb.loader.ensure_precompiled_header(install_path, self._pchname)
except (ImportError, AttributeError):
# ImportError may occur with wrong pip requirements resolution (unlikely)
# AttributeError will occur with (older) PyPy as it relies on older backends
self._pchname = None

def get_outputs(self):
outputs = _install.get_outputs(self)
# pre-emptively add allDict.cxx.pch, which may or may not be created; need full
# path to make sure the final relative path is correct
outputs.append(os.path.join(os.getcwd(), self.install_libbase, 'cppyy', 'allDict.cxx.pch'))
if self._pchname:
# pre-emptively add allDict.cxx.pch, which may or may not be created; need full
# path to make sure the final relative path is correct
outputs.append(os.path.join(os.getcwd(), self.install_libbase, 'cppyy', self._pchname))
return outputs


Expand Down

0 comments on commit 5461778

Please sign in to comment.