import msger
import utils
+import runner
import errors
from conf import configmgr
'armv7l',
]
+def get_processors():
+ """
+ get number of processors (online) based on
+ SC_NPROCESSORS_ONLN (returns 1 if config name does not exist).
+ """
+ try:
+ return os.sysconf('SC_NPROCESSORS_ONLN')
+ except ValueError:
+ return 1
+
+def get_hostarch():
+ hostarch = os.uname()[4]
+ if hostarch == 'i686':
+ hostarch = 'i586'
+ return hostarch
+
+def find_binary_path(binary):
+ if os.environ.has_key("PATH"):
+ paths = os.environ["PATH"].split(":")
+ else:
+ paths = []
+ if os.environ.has_key("HOME"):
+ paths += [os.environ["HOME"] + "/bin"]
+ paths += ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin",
+ "/usr/bin", "/sbin", "/bin"]
+
+ for path in paths:
+ bin_path = "%s/%s" % (path, binary)
+ if os.path.exists(bin_path):
+ return bin_path
+ return None
+
+def is_statically_linked(binary):
+ return ", statically linked, " in runner.outs(['file', binary])
+
+def setup_qemu_emulator():
+ # mount binfmt_misc if it doesn't exist
+ if not os.path.exists("/proc/sys/fs/binfmt_misc"):
+ modprobecmd = find_binary_path("modprobe")
+ runner.show([modprobecmd, "binfmt_misc"])
+ if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
+ mountcmd = find_binary_path("mount")
+ runner.show([mountcmd, "-t", "binfmt_misc", "none",
+ "/proc/sys/fs/binfmt_misc"])
+
+ # qemu_emulator is a special case, we can't use find_binary_path
+ # qemu emulator should be a statically-linked executable file
+ qemu_emulator = "/usr/bin/qemu-arm"
+ if not os.path.exists(qemu_emulator) or \
+ not is_statically_linked(qemu_emulator):
+ qemu_emulator = "/usr/bin/qemu-arm-static"
+ if not os.path.exists(qemu_emulator):
+ raise errors.QemuError("Please install a statically-linked qemu-arm")
+
+ # disable selinux, selinux will block qemu emulator to run
+ if os.path.exists("/usr/sbin/setenforce"):
+ msger.info('Try to disable selinux')
+ runner.show(["/usr/sbin/setenforce", "0"])
+
+ node = "/proc/sys/fs/binfmt_misc/arm"
+ if is_statically_linked(qemu_emulator) and os.path.exists(node):
+ return qemu_emulator
+
+ # unregister it if it has been registered and
+ # is a dynamically-linked executable
+ if not is_statically_linked(qemu_emulator) and os.path.exists(node):
+ qemu_unregister_string = "-1\n"
+ fds = open("/proc/sys/fs/binfmt_misc/arm", "w")
+ fds.write(qemu_unregister_string)
+ fds.close()
+
+ # register qemu emulator for interpreting other arch executable file
+ if not os.path.exists(node):
+ qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:\n" % qemu_emulator
+ fds = open("/proc/sys/fs/binfmt_misc/register", "w")
+ fds.write(qemu_arm_string)
+ fds.close()
+
+ return qemu_emulator
+
+
def do(opts, args):
workdir = os.getcwd()
if len(args) == 1:
workdir = args[0]
- hostarch = utils.get_hostarch()
+ hostarch = get_hostarch()
buildarch = hostarch
if opts.arch:
if opts.arch in buildarchmap:
if suwrapper:
cmd = [suwrapper] + cmd
- build_jobs = utils.get_processors()
+ build_jobs = get_processors()
if build_jobs > 1:
cmd += ['--jobs=%s' % build_jobs]
if opts.clean:
if buildarch.startswith('arm'):
try:
- utils.setup_qemu_emulator()
+ setup_qemu_emulator()
except errors.QemuError, exc:
msger.error('%s' % exc)
import shutil
import msger
-import runner
-import errors
-
class Workdir(object):
def __init__(self, path):
def __exit__(self, _type, _value, _tb):
os.chdir(self._cwd)
-def get_processors():
- """
- get number of processors (online) based on
- SC_NPROCESSORS_ONLN (returns 1 if config name does not exist).
- """
- try:
- return os.sysconf('SC_NPROCESSORS_ONLN')
- except ValueError:
- return 1
-
-def get_hostarch():
- hostarch = os.uname()[4]
- if hostarch == 'i686':
- hostarch = 'i586'
- return hostarch
-
-def find_binary_path(binary):
- if os.environ.has_key("PATH"):
- paths = os.environ["PATH"].split(":")
- else:
- paths = []
- if os.environ.has_key("HOME"):
- paths += [os.environ["HOME"] + "/bin"]
- paths += ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin",
- "/usr/bin", "/sbin", "/bin"]
-
- for path in paths:
- bin_path = "%s/%s" % (path, binary)
- if os.path.exists(bin_path):
- return bin_path
- return None
-
-def is_statically_linked(binary):
- return ", statically linked, " in runner.outs(['file', binary])
-
-def setup_qemu_emulator():
- # mount binfmt_misc if it doesn't exist
- if not os.path.exists("/proc/sys/fs/binfmt_misc"):
- modprobecmd = find_binary_path("modprobe")
- runner.show([modprobecmd, "binfmt_misc"])
- if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
- mountcmd = find_binary_path("mount")
- runner.show([mountcmd, "-t", "binfmt_misc", "none",
- "/proc/sys/fs/binfmt_misc"])
-
- # qemu_emulator is a special case, we can't use find_binary_path
- # qemu emulator should be a statically-linked executable file
- qemu_emulator = "/usr/bin/qemu-arm"
- if not os.path.exists(qemu_emulator) or \
- not is_statically_linked(qemu_emulator):
- qemu_emulator = "/usr/bin/qemu-arm-static"
- if not os.path.exists(qemu_emulator):
- raise errors.QemuError("Please install a statically-linked qemu-arm")
-
- # disable selinux, selinux will block qemu emulator to run
- if os.path.exists("/usr/sbin/setenforce"):
- msger.info('Try to disable selinux')
- runner.show(["/usr/sbin/setenforce", "0"])
-
- node = "/proc/sys/fs/binfmt_misc/arm"
- if is_statically_linked(qemu_emulator) and os.path.exists(node):
- return qemu_emulator
-
- # unregister it if it has been registered and
- # is a dynamically-linked executable
- if not is_statically_linked(qemu_emulator) and os.path.exists(node):
- qemu_unregister_string = "-1\n"
- fds = open("/proc/sys/fs/binfmt_misc/arm", "w")
- fds.write(qemu_unregister_string)
- fds.close()
-
- # register qemu emulator for interpreting other arch executable file
- if not os.path.exists(node):
- qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:\n" % qemu_emulator
- fds = open("/proc/sys/fs/binfmt_misc/register", "w")
- fds.write(qemu_arm_string)
- fds.close()
-
- return qemu_emulator
-
def guess_spec(workdir, default_spec):
if default_spec:
if not os.path.exists(default_spec):