mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2007 IBM Corp. Released under the GPL v2 |
| 3 | # Authors: Ryan Harper <ryanh@us.ibm.com> |
| 4 | # |
| 5 | |
| 6 | """ |
| 7 | This module defines the GitKernel class |
| 8 | """ |
| 9 | |
| 10 | __author__ = """ |
| 11 | ryanh@us.ibm.com (Ryan Harper) |
| 12 | """ |
| 13 | |
| 14 | |
| 15 | import os |
mbligh | 313f12c | 2008-05-15 23:33:50 +0000 | [diff] [blame] | 16 | import git, source_kernel |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | class GitKernel(git.GitRepo): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 20 | """ |
| 21 | This class represents a git kernel repo. |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 22 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 23 | It is used to pull down a local copy of a git repo, check if the local repo |
| 24 | is up-to-date, if not update and then build the kernel from the git repo. |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 25 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 26 | """ |
| 27 | def __init__(self, repodir, giturl, weburl): |
| 28 | git.GitRepo.__init__(self, repodir, giturl, weburl) |
| 29 | self.__patches = [] |
| 30 | self.__config = None |
| 31 | self.__build = None |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 32 | |
| 33 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 34 | def configure(self, config): |
| 35 | self.__config = config |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 36 | |
| 37 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 38 | def patch(self, patch): |
| 39 | self.__patches.append(patch) |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 40 | |
| 41 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 42 | def install(self, host, build=True, builddir=None): |
| 43 | # use tmpdir if no builddir specified |
| 44 | # NB: pass a builddir to install() method if you |
| 45 | # need to ensure the build remains after the completion |
| 46 | # of a job |
| 47 | if not builddir: |
| 48 | self.__build = os.path.join(host.get_tmp_dir(),"build") |
| 49 | print 'warning: builddir %s is not persistent' %(self.__build) |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 50 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 51 | # push source to host for install |
| 52 | print 'pushing %s to host' %(self.source_material) |
| 53 | host.send_file(self.source_material, self.__build) |
| 54 | remote_source_material= os.path.join(self.__build, |
| 55 | os.path.basename(self.source_material)) |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 56 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 57 | # use a source_kernel to configure, patch, build and install. |
| 58 | sk = source_kernel.SourceKernel(remote_source_material) |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 59 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 60 | if build: |
| 61 | # apply patches |
| 62 | for p in self.__patches: |
| 63 | sk.patch(p) |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 64 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 65 | # configure |
| 66 | sk.configure(self.__config) |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 67 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 68 | # build |
| 69 | sk.build(host) |
| 70 | |
| 71 | # install |
| 72 | sk.install(host) |