Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-8467: Wrap lsst_distrib with pybind11 #28

Merged
merged 3 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/lsst/sconsUtils/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ def SwigLoadableModule(self, target, source, **keywords):
pass
return myenv.LoadableModule(target, source, **keywords)

# @brief Like LoadableModule, but don't insist that all symbols are resolved, and set
# some pybind11-specific flags.
@memberOf(SConsEnvironment)
def Pybind11LoadableModule(self, target, source, **keywords):
myenv = self.Clone()
if myenv['PLATFORM'] == 'darwin':
myenv.Append(LDMODULEFLAGS=["-undefined", "suppress",
"-flat_namespace", "-headerpad_max_install_names"])
return myenv.LoadableModule(target, source, **keywords)

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Expand Down
47 changes: 46 additions & 1 deletion python/lsst/sconsUtils/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ def initialize(cls, packageName, versionString=None, eupsProduct=None, eupsProdu
scripts.append(os.path.join(root, "SConscript"))
if sconscriptOrder is None:
sconscriptOrder = ("lib", "python", "tests", "examples", "doc")

def key(path):
for i, item in enumerate(sconscriptOrder):
if path.startswith(item):
if path.lstrip("./").startswith(item):
return i
return len(sconscriptOrder)
scripts.sort(key=key)
Expand Down Expand Up @@ -306,6 +307,8 @@ def rewrite_shebang(target, source, env):
# to our current pseudo-convention: last part of env["packageName"], split by underscores,
# with "Lib" appended to the end.
#
# @return A list of SwigLoadableModule elements.
#
# @param swigNameList Sequence of SWIG modules to be built (does not include the file extensions).
# @param libs Libraries to link against, either as a string argument to be passed to
# env.getLibs() or a sequence of actual libraries to pass in.
Expand All @@ -332,6 +335,48 @@ def python(swigNameList=None, libs="main python", swigSrc=None):
state.targets["python"].extend(result)
return result

##
# @brief Convenience function to replace standard python/*/SConscript boilerplate.
#
# @return A list of Pybind11LoadableModule elements.
#
# @param nameList Sequence of pybind11 modules to be built (does not include the file extensions).
# @param libs Libraries to link against, either as a string argument to be passed to
# env.getLibs() or a sequence of actual libraries to pass in.
# @param extraSrc A dictionary of additional source files that go into the modules. Each
# key should be an entry in nameList, and each value should be a list
# of additional C++ source files.
# @param addUnderscore Add an underscore to each library name (if the source file name
# does not already start with underscore)? If false the library name
# is always the same as the source file name
# DEPRECATED: always use False for new code.
##
@staticmethod
def pybind11(nameList=[], libs="main python", extraSrc=None, addUnderscore=True):
srcList = extraSrc
if srcList is None:
srcList = dict([(name, []) for name in nameList])
for name in nameList:
srcList[name].append(name + ".cc")
if isinstance(libs, basestring):
libs = state.env.getLibs(libs)
elif libs is None:
libs = []
result = []
for name in nameList:
# TODO remove this block and the `addUnderscore` argument and always use pyLibName = name;
# but we can't do that until all our pybind11 SConscript files have been converted
if addUnderscore:
if name.startswith("_"):
pyLibName = name
else:
pyLibName = "_" + name
else:
pyLibName = name
result.extend(state.env.Pybind11LoadableModule(pyLibName, srcList[name], LIBS=libs))
state.targets["python"].extend(result)
return result

##
# @brief Convenience function to replace standard doc/SConscript boilerplate.
#
Expand Down