[game-data-packager] 11/25: Add support for cross-compiling packages

Simon McVittie smcv at debian.org
Sun Oct 9 21:26:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch master
in repository game-data-packager.

commit 333fbc38f65e136d9e2add5b60730ecbdeba5c8a
Author: Simon McVittie <smcv at debian.org>
Date:   Sun Oct 9 14:07:23 2016 +0100

    Add support for cross-compiling packages
---
 game_data_packager/build.py        | 37 ++++++++++++++++++++++++++++---------
 game_data_packager/command_line.py | 13 ++++++++++++-
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/game_data_packager/build.py b/game_data_packager/build.py
index 8d83aa0..ee78973 100644
--- a/game_data_packager/build.py
+++ b/game_data_packager/build.py
@@ -185,13 +185,16 @@ def iter_fat_mounts(folder):
                     yield path
 
 class PackagingTask(object):
-    def __init__(self, game, packaging=None):
+    def __init__(self, game, packaging=None, builder_packaging=None):
         # A GameData object.
         self.game = game
 
-        # A packaging system.
+        # The packaging system for which we are generating packages
         self.__packaging = packaging
 
+        # The packaging system used to find tools such as unrar
+        self.__builder_packaging = builder_packaging
+
         # A temporary directory.
         self.__workdir = None
 
@@ -265,6 +268,14 @@ class PackagingTask(object):
 
         return self.__packaging
 
+    @property
+    def builder_packaging(self):
+        """The PackagingSystem on the system doing the build."""
+        if self.__builder_packaging is None:
+            self.__builder_packaging = get_native_packaging_system()
+
+        return self.__builder_packaging
+
     def get_workdir(self):
         if self.__workdir is None:
             self.__workdir = tempfile.mkdtemp(prefix='gdptmp.')
@@ -1273,7 +1284,7 @@ class PackagingTask(object):
         with open(PKGINFO, 'w',  encoding='utf-8') as pkginfo:
             pkginfo.write('# Generated by game-data-packager %s\n' % package.version.split('+')[-1])
             pkginfo.write('# using fakeroot version %s\n' %
-                    self.packaging.current_version('fakeroot'))
+                    self.builder_packaging.current_version('fakeroot'))
             pkginfo.write('# %s\n' % time.strftime("%a %b %d %H:%M:%S UTC %Y", time.gmtime()))
             pkginfo.write('pkgname = %s\n' % package.name)
             pkginfo.write('pkgver = %s-1\n' % package.version)
@@ -1947,8 +1958,16 @@ class PackagingTask(object):
 
         self.verbose = getattr(args, 'verbose', False)
 
-        preserve_debs = (getattr(args, 'destination', None) is not None)
-        install_debs = getattr(args, 'install', True)
+        if self.packaging.__class__ is self.builder_packaging.__class__:
+            preserve_debs = (getattr(args, 'destination', None) is not None)
+            install_debs = getattr(args, 'install', True)
+        else:
+            preserve_debs = True
+            install_debs = False
+            if args.destination is None:
+                raise SystemExit('Must specify a destination when '
+                        'building packages for a different packaging '
+                        'system')
 
         if getattr(args, 'compress', None) is None:
             # default to not compressing if we aren't going to install it
@@ -2219,7 +2238,7 @@ class PackagingTask(object):
             for tool in build_depends:
                 tool = tool.strip()
 
-                if not which(tool) and not self.packaging.is_installed(tool):
+                if not which(tool) and not self.builder_packaging.is_installed(tool):
                     logger.error('package "%s" is needed to build "%s"' %
                                  (tool, package.name))
                     possible.discard(package)
@@ -2696,7 +2715,7 @@ class PackagingTask(object):
 
         # unace-nonfree package diverts /usr/bin/unace from unace package
         if (fmt == 'unace-nonfree' and
-                self.packaging.is_installed('unace-nonfree')):
+                self.builder_packaging.is_installed('unace-nonfree')):
             return True
 
         logger.warning('cannot unpack "%s": tool "%s" is not ' +
@@ -2712,13 +2731,13 @@ class PackagingTask(object):
         packages = set()
 
         for t in self.missing_tools:
-            p = self.packaging.package_for_tool(t)
+            p = self.builder_packaging.package_for_tool(t)
             if p is not None:
                 packages.add(p)
 
         if packages:
             logger.warning('installing these packages might help:\n' +
-                '%s %s', ' '.join(self.packaging.INSTALL_CMD),
+                '%s %s', ' '.join(self.builder_packaging.INSTALL_CMD),
                 ' '.join(sorted(packages)))
 
     def __ensure_hashes(self, hashes, path, size):
diff --git a/game_data_packager/command_line.py b/game_data_packager/command_line.py
index e1afa65..083b4ff 100644
--- a/game_data_packager/command_line.py
+++ b/game_data_packager/command_line.py
@@ -27,9 +27,11 @@ from . import (load_games)
 from .config import (read_config)
 from .data import (ProgressCallback)
 from .gog import (run_gog_meta_mode)
+from .packaging import (get_packaging_system)
 from .paths import (DATADIR)
 from .steam import (run_steam_meta_mode)
 from .util import (human_size)
+from .version import (FORMAT, DISTRO)
 
 logger = logging.getLogger(__name__)
 
@@ -92,6 +94,12 @@ def run_command_line():
             dest='packages', metavar='PACKAGE',
             help='Produce this data package (may be repeated)')
 
+    base_parser.add_argument('--target-format',
+            help='Produce packages for this packaging system',
+            choices='arch deb rpm'.split())
+    base_parser.add_argument('--target-distro',
+            help='Produce packages suitable for this distro')
+
     base_parser.add_argument('--install-method', metavar='METHOD',
             dest='install_method',
             help='Use METHOD (apt, dpkg, gdebi, gdebi-gtk, gdebi-kde) ' +
@@ -223,6 +231,8 @@ def run_command_line():
             packages=[],
             save_downloads=None,
             shortname=None,
+            target_format=FORMAT,
+            target_distro=DISTRO,
     )
     if config['install']:
         logger.debug('obeying INSTALL=yes in configuration')
@@ -288,7 +298,8 @@ def run_command_line():
         else:
             raise AssertionError('could not find %s' % parsed.shortname)
 
-    with game.construct_task() as task:
+    with game.construct_task(packaging=get_packaging_system(
+        parsed.target_format, parsed.target_distro)) as task:
         if sys.stderr.isatty():
             task.progress_factory = TerminalProgress
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git



More information about the Pkg-games-commits mailing list