]>
git.ipfire.org Git - pakfire.git/blob - src/pakfire/builder.py
03ea2d64d0a76a10b45b3bab8ff3079d2336297b
2 ###############################################################################
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 from . import _pakfire
32 log
= logging
.getLogger("pakfire.builder")
34 from .constants
import *
38 BUILD_LOG_HEADER
= """
40 | _ \ __ _| | __/ _(_)_ __ ___ | |__ _ _(_) | __| | ___ _ __
41 | |_) / _` | |/ / |_| | '__/ _ \ | '_ \| | | | | |/ _` |/ _ \ '__|
42 | __/ (_| | <| _| | | | __/ | |_) | |_| | | | (_| | __/ |
43 |_| \__,_|_|\_\_| |_|_| \___| |_.__/ \__,_|_|_|\__,_|\___|_|
46 Host : %(hostname)s (%(host_arch)s)
51 class Builder(object):
52 def __init__(self
, conf
, arch
=None, build_id
=None, logfile
=None, **kwargs
):
57 "enable_ccache" : True,
58 "enable_snapshot" : True,
61 # Add settings from keyword arguments
62 self
.settings
.update(kwargs
)
65 self
.build_id
= build_id
or "%s" % uuid
.uuid4()
68 self
.log
= self
.setup_logging(logfile
)
70 # Architecture to build for
71 self
.arch
= arch
or _pakfire
.native_arch()
74 self
.log
.debug("Entering %s" % self
)
76 # Initialise Pakfire instance
77 pakfire
= base
.Pakfire(
86 # Setup domain name resolution in chroot
87 for i
in ("/etc/resolv.conf", "/etc/hosts"):
90 return BuilderContext(pakfire
, self
)
92 def __exit__(self
, type, value
, traceback
):
93 self
.log
.debug("Leaving %s" % self
)
95 def setup_logging(self
, logfile
):
96 l
= log
.getChild(self
.build_id
)
97 l
.setLevel(logging
.DEBUG
)
99 # Print everything to the console
100 console
= logger
.ConsoleHandler()
101 l
.addHandler(console
)
103 # If we have a log file, we write INFO and higher level messages to it
104 # using the build formatter which adds a timestamp
106 h
= logging
.FileHandler(logfile
)
107 h
.setLevel(logging
.INFO
)
111 f
= logger
.BuildFormatter()
117 class BuilderContext(object):
118 def __init__(self
, pakfire
, builder
):
119 self
.pakfire
= pakfire
120 self
.builder
= builder
122 # Get a reference to the logger
123 self
.log
= self
.builder
.log
125 def _install(self
, packages
):
126 self
.log
.debug(_("Installing packages in build environment:"))
127 for package
in packages
:
128 self
.log
.debug(" %s" % package
)
131 with self
.pakfire
as p
:
132 # Install all required packages
133 transaction
= p
.install(packages
)
135 # Return how many packages were installed/changed
136 ret
= len(transaction
)
138 # Dump transaction to log
139 t
= transaction
.dump()
142 # Download transaction
143 transaction
.download()
145 # Run the transaction
150 def build(self
, path
, shell
=True):
151 # Install the package
152 self
._install
([path
])
154 for makefile
in glob
.glob("%s/usr/src/packages/*/*.nm" % self
.pakfire
.path
):
155 self
.pakfire
.build(makefile
, logging_callback
=self
.log
.log
, interactive
=shell
)
157 def shell(self
, packages
=[], install
=None):
161 self
._install
(packages
)