diff --git a/pisi/build.py b/pisi/build.py index 36d5f374..5b1c3353 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -17,6 +17,7 @@ import os import sys import glob +from copy import deepcopy from os.path import basename, dirname import gettext @@ -74,6 +75,10 @@ def check_path_collision(package, pkgList): # collide. Exp: # pinfo.path: /usr/share # path.path: /usr/share/doc + if path.path.endswith(ctx.const.ar_file_suffix) and ctx.get_option('create_static'): + # don't throw collision error for ar files. + # we'll handle this in gen_files_xml.. + continue if util.subpath(pinfo.path, path.path): collisions.append(path.path) ctx.ui.error(_('Path %s belongs in multiple packages') % @@ -461,6 +466,28 @@ class Builder: ctx.ui.action(_("* Applying patch: %s") % patch.filename) util.do_patch(self.srcDir, patchFile, level=patch.level, target=patch.target) + def generate_static_package_object(self): + ar_files = [] + for root, dirs, files in os.walk(self.pkg_install_dir()): + for f in files: + if f.endswith(ctx.const.ar_file_suffix) and util.is_ar_file(util.join_path(root, f)): + ar_files.append(util.join_path(root, f)) + + if not len(ar_files): + return None + + static_package_obj = pisi.specfile.Package() + static_package_obj.name = self.spec.source.name + ctx.const.static_name_suffix + # FIXME: find a better way to deal with the summary and description constants. + static_package_obj.summary['en'] = u'Ar files for %s' % (self.spec.source.name) + static_package_obj.description['en'] = u'Ar files for %s' % (self.spec.source.name) + static_package_obj.partOf = 'library:static' + for f in ar_files: + static_package_obj.files.append(pisi.specfile.Path(path = f[len(self.pkg_install_dir()):], fileType = "library")) + static_package_obj.packageDependencies.append(pisi.dependency.Dependency(package = self.spec.source.name)) + + return static_package_obj + def strip_install_dir(self): """strip install directory""" ctx.ui.action(_("Stripping files..")) @@ -529,6 +556,13 @@ class Builder: def add_path(path): # add the files under material path for fpath, fhash in util.get_file_hashes(path, collisions, install_dir): + if ctx.get_option('create_static') \ + and fpath.endswith(ctx.const.ar_file_suffix) \ + and not package.name.endswith(ctx.const.static_name_suffix) \ + and util.is_ar_file(fpath): + # if this is an ar file, and this package is not a -static package, + # don't include this file into the package. + continue frpath = util.removepathprefix(install_dir, fpath) # relative path ftype, permanent = get_file_type(frpath, package.files, install_dir) fsize = util.dir_size(fpath) @@ -641,6 +675,11 @@ class Builder: # Strip install directory before building .pisi packages. self.strip_install_dir() + if ctx.get_option('create_static'): + obj = self.generate_static_package_object() + if obj: + self.spec.packages.append(obj) + package_names = [] old_package_names = [] diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index da9316ae..9c1ff59d 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -352,6 +352,8 @@ to be downloaded from a repository containing sources. help=_("bypass errors from ActionsAPI")) self.parser.add_option("-B", "--ignore-comar", action="store_true", default=False, help=_("bypass comar configuration agent")) + self.parser.add_option("-S", "--create-static", action="store_true", + default=False, help=_("automatically create a *-static package with ar files")) def run(self): diff --git a/pisi/constants.py b/pisi/constants.py index 91860158..f143c47d 100644 --- a/pisi/constants.py +++ b/pisi/constants.py @@ -45,10 +45,14 @@ class Constants: __c = _constant() def __init__(self): - # prefix for package names + # suffix for package names self.__c.package_suffix = ".pisi" self.__c.xdelta_suffix = ".xdelta" + # suffix for auto generated ar packages + self.__c.static_name_suffix = "-static" + self.__c.ar_file_suffix = ".a" + # directory suffixes for build self.__c.work_dir_suffix = "/work" self.__c.install_dir_suffix = "/install" diff --git a/pisi/util.py b/pisi/util.py index b5e786a1..5f850297 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -312,11 +312,14 @@ def copy_file(src,dest): check_dir(os.path.dirname(dest)) shutil.copyfile(src, dest) +def is_ar_file(file_path): + return open(file_path).readline().strip() == '!' + def clean_ar_timestamps(ar_file): """clean the timestamps of the ar files""" - content = open(ar_file).readlines() - if not content[0].strip() == '!': + if not is_ar_file(ar_file): return + content = open(ar_file).readlines() fp = open(ar_file, 'w') for line in content: pos = line.rfind(chr(32) + chr(96))