Skip to content

Commit 5bf6250

Browse files
committed
[setup] init LD_LIBRARY_PATH in cx_Freeze
As it cannot be modified later in python.
1 parent c073b76 commit 5bf6250

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

meshroom/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ def setupEnvironment():
2727
2828
- Meshroom/
2929
- aliceVision/
30-
- bin/ # runtime bundled binaries (exe + libs)
30+
- bin/ # runtime bundled binaries (windows: exe + libs, unix: executables)
31+
- lib/ # runtime bundled libraries (unix: libs)
3132
- share/ # resource files
32-
- COPYING.md # AliceVision COPYING file
33-
- cameraSensors.db # sensor database
34-
- vlfeat_K80L3.tree # voctree file
33+
- aliceVision/
34+
- COPYING.md # AliceVision COPYING file
35+
- cameraSensors.db # sensor database
36+
- vlfeat_K80L3.tree # voctree file
3537
- lib/ # Python lib folder
3638
- qtPlugins/
3739
Meshroom # main executable
@@ -58,28 +60,24 @@ def addToEnvPath(var, val, index=-1):
5860
paths[index:index] = val
5961
os.environ[var] = os.pathsep.join(paths)
6062

61-
# detect if this is a frozen environment based on executable name
62-
isStandalone = "python" not in os.path.basename(sys.executable).lower()
63+
# sys.frozen is initialized by cx_Freeze
64+
isFrozen = getattr(sys, "frozen", False)
6365
# setup root directory (override possible by setting "MESHROOM_INSTALL_DIR" environment variable)
64-
rootDir = os.path.dirname(sys.executable) if isStandalone else os.environ.get("MESHROOM_INSTALL_DIR", None)
66+
rootDir = os.path.dirname(sys.executable) if isFrozen else os.environ.get("MESHROOM_INSTALL_DIR", None)
6567

6668
if rootDir:
6769
os.environ["MESHROOM_INSTALL_DIR"] = rootDir
6870

6971
aliceVisionDir = os.path.join(rootDir, "aliceVision")
7072
# default directories
7173
aliceVisionBinDir = os.path.join(aliceVisionDir, "bin")
72-
aliceVisionLibDirs = [os.path.join(aliceVisionDir, "lib64"), os.path.join(aliceVisionDir, "lib")] # Unix
7374
aliceVisionShareDir = os.path.join(aliceVisionDir, "share", "aliceVision")
7475
qtPluginsDir = os.path.join(rootDir, "qtPlugins")
7576
sensorDBPath = os.path.join(aliceVisionShareDir, "cameraSensors.db")
7677
voctreePath = os.path.join(aliceVisionShareDir, "vlfeat_K80L3.tree")
77-
# Unix: "lib" contains shared libraries that needs to be in LD_LIBRARY_PATH
78-
libDir = os.path.join(rootDir, "lib")
7978

8079
env = {
8180
'PATH': aliceVisionBinDir,
82-
'LD_LIBRARY_PATH': [libDir] + aliceVisionLibDirs, # Unix
8381
'QT_PLUGIN_PATH': [qtPluginsDir],
8482
'QML2_IMPORT_PATH': [os.path.join(qtPluginsDir, "qml")]
8583
}

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(self, script, initScript=None, base=None, targetName=None, icons=No
3131
targetName += PlatformExecutable.exeExtensions[platform.system()]
3232
# get icon for platform if defined
3333
icon = icons.get(platform.system(), None) if icons else None
34+
if platform.system() in (self.Linux, self.Darwin):
35+
currentDir = os.path.dirname(os.path.abspath(__file__))
36+
initScript = os.path.join(currentDir, "setupInitScriptUnix.py")
3437
super(PlatformExecutable, self).__init__(script, initScript, base, targetName, icon, shortcutName,
3538
shortcutDir, copyright, trademarks)
3639

setupInitScriptUnix.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#------------------------------------------------------------------------------
2+
# ConsoleSetLibPath.py
3+
# Initialization script for cx_Freeze which manipulates the path so that the
4+
# directory in which the executable is found is searched for extensions but
5+
# no other directory is searched. The environment variable LD_LIBRARY_PATH is
6+
# manipulated first, however, to ensure that shared libraries found in the
7+
# target directory are found. This requires a restart of the executable because
8+
# the environment variable LD_LIBRARY_PATH is only checked at startup.
9+
#------------------------------------------------------------------------------
10+
11+
import os
12+
import sys
13+
import zipimport
14+
15+
FILE_NAME = sys.executable
16+
DIR_NAME = os.path.dirname(sys.executable)
17+
18+
paths = os.environ.get("LD_LIBRARY_PATH", "").split(os.pathsep)
19+
20+
if DIR_NAME not in paths:
21+
paths.insert(0, DIR_NAME)
22+
paths.insert(0, os.path.join(DIR_NAME, "lib"))
23+
paths.insert(0, os.path.join(DIR_NAME, "aliceVision", "lib"))
24+
paths.insert(0, os.path.join(DIR_NAME, "aliceVision", "lib64"))
25+
26+
os.environ["LD_LIBRARY_PATH"] = os.pathsep.join(paths)
27+
os.execv(sys.executable, sys.argv)
28+
29+
sys.frozen = True
30+
sys.path = sys.path[:4]
31+
32+
33+
def run():
34+
m = __import__("__main__")
35+
importer = zipimport.zipimporter(os.path.dirname(os.__file__))
36+
name, ext = os.path.splitext(os.path.basename(os.path.normcase(FILE_NAME)))
37+
moduleName = "%s__main__" % name
38+
code = importer.get_code(moduleName)
39+
exec(code, m.__dict__)
40+

0 commit comments

Comments
 (0)