This repository has been archived by the owner on Feb 25, 2018. It is now read-only.
/
linux.py
87 lines (73 loc) · 3.4 KB
/
linux.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Copyright (c) 2009-2010, Cloud Matrix Pty. Ltd.
# All rights reserved; available under the terms of the BSD License.
from __future__ import with_statement
import os
import stat
from myppy.envs import base
from myppy.recipes import linux as _linux_recipes
class MyppyEnv(base.MyppyEnv):
DEPENDENCIES = ["apbuild","patchelf"]
DEPENDENCIES.extend(base.MyppyEnv.DEPENDENCIES)
def __init__(self,rootdir):
super(MyppyEnv,self).__init__(rootdir)
self.env["APBUILD_STATIC_LIBGCC"] = "1"
self.env["AUTOPACKAGE_FRONTEND"] = "apkg-ttyfe"
self.env["CC"] = "apgcc"
self.env["CXX"] = "apg++"
self._add_env_path("PKG_CONFIG_PATH",os.path.join(self.PREFIX,
"lib/pkgconfig"))
_RECIPES_WITH_APGCC_PROBLEMS = ("apbuild_base","apbuild",
"lib_apiextractor",)
def record_files(self,recipe,files):
for fpath in files:
fpath = os.path.join(self.rootdir,fpath)
fnm = os.path.basename(fpath)
if fpath == os.path.realpath(fpath):
if recipe not in self._RECIPES_WITH_APGCC_PROBLEMS:
if fnm.endswith(".so") or ".so." in fnm:
self._check_glibc_symbols(fpath)
self._strip(fpath)
self._adjust_rpath(fpath)
elif "." not in fnm:
fileinfo = self.bt("file",fpath)
if "executable" in fileinfo and "ELF" in fileinfo:
self._strip(fpath)
self._adjust_rpath(fpath)
super(MyppyEnv,self).record_files(recipe,files)
def _strip(self,fpath):
mod = os.stat(fpath).st_mode
os.chmod(fpath,stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
self.do("strip",fpath)
os.chmod(fpath,mod)
def _check_glibc_symbols(self,fpath):
print "VERIFYING GLIBC SYMBOLS", fpath
for ln in self.bt("objdump","-T",fpath).split("\n"):
for field in ln.split():
if field.startswith("GLIBC_"):
ver = field.split("_",1)[1].split(".")
ver = map(int,ver)
if ver >= [2,4,]:
err = "new glibc symbols in " + fpath
err += "\n" + ln.strip()
assert False, err
elif field.startswith("GLIBCXX_"):
ver = field.split("_",1)[1].split(".")
ver = map(int,ver)
if ver > [3,4,]:
err = "new glibcxx symbols in " + fpath
err += "\n" + ln.strip()
assert False, err
def _adjust_rpath(self,fpath):
# patchelf might not be installed if we're just initialising the env.
if os.path.exists(os.path.join(self.PREFIX,"bin","patchelf")):
print "ADJUSTING RPATH", fpath
backrefs = []
froot = os.path.dirname(fpath)
while froot != self.PREFIX:
backrefs.append("..")
froot = os.path.dirname(froot)
rpath = "/".join(backrefs) + "/lib"
rpath = "${ORIGIN}:${ORIGIN}/" + rpath
self.do("patchelf","--set-rpath",rpath,fpath)
def load_recipe(self,recipe):
return self._load_recipe_subclass(recipe,MyppyEnv,_linux_recipes)