blob: 1f4273c1b2645a1648dce7ce92224fa2fa979ead [file] [log] [blame]
mbligh3e0eaf12007-12-04 22:45:03 +00001#
2# Copyright 2007 IBM Corp. Released under the GPL v2
3# Authors: Ryan Harper <ryanh@us.ibm.com>
4#
5
6"""
7This module defines the GitKernel class
8"""
9
10__author__ = """
11ryanh@us.ibm.com (Ryan Harper)
12"""
13
14
15import os
mbligh313f12c2008-05-15 23:33:50 +000016import git, source_kernel
mbligh3e0eaf12007-12-04 22:45:03 +000017
18
19class GitKernel(git.GitRepo):
jadmanski0afbb632008-06-06 21:10:57 +000020 """
21 This class represents a git kernel repo.
mbligh3e0eaf12007-12-04 22:45:03 +000022
jadmanski0afbb632008-06-06 21:10:57 +000023 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.
mbligh3e0eaf12007-12-04 22:45:03 +000025
jadmanski0afbb632008-06-06 21:10:57 +000026 """
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
mbligh3e0eaf12007-12-04 22:45:03 +000032
33
jadmanski0afbb632008-06-06 21:10:57 +000034 def configure(self, config):
35 self.__config = config
mbligh3e0eaf12007-12-04 22:45:03 +000036
37
jadmanski0afbb632008-06-06 21:10:57 +000038 def patch(self, patch):
39 self.__patches.append(patch)
mbligh3e0eaf12007-12-04 22:45:03 +000040
41
jadmanski0afbb632008-06-06 21:10:57 +000042 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)
mbligh3e0eaf12007-12-04 22:45:03 +000050
jadmanski0afbb632008-06-06 21:10:57 +000051 # 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))
mbligh3e0eaf12007-12-04 22:45:03 +000056
jadmanski0afbb632008-06-06 21:10:57 +000057 # use a source_kernel to configure, patch, build and install.
58 sk = source_kernel.SourceKernel(remote_source_material)
mbligh3e0eaf12007-12-04 22:45:03 +000059
jadmanski0afbb632008-06-06 21:10:57 +000060 if build:
61 # apply patches
62 for p in self.__patches:
63 sk.patch(p)
mbligh3e0eaf12007-12-04 22:45:03 +000064
jadmanski0afbb632008-06-06 21:10:57 +000065 # configure
66 sk.configure(self.__config)
mbligh3e0eaf12007-12-04 22:45:03 +000067
jadmanski0afbb632008-06-06 21:10:57 +000068 # build
69 sk.build(host)
70
71 # install
72 sk.install(host)