summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean@guyomarch.bzh>2016-05-29 14:54:36 +0200
committerJean Guyomarc'h <jean@guyomarch.bzh>2016-05-29 17:17:54 +0200
commit5d8f717c327514c863bfcc072a15b5c4e26b8887 (patch)
treeb0664a151c73a2651ac0452af11c3aa2f38fe039
parent3ba3d6b74036f538d25465e6f9507fe32defdbbd (diff)
packager: add prefix-awareness
So long, hard-coded paths.
-rwxr-xr-xpackage_osx.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/package_osx.py b/package_osx.py
index 0611f62..ebe857a 100755
--- a/package_osx.py
+++ b/package_osx.py
@@ -14,6 +14,23 @@ import argparse
14import shutil 14import shutil
15import xml.etree.ElementTree as ET 15import xml.etree.ElementTree as ET
16 16
17def which(prog):
18 return subprocess.check_output(["which", prog]).strip()
19
20def prefix_get(prog):
21 binary = which(prog)
22 if binary is None:
23 raise RuntimeError("Could not find {0}".format(prog))
24 paths = binary.split('/')
25 prefix = ""
26
27 for p in range(1, len(paths) - 2):
28 prefix = prefix + '/' + paths[p]
29 return prefix
30
31def config_prefix_get(config):
32 return prefix_get(config["EXEC_NAME"])
33
17def setDefaultOptions(config): 34def setDefaultOptions(config):
18 def setDefaultOpt(config, name, value): 35 def setDefaultOpt(config, name, value):
19 if config.has_key(name): 36 if config.has_key(name):
@@ -33,12 +50,14 @@ def setDefaultOptions(config):
33 setDefaultOpt(config, "LAUNCHER_PATH", pjoin(config["MACOS_PATH"], 50 setDefaultOpt(config, "LAUNCHER_PATH", pjoin(config["MACOS_PATH"],
34 "{EXEC_NAME}_launcher.sh".format(**config))) 51 "{EXEC_NAME}_launcher.sh".format(**config)))
35 52
53 prefix = config_prefix_get(config)
54
36 setDefaultOpt(config, "ICON_PATH", None) 55 setDefaultOpt(config, "ICON_PATH", None)
37 setDefaultOpt(config, "ICON_NAME", "{BASE_NAME}.icns".format(**config)) 56 setDefaultOpt(config, "ICON_NAME", "{BASE_NAME}.icns".format(**config))
38 57
39 setDefaultOpt(config, "VERSION", "1.13.0") 58 setDefaultOpt(config, "VERSION", "1.13.0")
40 59
41 setDefaultOpt(config, "INST_PREFIX", "/opt/local") 60 setDefaultOpt(config, "INST_PREFIX", prefix)
42 61
43 setDefaultOpt(config, "BIN_LIST", []) 62 setDefaultOpt(config, "BIN_LIST", [])
44 63
@@ -72,6 +91,13 @@ def load_config_file(fname):
72 for k in dir(confmodule): 91 for k in dir(confmodule):
73 if k.isupper(): 92 if k.isupper():
74 conf[k] = getattr(confmodule, k) 93 conf[k] = getattr(confmodule, k)
94
95 prefix = config_prefix_get(conf)
96 for k, v in conf.iteritems():
97 # FIXME - pretty bad, but will do...
98 if type(v) is str:
99 conf[k] = v.replace("@PREFIX@", prefix)
100
75 return conf 101 return conf
76 102
77def file_executable_is(path): 103def file_executable_is(path):
@@ -98,14 +124,14 @@ def fix_lib(path, fixedlib, config):
98 return 124 return
99 basename_path = os.path.basename(path) 125 basename_path = os.path.basename(path)
100 deps = subprocess.check_output(["otool", "-L", path]) 126 deps = subprocess.check_output(["otool", "-L", path])
127 prefix = config_prefix_get(config)
101 for depline in deps.split("\n")[1:]: #skip first line 128 for depline in deps.split("\n")[1:]: #skip first line
102 dep = depline.strip().split(" ")[0] 129 dep = depline.strip().split(" ")[0]
103 basename_dep = os.path.basename(dep) 130 basename_dep = os.path.basename(dep)
104 131
105 if dep == "": 132 if dep == "":
106 continue 133 continue
107 # FIXME: Do not rely on hard paths (e.g. /opt/local - macports) 134 if not dep.startswith(config["INST_PREFIX"]) and not dep.startswith(prefix):
108 if not dep.startswith(config["INST_PREFIX"]) and not dep.startswith("/opt/local"):
109 continue 135 continue
110 136
111 print " fix dep ", dep 137 print " fix dep ", dep
@@ -172,7 +198,7 @@ def bundle_module(module, fixedlib, config):
172 198
173 199
174def bundle_exe(binname, dest, fixedlib, config): 200def bundle_exe(binname, dest, fixedlib, config):
175 orig_exec_path = subprocess.check_output(["which", binname]).strip() 201 orig_exec_path = which(binname)
176 shutil.copy(orig_exec_path, dest) 202 shutil.copy(orig_exec_path, dest)
177 203
178 #fix the exe 204 #fix the exe