From f6d579ba66973218aee1f80cbf5afdcfc127a9e3 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Fri, 17 Aug 2012 23:44:13 -0700 Subject: classes: Rename chrpath.bbclass -> patchelf.bbclass Fix references to chrpath bbclass Rename CHRPATH_BIN to PATCHELF_BIN Signed-off-by: Khem Raj --- meta/classes/chrpath.bbclass | 94 ---------------------------------------- meta/classes/package.bbclass | 2 +- meta/classes/patchelf.bbclass | 94 ++++++++++++++++++++++++++++++++++++++++ meta/classes/relocatable.bbclass | 2 +- 4 files changed, 96 insertions(+), 96 deletions(-) delete mode 100644 meta/classes/chrpath.bbclass create mode 100644 meta/classes/patchelf.bbclass diff --git a/meta/classes/chrpath.bbclass b/meta/classes/chrpath.bbclass deleted file mode 100644 index 3263505041..0000000000 --- a/meta/classes/chrpath.bbclass +++ /dev/null @@ -1,94 +0,0 @@ -CHRPATH_BIN ?= "patchelf" -PREPROCESS_RELOCATE_DIRS ?= "" - -def process_dir (directory, d): - import subprocess as sub - import stat - - cmd = d.expand('${CHRPATH_BIN}') - tmpdir = d.getVar('TMPDIR') - basedir = d.expand('${base_prefix}') - - #bb.debug("Checking %s for binaries to process" % directory) - if not os.path.exists(directory): - return - - dirs = os.listdir(directory) - for file in dirs: - fpath = directory + "/" + file - fpath = os.path.normpath(fpath) - if os.path.islink(fpath): - # Skip symlinks - continue - - if os.path.isdir(fpath): - process_dir(fpath, d) - else: - #bb.note("Testing %s for relocatability" % fpath) - - # We need read and write permissions for patchelf, if we don't have - # them then set them temporarily. Take a copy of the files - # permissions so that we can restore them afterwards. - perms = os.stat(fpath)[stat.ST_MODE] - if os.access(fpath, os.W_OK|os.R_OK): - perms = None - else: - # Temporarily make the file writeable so we can patchelf it - os.chmod(fpath, perms|stat.S_IRWXU) - - p = sub.Popen([cmd, '--print-rpath', fpath],stdout=sub.PIPE,stderr=sub.PIPE) - err, out = p.communicate() - # If returned succesfully, process stderr for results - if p.returncode != 0: - continue - - #bb.note("Current rpath for %s is %s" % (fpath, err.strip())) - rpaths = err.split(":") - new_rpaths = [] - for rpath in rpaths: - # If rpath is already dynamic copy it to new_rpath and continue - if rpath.find("$ORIGIN") != -1: - new_rpaths.append(rpath.strip()) - continue - # If the rpath shares a root with base_prefix determine a new dynamic rpath from the - # base_prefix shared root - if rpath.find(basedir) != -1: - depth = fpath.partition(basedir)[2].count('/') - libpath = rpath.partition(basedir)[2].strip() - # otherwise (i.e. cross packages) determine a shared root based on the TMPDIR - # NOTE: This will not work reliably for cross packages, particularly in the case - # where your TMPDIR is a short path (i.e. /usr/poky) as patchelf cannot insert an - # rpath longer than that which is already set. - elif rpath.find(tmpdir) != -1: - depth = fpath.rpartition(tmpdir)[2].count('/') - libpath = rpath.partition(tmpdir)[2].strip() - else: - new_rpaths.append(rpath.strip()) - continue - base = "$ORIGIN" - while depth > 1: - base += "/.." - depth-=1 - new_rpaths.append("%s%s" % (base, libpath)) - - # if we have modified some rpaths call patchelf to update the binary - if len(new_rpaths): - args = ":".join(new_rpaths) - #bb.note("Setting rpath for %s to %s" %(fpath, args)) - p = sub.Popen([cmd, '--set-rpath', args, fpath],stdout=sub.PIPE,stderr=sub.PIPE) - out, err = p.communicate() - if p.returncode != 0: - bb.error("%s: patchelf command failed with exit code %d:\n%s%s" % (d.getVar('PN', True), p.returncode, out, err)) - raise bb.build.FuncFailed - - if perms: - os.chmod(fpath, perms) - -def rpath_replace (path, d): - bindirs = d.expand("${bindir} ${sbindir} ${base_sbindir} ${base_bindir} ${libdir} ${base_libdir} ${libexecdir} ${PREPROCESS_RELOCATE_DIRS}").split() - - for bindir in bindirs: - #bb.note ("Processing directory " + bindir) - directory = path + "/" + bindir - process_dir (directory, d) - diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 73c4358aff..6197f88518 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass @@ -40,7 +40,7 @@ inherit packagedata inherit prserv -inherit chrpath +inherit patchelf PKGD = "${WORKDIR}/package" PKGDEST = "${WORKDIR}/packages-split" diff --git a/meta/classes/patchelf.bbclass b/meta/classes/patchelf.bbclass new file mode 100644 index 0000000000..032bb022e8 --- /dev/null +++ b/meta/classes/patchelf.bbclass @@ -0,0 +1,94 @@ +PATCHELF_BIN ?= "patchelf" +PREPROCESS_RELOCATE_DIRS ?= "" + +def process_dir (directory, d): + import subprocess as sub + import stat + + cmd = d.expand('${PATCHELF_BIN}') + tmpdir = d.getVar('TMPDIR') + basedir = d.expand('${base_prefix}') + + #bb.debug("Checking %s for binaries to process" % directory) + if not os.path.exists(directory): + return + + dirs = os.listdir(directory) + for file in dirs: + fpath = directory + "/" + file + fpath = os.path.normpath(fpath) + if os.path.islink(fpath): + # Skip symlinks + continue + + if os.path.isdir(fpath): + process_dir(fpath, d) + else: + #bb.note("Testing %s for relocatability" % fpath) + + # We need read and write permissions for patchelf, if we don't have + # them then set them temporarily. Take a copy of the files + # permissions so that we can restore them afterwards. + perms = os.stat(fpath)[stat.ST_MODE] + if os.access(fpath, os.W_OK|os.R_OK): + perms = None + else: + # Temporarily make the file writeable so we can patchelf it + os.chmod(fpath, perms|stat.S_IRWXU) + + p = sub.Popen([cmd, '--print-rpath', fpath],stdout=sub.PIPE,stderr=sub.PIPE) + err, out = p.communicate() + # If returned succesfully, process stderr for results + if p.returncode != 0: + continue + + #bb.note("Current rpath for %s is %s" % (fpath, err.strip())) + rpaths = err.split(":") + new_rpaths = [] + for rpath in rpaths: + # If rpath is already dynamic copy it to new_rpath and continue + if rpath.find("$ORIGIN") != -1: + new_rpaths.append(rpath.strip()) + continue + # If the rpath shares a root with base_prefix determine a new dynamic rpath from the + # base_prefix shared root + if rpath.find(basedir) != -1: + depth = fpath.partition(basedir)[2].count('/') + libpath = rpath.partition(basedir)[2].strip() + # otherwise (i.e. cross packages) determine a shared root based on the TMPDIR + # NOTE: This will not work reliably for cross packages, particularly in the case + # where your TMPDIR is a short path (i.e. /usr/poky) as patchelf cannot insert an + # rpath longer than that which is already set. + elif rpath.find(tmpdir) != -1: + depth = fpath.rpartition(tmpdir)[2].count('/') + libpath = rpath.partition(tmpdir)[2].strip() + else: + new_rpaths.append(rpath.strip()) + continue + base = "$ORIGIN" + while depth > 1: + base += "/.." + depth-=1 + new_rpaths.append("%s%s" % (base, libpath)) + + # if we have modified some rpaths call patchelf to update the binary + if len(new_rpaths): + args = ":".join(new_rpaths) + #bb.note("Setting rpath for %s to %s" %(fpath, args)) + p = sub.Popen([cmd, '--set-rpath', args, fpath],stdout=sub.PIPE,stderr=sub.PIPE) + out, err = p.communicate() + if p.returncode != 0: + bb.error("%s: patchelf command failed with exit code %d:\n%s%s" % (d.getVar('PN', True), p.returncode, out, err)) + raise bb.build.FuncFailed + + if perms: + os.chmod(fpath, perms) + +def rpath_replace (path, d): + bindirs = d.expand("${bindir} ${sbindir} ${base_sbindir} ${base_bindir} ${libdir} ${base_libdir} ${libexecdir} ${PREPROCESS_RELOCATE_DIRS}").split() + + for bindir in bindirs: + #bb.note ("Processing directory " + bindir) + directory = path + "/" + bindir + process_dir (directory, d) + diff --git a/meta/classes/relocatable.bbclass b/meta/classes/relocatable.bbclass index 4ca9981f44..64f392eb50 100644 --- a/meta/classes/relocatable.bbclass +++ b/meta/classes/relocatable.bbclass @@ -1,4 +1,4 @@ -inherit chrpath +inherit patchelf SYSROOT_PREPROCESS_FUNCS += "relocatable_binaries_preprocess" -- cgit 1.2.3-korg