From fef6c20e253772325dccd55d194679cfd8634f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Wed, 28 Sep 2005 13:18:37 +0000 Subject: [PATCH] - strip support! Use NoStrip global variable in actions.py if you don't want/need to strip a path/file... --- pisi/build.py | 19 +++++++++++++++++-- pisi/util.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/pisi/build.py b/pisi/build.py index 4fa8238b..33d8e7e8 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -162,6 +162,8 @@ class PisiBuild: self.run_build_action() self.run_install_action() + self.strip_install_dir() + # after all, we are ready to build/prepare the packages self.build_packages() @@ -287,6 +289,16 @@ class PisiBuild: ctx.ui.action(_("* Applying patch: %s") % patch.filename) util.do_patch(self.srcDir, patchFile, level=patch.level, target=patch.target) + def strip_install_dir(self): + """strip install directory""" + ctx.ui.action(_("Stripping files..")) + install_dir = self.bctx.pkg_install_dir() + try: + nostrip = self.actionGlobals['NoStrip'] + util.strip_directory(install_dir, nostrip) + except KeyError: + util.strip_directory(install_dir) + def gen_metadata_xml(self, package): """Generate the metadata.xml file for build source. @@ -314,7 +326,8 @@ class PisiBuild: else: metadata.package.build = self.calc_build_no(metadata.package.name) - metadata.write(os.path.join(self.bctx.pkg_dir(), ctx.const.metadata_xml)) + metadata_xml_path = os.path.join(self.bctx.pkg_dir(), ctx.const.metadata_xml) + metadata.write(metadata_xml_path) self.metadata = metadata def gen_files_xml(self, package): @@ -339,7 +352,9 @@ class PisiBuild: d[frpath] = FileInfo(frpath, ftype, fsize, fhash) for (p, fileinfo) in d.iteritems(): files.append(fileinfo) - files.write(os.path.join(self.bctx.pkg_dir(), ctx.const.files_xml)) + + files_xml_path = os.path.join(self.bctx.pkg_dir(), ctx.const.files_xml) + files.write(files_xml_path) self.files = files def calc_build_no(self, package_name): diff --git a/pisi/util.py b/pisi/util.py index 2917f6b6..c09eafae 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -353,6 +353,48 @@ def do_patch(sourceDir, patchFile, level, target = ''): os.chdir(cwd) + +def strip_directory(top, excludelist=[]): + for root, dirs, files in os.walk(top): + for fn in files: + frpath = os.path.join(root, fn) + + # real path in .pisi package + p = '/' + removepathprefix(top, frpath) + strip = True + for exclude in excludelist: + if p.startswith(exclude): + strip = False + + if strip: + strip_file(frpath) + +def strip_file(filepath): + """strip a file""" + p = os.popen("file %s" % filepath) + o = p.read() + + def run_strip(f, flags=""): + p = os.popen("strip %s %s" %(flags, f)) + ret = p.close() + if ret: + raise UtilError, "strip command failed!" + + if "current ar archive" in o: + run_strip(filepath, "-g") + return True + + elif "SB executable" in o: + run_strip(filepath) + return True + + elif "SB shared object" in o: + run_strip(filepath, "--strip-unneeded") + # FIXME: warn for TEXTREL + return True + + return False + def partition_freespace(directory): """ returns free space of given directory's partition """ st = os.statvfs(directory)