-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- python -*- | ||
|
||
import lsst.sconsUtils | ||
import re | ||
import os.path | ||
import subprocess | ||
|
||
dependencies = {} | ||
|
||
class Configuration(lsst.sconsUtils.Configuration): | ||
|
||
def __init__(self): | ||
self.name, self.root = self.parseFilename(__file__) | ||
|
||
@staticmethod | ||
def _get_config_var(name): | ||
"""The relevant Python is not guaranteed to be the Python | ||
that we are using to run SCons so we must shell out to the | ||
PATH python.""" | ||
pycmd = 'import distutils.sysconfig as s; print(s.get_config_var("{}"))'.format(name) | ||
result = subprocess.check_output(["python", "-c", pycmd]).decode().strip() | ||
# Be consistent with native interface | ||
if result == "None": | ||
result = None | ||
return result | ||
|
||
def configure(self, conf, packages, check=False, build=True): | ||
lsst.sconsUtils.log.info("Configuring package '%s'." % self.name) | ||
conf.env.AppendUnique(XCPPPATH=self._get_config_var("CONFINCLUDEPY").split()) | ||
libDir = self._get_config_var("LIBPL") | ||
conf.env.AppendUnique(LIBPATH=[libDir]) | ||
pylibrary = self._get_config_var("LIBRARY") | ||
mat = re.search("(python.*)\.(a|so|dylib)$", pylibrary) | ||
if mat: | ||
conf.env.libs["python"].append(mat.group(1)) | ||
lsst.sconsUtils.log.info("Adding '%s' to target 'python'." % mat.group(1)) | ||
for w in (" ".join([self._get_config_var("MODLIBS"), | ||
self._get_config_var("SHLIBS")])).split(): | ||
mat = re.search(r"^-([Ll])(.*)", w) | ||
if mat: | ||
lL = mat.group(1) | ||
arg = mat.group(2) | ||
if lL == "l": | ||
if not arg in conf.env.libs: | ||
conf.env.libs["python"].append(arg) | ||
lsst.sconsUtils.log.info("Adding '%s' to target 'python'." % arg) | ||
else: | ||
if os.path.isdir(arg): | ||
conf.env.AppendUnique(LIBPATH=[arg]) | ||
lsst.sconsUtils.log.info("Adding '%s' to link path." % arg) | ||
if conf.env['PLATFORM'] == 'darwin': | ||
frameworkDir = libDir # search up the libDir tree for the proper home for frameworks | ||
while frameworkDir and not re.match("^//*$", frameworkDir): | ||
frameworkDir, d2 = os.path.split(frameworkDir) | ||
if d2 == "Python.framework": | ||
if not "Python" in os.listdir(os.path.join(frameworkDir, d2)): | ||
lsst.sconUtils.log.warn( | ||
"Expected to find Python in framework directory %s, but it isn't there" | ||
% frameworkDir | ||
) | ||
return False | ||
break | ||
opt = "-F%s" % frameworkDir | ||
if opt not in conf.env["LDMODULEFLAGS"]: | ||
conf.env.Append(LDMODULEFLAGS = [opt,]) | ||
return True | ||
|
||
config = Configuration() |