[jhbuild/desrt/packagedb: 9/21] MakeModule: add 'make' helper



commit b51f891f17a8669861d4d09c95205e5bde391b50
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Jan 4 11:29:52 2015 -0500

    MakeModule: add 'make' helper
    
    Instead of repeating the logic in a dozen places, add a helper function
    that collects arguments, builds the 'make' invocation and executes it.
    
    Use this from the autotools and cmake modtypes.
    
    There is an inconsistency about whether makeargs are passed to 'make
    install' between autotools (they aren't) and cmake (they are).  This
    patch preserves that inconsistency.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742292

 jhbuild/modtypes/__init__.py  |   11 +++++++++++
 jhbuild/modtypes/autotools.py |   40 +++++++---------------------------------
 jhbuild/modtypes/cmake.py     |   19 ++++---------------
 3 files changed, 22 insertions(+), 48 deletions(-)
---
diff --git a/jhbuild/modtypes/__init__.py b/jhbuild/modtypes/__init__.py
index b7a06cc..cb0631d 100644
--- a/jhbuild/modtypes/__init__.py
+++ b/jhbuild/modtypes/__init__.py
@@ -519,6 +519,17 @@ class MakeModule(Package):
             makeargs = re.sub(r'-j\w*\d+', '', makeargs) + ' -j 1'
         return self.eval_args(makeargs).strip()
 
+    def make(self, buildscript, target='', pre='', makeargs=None):
+        makecmd = os.environ.get('MAKE', 'make')
+
+        if makeargs is None:
+            makeargs = self.get_makeargs(self, buildscript)
+
+        cmd = '{pre}{make} {makeargs} {target}'.format(pre=pre,
+                                                        make=makecmd,
+                                                        makeargs=makeargs,
+                                                        target=target)
+        buildscript.execute(cmd, cwd = self.get_builddir(buildscript), extra_env = self.extra_env)
 
 class DownloadableModule:
     PHASE_CHECKOUT = 'checkout'
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index d57935b..257f722 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -248,19 +248,13 @@ class AutogenModule(MakeModule, DownloadableModule):
 
     def do_clean(self, buildscript):
         buildscript.set_action(_('Cleaning'), self)
-        makeargs = self.get_makeargs(buildscript)
-        cmd = '%s %s clean' % (os.environ.get('MAKE', 'make'), makeargs)
-        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                extra_env = self.extra_env)
+        self.make(buildscript, 'clean')
     do_clean.depends = [PHASE_CONFIGURE]
     do_clean.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
     def do_build(self, buildscript):
         buildscript.set_action(_('Building'), self)
-        makeargs = self.get_makeargs(buildscript)
-        cmd = '%s%s %s' % (self.static_analyzer_pre_cmd(buildscript), os.environ.get('MAKE', 'make'), 
makeargs)
-        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                extra_env = self.extra_env)
+        self.make(buildscript, pre=self.static_analyzer_pre_cmd(buildscript))
     do_build.depends = [PHASE_CONFIGURE]
     do_build.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE,
             PHASE_CLEAN, PHASE_DISTCLEAN]
@@ -291,11 +285,8 @@ class AutogenModule(MakeModule, DownloadableModule):
 
     def do_check(self, buildscript):
         buildscript.set_action(_('Checking'), self)
-        makeargs = self.get_makeargs(buildscript, add_parallel=False)
-        cmd = '%s%s %s check' % (self.static_analyzer_pre_cmd(buildscript), os.environ.get('MAKE', 'make'), 
makeargs)
         try:
-            buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                    extra_env = self.extra_env)
+            self.make(buildscript, 'check', pre=self.static_analyzer_pre_cmd(buildscript))
         except CommandError:
             if not buildscript.config.makecheck_advisory:
                 raise
@@ -304,19 +295,13 @@ class AutogenModule(MakeModule, DownloadableModule):
 
     def do_dist(self, buildscript):
         buildscript.set_action(_('Creating tarball for'), self)
-        makeargs = self.get_makeargs(buildscript)
-        cmd = '%s %s dist' % (os.environ.get('MAKE', 'make'), makeargs)
-        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                    extra_env = self.extra_env)
+        self.make(buildscript, 'dist')
     do_dist.depends = [PHASE_CONFIGURE]
     do_dist.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
     def do_distcheck(self, buildscript):
         buildscript.set_action(_('Dist checking'), self)
-        makeargs = self.get_makeargs(buildscript)
-        cmd = '%s %s distcheck' % (os.environ.get('MAKE', 'make'), makeargs)
-        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                    extra_env = self.extra_env)
+        self.make(buildscript, 'distcheck')
     do_distcheck.depends = [PHASE_DIST]
     do_distcheck.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
@@ -329,15 +314,7 @@ class AutogenModule(MakeModule, DownloadableModule):
 
         buildscript.set_action(_('Installing'), self)
         destdir = self.prepare_installroot(buildscript)
-        if self.makeinstallargs:
-            cmd = '%s %s DESTDIR=%s' % (os.environ.get('MAKE', 'make'),
-                                        self.makeinstallargs,
-                                        destdir)
-        else:
-            cmd = '%s install DESTDIR=%s' % (os.environ.get('MAKE', 'make'),
-                                             destdir)
-        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                    extra_env = self.extra_env)
+        self.make(buildscript, self.makeinstallargs or 'install', makeargs='DESTDIR={}'.format(destdir))
         self.process_install(buildscript, self.get_revision())
 
     do_install.depends = [PHASE_BUILD]
@@ -360,10 +337,7 @@ class AutogenModule(MakeModule, DownloadableModule):
         if hasattr(self.branch, 'delete_unknown_files'):
             self.branch.delete_unknown_files(buildscript)
         else:
-            makeargs = self.get_makeargs(buildscript)
-            cmd = '%s %s distclean' % (os.environ.get('MAKE', 'make'), makeargs)
-            buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                                extra_env = self.extra_env)
+            self.make(buildscript, 'distclean')
     do_distclean.depends = [PHASE_CHECKOUT]
 
     def xml_tag_and_attrs(self):
diff --git a/jhbuild/modtypes/cmake.py b/jhbuild/modtypes/cmake.py
index 1d4e752..044fd4b 100644
--- a/jhbuild/modtypes/cmake.py
+++ b/jhbuild/modtypes/cmake.py
@@ -97,27 +97,20 @@ class CMakeModule(MakeModule, DownloadableModule):
     def do_clean(self, buildscript):
         buildscript.set_action(_('Cleaning'), self)
         builddir = self.get_builddir(buildscript)
-        cmd = '%s %s clean' % (os.environ.get('MAKE', 'make'), self.get_makeargs(buildscript))
-        buildscript.execute(cmd, cwd = builddir,
-                extra_env = self.extra_env)
+        self.make(buildscript, 'clean')
     do_clean.depends = [PHASE_CONFIGURE]
     do_clean.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
     def do_build(self, buildscript):
         buildscript.set_action(_('Building'), self)
         builddir = self.get_builddir(buildscript)
-        cmd = '%s %s' % (os.environ.get('MAKE', 'make'), self.get_makeargs(buildscript))
-        buildscript.execute(cmd, cwd = builddir,
-                extra_env = self.extra_env)
+        self.make(buildscript)
     do_build.depends = [PHASE_CONFIGURE]
     do_build.error_phases = [PHASE_FORCE_CHECKOUT]
 
     def do_dist(self, buildscript):
         buildscript.set_action(_('Creating tarball for'), self)
-        cmd = '%s %s package_source' % (os.environ.get('MAKE', 'make'),
-                self.get_makeargs(buildscript))
-        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                extra_env = self.extra_env)
+        self.make(buildscript, 'package_source')
     do_dist.depends = [PHASE_CONFIGURE]
     do_dist.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
@@ -125,11 +118,7 @@ class CMakeModule(MakeModule, DownloadableModule):
         buildscript.set_action(_('Installing'), self)
         builddir = self.get_builddir(buildscript)
         destdir = self.prepare_installroot(buildscript)
-        cmd = '%s %s install DESTDIR=%s' % (os.environ.get('MAKE', 'make'),
-                self.get_makeargs(buildscript), destdir)
-        buildscript.execute(cmd,
-                cwd = builddir,
-                extra_env = self.extra_env)
+        self.make(buildscript, 'install DESTDIR=%s'.format(destdir))
         self.process_install(buildscript, self.get_revision())
     do_install.depends = [PHASE_BUILD]
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]