Skip to content
Snippets Groups Projects
Commit 6a2c9179 authored by AlQuemist's avatar AlQuemist
Browse files

mac_package: modify Settings class for the Python-wheel mode

parent 0e9faa40
No related branches found
No related tags found
3 merge requests!2050rebase main on r21/v21.1,!2047<root>/CMakeLists.txt: add 'BornAgain_LIBRARIES' cached variable to store...,!2029Fix MacOS packaging scripts for r21.1
......@@ -408,9 +408,14 @@ class Settings:
# Python-related variables
PyInfo = namedtuple("PythonInfo", ["dir", "lib", "version", "rpaths"])
def __init__(self, pkg_root, main_exe_src,
qt_framework_root, qt_framework_plugins_dir, qt_plugins_dir):
def __init__(self, pkg_root,
main_exe_src, core_libs, extra_libs,
python_mode, pkg_py_root_dir, pkg_py_lib_dir, pkg_py_extra_lib_dir,
qt_framework_root, qt_framework_plugins_dir, qt_plugins_dir, qt_plugins):
# map {reference/abs. path => LibraryFile}
self.libs = dict()
# package-related directories
fwdir = "Frameworks"
self.dirs = {
#-- absolute paths
......@@ -426,16 +431,30 @@ class Settings:
"FW_qt_plugin": qt_plugins_dir, # Qt plugins dir
}
# map {reference/abs. path => LibraryFile}
self.libs = dict()
# main executable
if main_exe_src:
# Python-package mode
self.python_mode = bool(python_mode)
if self.python_mode:
self.dirs['root'] = pkg_py_root_dir
self.dirs['corelib'] = removeprefix(pkg_py_lib_dir, pkg_py_root_dir + '/')
core_libs.extend(find_dylibs(pkg_py_lib_dir))
self.dirs['exlib'] = removeprefix(pkg_py_extra_lib_dir, pkg_py_root_dir + '/')
extra_libs.extend(find_dylibs(pkg_py_extra_lib_dir))
else:
# main executable
_main_exe_dst = self.dirs['root'] + '/' + self.dirs['exe'] \
+ '/' + os.path.basename(main_exe_src)
self.libs = {main_exe_src:
LibraryFile(dtype='main_exe', src=main_exe_src, dst=_main_exe_dst)}
# initial libraries
self.libs_init = tuple()
#-- Qt plugins
self.libs.update({self.dirs['qt_root_plugins_dir'] + '/' + l:
LibraryFile(dtype='plugin_qt', src=l) for l in qt_plugins})
# core libraries
self.libs.update({l: LibraryFile(dtype='core_lib', src=l) for l in set(core_libs)})
# extra libraries
self.libs.update({l: LibraryFile(dtype='extra_lib', src=l) for l in set(extra_libs)})
# all initial libraries
self.libs_init = tuple(self.libs.keys())
# map {source-path => destination-path}
self.src_dst_tbl = dict()
# map {source-path => destination-path}
......@@ -682,12 +701,26 @@ class Settings:
#------------------------------------------------------------------------------80
_core_libs = "@MACPKG_CORE_LIBS@" # core libraries and executables
_extra_libs = "@MACPKG_EXTRA_LIBS@"
main_exe_src = "@MACPKG_MAIN_EXE@"
pkg_root = os.path.dirname(sys.argv[1] + '/') # root dir, eg. '/tmp/bornagain.app/Contents'
core_libs = splat(_core_libs, ';')
_extra_libs = "@MACPKG_EXTRA_LIBS@"
extra_libs = splat(_extra_libs, ';')
main_exe_src = "@MACPKG_MAIN_EXE@"
pkg_root = ""
if len(sys.argv) > 1:
# root dir, eg. '/tmp/bornagain.app/Contents'
pkg_root = os.path.dirname(sys.argv[1] + '/')
# Python-related variables
python_mode = bool("@BA_PY_MODE@")
python_exe = "@__Py3_EXECUTABLE@"
pkg_py_output_dir = os.path.dirname("@BA_PY_OUTPUT_DIR@/")
pkg_py_root_dir = os.path.dirname("@BA_PY_INIT_OUTPUT_DIR@/")
pkg_py_lib_dir = os.path.dirname("@BA_PY_LIBRARY_OUTPUT_DIR@/")
pkg_py_extra_lib_dir = os.path.dirname("@BA_PY_EXTRA_LIBRARY_OUTPUT_DIR@/")
pkg_py_wheel_dir = os.path.dirname("@BA_PY_PACKAGE_WHEEL_DIR@/")
# Qt-related variables
# eg. input Qt dir = '/usr/local/opt/qt@5/lib/cmake/Qt'
# => '/usr/local/opt/qt@5'
qtdir = "@Qt_DIR@/"
......@@ -698,41 +731,52 @@ qt_framework_plugins_dir = os.path.dirname(qt_framework_root + '/' + qt_plugins_
# list of required Qt plugins
_qt_plugins = "@MACPKG_QT_PLUGINS@"
qt_plugins_dir = "@MACPKG_QT_PLUGINS_DIR@"
qt_plugins = splat(_qt_plugins, ';')
qt_plugins_dir = "@MACPKG_QT_PLUGINS_DIR@/"
if python_mode:
if not python_exe:
raise ValueError("%s: Error: Provide the Python executable." % TITLE)
if not pkg_root:
raise ValueError("%s: Error: Provide the root directory of the package." % TITLE)
if not pkg_py_root_dir:
raise ValueError("%s: Error: Provide the root directory of the Python package." % TITLE)
if not main_exe_src:
raise ValueError("%s: Error: Main executable does not exist." % TITLE)
if not extra_libs:
core_libs = find_dylibs(pkg_py_lib_dir)
pkg_root = pkg_py_root_dir
else:
if not pkg_root:
raise ValueError("%s: Error: Provide the root directory of the package." % TITLE)
if not core_libs:
raise ValueError("%s: Error: Provide the core libraries of the package." % TITLE)
if not main_exe_src:
raise ValueError("%s: Error: Main executable does not exist." % TITLE)
if not qt_framework_root:
raise ValueError("%s: Error: Provide the root directory of the Qt framework." % TITLE)
#------------------------------------------------------------------------------80
print("-- Package variables --")
print("%s: package root = '%s'" % (TITLE, pkg_root))
print("%s: main executable = '%s'" % (TITLE, main_exe_src))
print("%s: core libraries = '%s'" % (TITLE, core_libs))
print("%s: extra libraries = '%s'" % (TITLE, extra_libs))
print("-- Python")
print("%s: Python mode = %s" % (TITLE, python_mode))
print("%s: Python executable = '%s'" % (TITLE, python_exe))
print("%s: Python package root dir = '%s'" % (TITLE, pkg_py_root_dir))
print("%s: Python package libraries dir = '%s'" % (TITLE, pkg_py_lib_dir))
print("%s: Python package extra libraries dir = '%s'" % (TITLE, pkg_py_extra_lib_dir))
print("%s: Python wheel dir = '%s'" % (TITLE, pkg_py_wheel_dir))
print("-- Qt")
print("%s: Qt framework root = '%s'" % (TITLE, qt_framework_root))
print("%s: Qt plugings dir = '%s'" % (TITLE, qt_plugins_dir))
print("%s: Qt plugings = '%s'" % (TITLE, qt_plugins))
print("-----------------------")
#-- package definition
pkg = Settings(pkg_root, main_exe_src,
qt_framework_root, qt_framework_plugins_dir, qt_plugins_dir)
#-- core libraries
pkg.libs.update({l: LibraryFile(dtype='core_lib', src=l) for l in core_libs})
#-- extra libraries
pkg.libs.update({l: LibraryFile(dtype='extra_lib', src=l) for l in extra_libs})
#-- copy Qt plugins to the corresponding dir
pkg.libs.update({pkg.dirs['qt_root_plugins_dir'] + '/' + l:
LibraryFile(dtype='plugin_qt', src=l) for l in qt_plugins})
#-- collect a list of binaries plus those which are already placed in the package
pkg.libs_init = tuple(pkg.libs.keys())
pkg = Settings(pkg_root,
main_exe_src, core_libs, extra_libs,
python_mode, pkg_py_root_dir, pkg_py_lib_dir, pkg_py_extra_lib_dir,
qt_framework_root, qt_framework_plugins_dir, qt_plugins_dir, qt_plugins)
#-- print package information
print("\n%s: package directories:" % TITLE)
......@@ -744,8 +788,9 @@ for fnm in pkg.libs_init:
# eg., '+ lib/libA.dylib'
print(" + '%s'" % removeprefix(fnm, pkg.dirs['root'] + '/'))
#-- find the dependencies of the binaries
print()
#-- find the dependencies of the binaries
pkg.libs = Settings.dependencies(pkg.libs, pkg.dirs, pkg.libs_init, level_max=10)
#-- determine the destination of libraries in the package
......@@ -833,7 +878,7 @@ for lib in pkg.dst_tbl.values():
print("%s: Command failed: %s" % (TITLE, _prc.args))
#-- make Python wheel (when in Python mode)
if Settings.python_mode:
if pkg.python_mode:
print("%s: creating Python wheel in '%s'..." % (TITLE, pkg_py_wheel_dir))
print(" Python executable = '%s'" % python_exe)
PythonFramework.make_wheel(python_exe, pkg_py_output_dir, pkg_py_wheel_dir)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment