blob: da725c74323850b0b304e3cc7bdbd5c02bceb707 [file] [log] [blame]
mblighc86b0b42006-07-28 17:35:28 +00001__author__ = """Copyright Martin J. Bligh, 2006"""
mbligha2508052006-05-28 21:29:53 +00002
apwba5bbfd2006-10-16 09:25:45 +00003import os,os.path,shutil,urllib,copy,pickle,re,glob
mblighf4c35322006-03-13 01:01:10 +00004from autotest_utils import *
mbligh10038012006-10-19 03:32:45 +00005import kernel_config, test, os_dep
mblighf4c35322006-03-13 01:01:10 +00006
7class kernel:
mblighc86b0b42006-07-28 17:35:28 +00008 """ Class for compiling kernels.
9
10 Data for the object includes the src files
11 used to create the kernel, patches applied, config (base + changes),
12 the build directory itself, and logged output
13
14 Properties:
15 job
16 Backpointer to the job object we're part of
17 autodir
18 Path to the top level autotest dir (/usr/local/autotest)
mblighc86b0b42006-07-28 17:35:28 +000019 src_dir
mbligh1e8858e2006-11-24 22:18:35 +000020 <tmp_dir>/src/
mblighc49af7b2006-11-24 04:02:21 +000021 build_dir
mbligh1e8858e2006-11-24 22:18:35 +000022 <tmp_dir>/linux/
mblighc86b0b42006-07-28 17:35:28 +000023 config_dir
mbligh1e8858e2006-11-24 22:18:35 +000024 <results_dir>/config/
mblighc86b0b42006-07-28 17:35:28 +000025 log_dir
mbligh1e8858e2006-11-24 22:18:35 +000026 <results_dir>/debug/
27 results_dir
28 <results_dir>/results/
mblighc86b0b42006-07-28 17:35:28 +000029 """
30
mbligh8baa2ea2006-12-17 23:01:24 +000031 autodir = ''
32
33 def __init__(self, job, base_tree, results_dir, tmp_dir, build_dir, leave = False):
mblighc86b0b42006-07-28 17:35:28 +000034 """Initialize the kernel build environment
35
36 job
37 which job this build is part of
mblighc86b0b42006-07-28 17:35:28 +000038 base_tree
mbligh534015f2006-09-15 03:28:56 +000039 base kernel tree. Can be one of the following:
40 1. A local tarball
41 2. A URL to a tarball
42 3. A local directory (will symlink it)
43 4. A shorthand expandable (eg '2.6.11-git3')
mbligh1e8858e2006-11-24 22:18:35 +000044 results_dir
45 Results directory (holds config/, debug/, results/)
46 tmp_dir
mbligh72b88fc2006-12-16 18:41:35 +000047
mbligh1e8858e2006-11-24 22:18:35 +000048 leave
49 Boolean, whether to leave existing tmpdir or not
mblighc86b0b42006-07-28 17:35:28 +000050 """
mblighf4c35322006-03-13 01:01:10 +000051 self.job = job
mbligh678823f2006-12-07 18:49:00 +000052 self.autodir = job.autodir
mblighf4c35322006-03-13 01:01:10 +000053
mbligh1e8858e2006-11-24 22:18:35 +000054 self.src_dir = os.path.join(tmp_dir, 'src')
mbligh8baa2ea2006-12-17 23:01:24 +000055 self.build_dir = os.path.join(tmp_dir, build_dir)
mbligha2508052006-05-28 21:29:53 +000056 # created by get_kernel_tree
mbligh1e8858e2006-11-24 22:18:35 +000057 self.config_dir = os.path.join(results_dir, 'config')
58 self.log_dir = os.path.join(results_dir, 'debug')
59 self.results_dir = os.path.join(results_dir, 'results')
60
61 if not leave:
62 if os.path.isdir(self.src_dir):
63 system('rm -rf ' + self.src_dir)
64 if os.path.isdir(self.build_dir):
65 system('rm -rf ' + self.build_dir)
66
mblighf4c35322006-03-13 01:01:10 +000067 os.mkdir(self.src_dir)
mbligh1e8858e2006-11-24 22:18:35 +000068 for path in [self.config_dir, self.log_dir, self.results_dir]:
69 if os.path.exists(path):
70 system('rm -rf ' + path)
71 os.mkdir(path)
mblighf4c35322006-03-13 01:01:10 +000072
mbligh4426de02006-10-10 07:18:28 +000073 logpath = os.path.join(self.log_dir, 'build_log')
74 self.logfile = open(logpath, 'w+')
75
mbligh72b88fc2006-12-16 18:41:35 +000076 self.target_arch = None
mblighfdbcaec2006-10-01 23:28:57 +000077 self.build_target = 'bzImage'
mbligh8baa2ea2006-12-17 23:01:24 +000078 self.build_image = None
mblighfdbcaec2006-10-01 23:28:57 +000079
mblighcac347a2007-06-02 17:21:48 +000080 if get_current_kernel_arch() == 'ia64':
81 self.build_target = 'all'
82 self.build_image = 'vmlinux.gz'
83
mblighfdbcaec2006-10-01 23:28:57 +000084 if leave:
85 return
mbligh534015f2006-09-15 03:28:56 +000086
mbligh4426de02006-10-10 07:18:28 +000087 self.logfile.write('BASE: %s\n' % base_tree)
apw2366d992007-03-12 20:35:57 +000088
89 # Where we have direct version hint record that
90 # for later configuration selection.
91 shorthand = re.compile(r'^\d+\.\d+\.\d+')
92 if shorthand.match(base_tree):
93 self.base_tree_version = base_tree
94 else:
95 self.base_tree_version = None
96
mbligh534015f2006-09-15 03:28:56 +000097 if os.path.exists(base_tree):
98 self.get_kernel_tree(base_tree)
99 else:
apw8ad56be2006-11-06 17:49:54 +0000100 args = self.job.config_get('mirror.ftp_kernel_org')
mbligh548f29a2006-10-17 04:55:12 +0000101 if args:
102 args = '-l ' + args
mbligh72b88fc2006-12-16 18:41:35 +0000103 base_components = kernelexpand(base_tree, args)
mbligh534015f2006-09-15 03:28:56 +0000104 print 'kernelexpand: '
105 print base_components
106 self.get_kernel_tree(base_components.pop(0))
107 if base_components: # apply remaining patches
108 self.patch(*base_components)
mblighf4c35322006-03-13 01:01:10 +0000109
110
mblighd016ecc2006-11-25 21:41:07 +0000111 def patch(self, *patches):
mblighc86b0b42006-07-28 17:35:28 +0000112 """Apply a list of patches (in order)"""
mbligh1e8858e2006-11-24 22:18:35 +0000113 if not patches:
114 return
mblighd016ecc2006-11-25 21:41:07 +0000115 # if isinstance(patches, basestring):
116 # patches = [patches]
mbligh534015f2006-09-15 03:28:56 +0000117 print 'Applying patches: ', patches
118 # self.job.stdout.redirect(os.path.join(self.log_dir, 'stdout'))
mblighf4c35322006-03-13 01:01:10 +0000119 local_patches = self.get_patches(patches)
mbligh4426de02006-10-10 07:18:28 +0000120 for patch in patches:
121 self.logfile.write('PATCH: %s\n' % patch)
mblighf4c35322006-03-13 01:01:10 +0000122 self.apply_patches(local_patches)
mbligh534015f2006-09-15 03:28:56 +0000123 # self.job.stdout.restore()
mblighf4c35322006-03-13 01:01:10 +0000124
125
apwb449c7d2006-12-05 12:21:44 +0000126 def config(self, config_file = '', config_list = None,
127 defconfig = False):
mbligh93057012006-08-06 15:51:56 +0000128 self.job.stdout.redirect(os.path.join(self.log_dir, 'stdout'))
mbligh678823f2006-12-07 18:49:00 +0000129 self.set_cross_cc()
apwb449c7d2006-12-05 12:21:44 +0000130 config = kernel_config.kernel_config(self.job, self.build_dir,
apw2366d992007-03-12 20:35:57 +0000131 self.config_dir, config_file, config_list,
132 defconfig, self.base_tree_version)
mblighf4c35322006-03-13 01:01:10 +0000133 self.job.stdout.restore()
134
135
136 def get_patches(self, patches):
mbligh1e8858e2006-11-24 22:18:35 +0000137 """fetch the patches to the local src_dir"""
mblighf4c35322006-03-13 01:01:10 +0000138 local_patches = []
139 for patch in patches:
mbligh1e8858e2006-11-24 22:18:35 +0000140 dest = os.path.join(self.src_dir, basename(patch))
141 print "get_file %s %s %s %s" % (patch, dest, self.src_dir, basename(patch))
mblighf4c35322006-03-13 01:01:10 +0000142 get_file(patch, dest)
143 local_patches.append(dest)
mbligh534015f2006-09-15 03:28:56 +0000144 return local_patches
mblighf4c35322006-03-13 01:01:10 +0000145
mbligh72b88fc2006-12-16 18:41:35 +0000146
mbligh534015f2006-09-15 03:28:56 +0000147 def apply_patches(self, local_patches):
mblighc86b0b42006-07-28 17:35:28 +0000148 """apply the list of patches, in order"""
mblighf4c35322006-03-13 01:01:10 +0000149 builddir = self.build_dir
150 os.chdir(builddir)
151
mbligh534015f2006-09-15 03:28:56 +0000152 if not local_patches:
mblighf4c35322006-03-13 01:01:10 +0000153 return None
mbligh534015f2006-09-15 03:28:56 +0000154 for patch in local_patches:
mblighf4c35322006-03-13 01:01:10 +0000155 print 'Patching from', basename(patch), '...'
mbligh4426de02006-10-10 07:18:28 +0000156 cat_file_to_cmd(patch, 'patch -p1 > /dev/null')
mbligh72b88fc2006-12-16 18:41:35 +0000157
158
159 def get_kernel_tree(self, base_tree):
mblighc49af7b2006-11-24 04:02:21 +0000160 """Extract/link base_tree to self.build_dir"""
mbligh5970cf02006-08-06 15:39:22 +0000161
162 # if base_tree is a dir, assume uncompressed kernel
163 if os.path.isdir(base_tree):
164 print 'Symlinking existing kernel source'
mblighc49af7b2006-11-24 04:02:21 +0000165 os.symlink(base_tree, self.build_dir)
mblighf4c35322006-03-13 01:01:10 +0000166
mbligh5970cf02006-08-06 15:39:22 +0000167 # otherwise, extract tarball
168 else:
mblighc49af7b2006-11-24 04:02:21 +0000169 os.chdir(os.path.dirname(self.src_dir))
170 # Figure out local destination for tarball
171 tarball = os.path.join(self.src_dir, os.path.basename(base_tree))
mbligh5970cf02006-08-06 15:39:22 +0000172 get_file(base_tree, tarball)
mbligh5970cf02006-08-06 15:39:22 +0000173 print 'Extracting kernel tarball:', tarball, '...'
mblighc49af7b2006-11-24 04:02:21 +0000174 extract_tarball_to_dir(tarball, self.build_dir)
mbligh5970cf02006-08-06 15:39:22 +0000175
mblighf4c35322006-03-13 01:01:10 +0000176
mblighfdbcaec2006-10-01 23:28:57 +0000177 def extraversion(self, tag, append=1):
178 os.chdir(self.build_dir)
mbligh4426de02006-10-10 07:18:28 +0000179 extraversion_sub = r's/^EXTRAVERSION =\s*\(.*\)/EXTRAVERSION = '
mblighfdbcaec2006-10-01 23:28:57 +0000180 if append:
mbligh4426de02006-10-10 07:18:28 +0000181 p = extraversion_sub + '\\1-%s/' % tag
mblighfdbcaec2006-10-01 23:28:57 +0000182 else:
mbligh4426de02006-10-10 07:18:28 +0000183 p = extraversion_sub + '-%s/' % tag
mbligh4c3fe4a2007-07-31 17:59:21 +0000184 system('mv Makefile Makefile.old')
185 system('sed "%s" < Makefile.old > Makefile' % p)
mblighfdbcaec2006-10-01 23:28:57 +0000186
187
188 def build(self, make_opts = '', logfile = '', extraversion='autotest'):
mblighc86b0b42006-07-28 17:35:28 +0000189 """build the kernel
mbligh72b88fc2006-12-16 18:41:35 +0000190
mblighc86b0b42006-07-28 17:35:28 +0000191 make_opts
192 additional options to make, if any
193 """
mbligh10038012006-10-19 03:32:45 +0000194 os_dep.commands('gcc', 'make')
mbligh6d4c9412006-09-13 23:08:44 +0000195 if logfile == '':
196 logfile = os.path.join(self.log_dir, 'kernel_build')
mblighf4c35322006-03-13 01:01:10 +0000197 os.chdir(self.build_dir)
mblighfdbcaec2006-10-01 23:28:57 +0000198 if extraversion:
199 self.extraversion(extraversion)
mbligh93057012006-08-06 15:51:56 +0000200 print os.path.join(self.log_dir, 'stdout')
mbligh6d4c9412006-09-13 23:08:44 +0000201 self.job.stdout.redirect(logfile + '.stdout')
202 self.job.stderr.redirect(logfile + '.stderr')
mbligha2508052006-05-28 21:29:53 +0000203 self.set_cross_cc()
mblighf4c35322006-03-13 01:01:10 +0000204 # setup_config_file(config_file, config_overrides)
apwc7846102006-04-06 18:22:13 +0000205
206 # Not needed on 2.6, but hard to tell -- handle failure
mblighfdbcaec2006-10-01 23:28:57 +0000207 system('make dep', ignorestatus=1)
mblighf4c35322006-03-13 01:01:10 +0000208 threads = 2 * count_cpus()
mbligh6d4c9412006-09-13 23:08:44 +0000209 build_string = 'make -j %d %s %s' % (threads, make_opts,
210 self.build_target)
211 # eg make bzImage, or make zImage
212 print build_string
213 system(build_string)
mblighf4c35322006-03-13 01:01:10 +0000214 if kernel_config.modules_needed('.config'):
apwd4701972006-10-16 09:24:56 +0000215 system('make -j %d modules' % (threads))
apwc7846102006-04-06 18:22:13 +0000216
mblighf4c35322006-03-13 01:01:10 +0000217 self.job.stdout.restore()
218 self.job.stderr.restore()
mbligh72b88fc2006-12-16 18:41:35 +0000219
mbligh4426de02006-10-10 07:18:28 +0000220 kernel_version = self.get_kernel_build_ver()
221 kernel_version = re.sub('-autotest', '', kernel_version)
222 self.logfile.write('BUILD VERSION: %s\n' % kernel_version)
mbligh1e8858e2006-11-24 22:18:35 +0000223
224 force_copy(self.build_dir+'/System.map', self.results_dir)
mblighf4c35322006-03-13 01:01:10 +0000225
226
227 def build_timed(self, threads, timefile = '/dev/null', make_opts = ''):
mblighc86b0b42006-07-28 17:35:28 +0000228 """time the bulding of the kernel"""
mblighb8a14e32006-05-06 00:17:35 +0000229 os.chdir(self.build_dir)
mbligh678823f2006-12-07 18:49:00 +0000230 self.set_cross_cc()
mblighb8a14e32006-05-06 00:17:35 +0000231 print "make clean"
232 system('make clean')
mbligha2bb9d62006-10-09 16:26:03 +0000233 build_string = "/usr/bin/time -o %s make %s -j %s vmlinux" % (timefile, make_opts, threads)
mblighf4c35322006-03-13 01:01:10 +0000234 print build_string
apwc7846102006-04-06 18:22:13 +0000235 system(build_string)
236 if (not os.path.isfile('vmlinux')):
237 raise TestError("no vmlinux found, kernel build failed")
mblighb8a14e32006-05-06 00:17:35 +0000238
239
240 def clean(self):
mblighc86b0b42006-07-28 17:35:28 +0000241 """make clean in the kernel tree"""
mblighb8a14e32006-05-06 00:17:35 +0000242 os.chdir(self.build_dir)
mblighf4c35322006-03-13 01:01:10 +0000243 print "make clean"
apwc7846102006-04-06 18:22:13 +0000244 system('make clean')
mblighf4c35322006-03-13 01:01:10 +0000245
mbligh50f42ea2006-09-30 22:22:21 +0000246
247 def mkinitrd(self, version, image, system_map, initrd):
248 """Build kernel initrd image.
249 Try to use distro specific way to build initrd image.
250 Parameters:
251 version
252 new kernel version
253 image
254 new kernel image file
255 system_map
256 System.map file
257 initrd
258 initrd image file to build
259 """
260 vendor = get_os_vendor()
261
262 if os.path.isfile(initrd):
mblighfdbcaec2006-10-01 23:28:57 +0000263 print "Existing %s file, will remove it." % initrd
mbligh50f42ea2006-09-30 22:22:21 +0000264 os.remove(initrd)
mbligh72b88fc2006-12-16 18:41:35 +0000265
mbligh50f42ea2006-09-30 22:22:21 +0000266 if vendor in ['Red Hat', 'Fedora Core']:
mblighfdbcaec2006-10-01 23:28:57 +0000267 system('mkinitrd %s %s' % (initrd, version))
mbligh50f42ea2006-09-30 22:22:21 +0000268 elif vendor in ['SUSE']:
mblighfdbcaec2006-10-01 23:28:57 +0000269 system('mkinitrd -k %s -i %s -M %s' % (image, initrd, system_map))
apwc898a1f2007-02-28 15:27:22 +0000270 elif vendor in ['Debian', 'Ubuntu']:
271 if os.path.isfile('/usr/sbin/mkinitrd'):
272 cmd = '/usr/sbin/mkinitrd'
273 elif os.path.isfile('/usr/sbin/mkinitramfs'):
274 cmd = '/usr/sbin/mkinitramfs'
275 else:
276 raise TestError('No Debian initrd builder')
277 system('%s -o %s %s' % (cmd, initrd, version))
mbligh50f42ea2006-09-30 22:22:21 +0000278 else:
mblighfdbcaec2006-10-01 23:28:57 +0000279 raise TestError('Unsupported vendor %s' % vendor)
mbligh50f42ea2006-09-30 22:22:21 +0000280
281
mbligh8baa2ea2006-12-17 23:01:24 +0000282 def set_build_image(self, image):
283 self.build_image = image
284
285
mbligh6a1d4db2006-10-06 04:30:16 +0000286 def install(self, tag='autotest', prefix = '/'):
mblighc86b0b42006-07-28 17:35:28 +0000287 """make install in the kernel tree"""
mblighf4c35322006-03-13 01:01:10 +0000288 os.chdir(self.build_dir)
mbligh72b88fc2006-12-16 18:41:35 +0000289
mbligh6a1d4db2006-10-06 04:30:16 +0000290 if not os.path.isdir(prefix):
291 os.mkdir(prefix)
mbligha87116f2006-10-10 02:47:08 +0000292 self.boot_dir = os.path.join(prefix, 'boot')
293 if not os.path.isdir(self.boot_dir):
294 os.mkdir(self.boot_dir)
mbligh0ad65582006-10-06 04:16:36 +0000295
mbligh8baa2ea2006-12-17 23:01:24 +0000296 if not self.build_image:
297 images = glob.glob('arch/*/boot/' + self.build_target)
298 if len(images):
299 self.build_image = images[0]
300 else:
301 self.build_image = self.build_target
mbligha87116f2006-10-10 02:47:08 +0000302
303 # remember installed files
mbligha87116f2006-10-10 02:47:08 +0000304 self.vmlinux = self.boot_dir + '/vmlinux-' + tag
mbligh8baa2ea2006-12-17 23:01:24 +0000305 if (self.build_image != 'vmlinux'):
apw9a61c5b2006-11-28 10:03:15 +0000306 self.image = self.boot_dir + '/vmlinuz-' + tag
307 else:
308 self.image = self.vmlinux
mbligha87116f2006-10-10 02:47:08 +0000309 self.system_map = self.boot_dir + '/System.map-' + tag
310 self.config = self.boot_dir + '/config-' + tag
311 self.initrd = ''
312
313 # copy to boot dir
mbligha87116f2006-10-10 02:47:08 +0000314 force_copy('vmlinux', self.vmlinux)
mbligh8baa2ea2006-12-17 23:01:24 +0000315 if (self.build_image != 'vmlinux'):
316 force_copy(self.build_image, self.image)
mbligha87116f2006-10-10 02:47:08 +0000317 force_copy('System.map', self.system_map)
318 force_copy('.config', self.config)
319
mbligh6a1d4db2006-10-06 04:30:16 +0000320 if not kernel_config.modules_needed('.config'):
321 return
322
323 system('make modules_install INSTALL_MOD_PATH=%s' % prefix)
324 if prefix == '/':
mbligha87116f2006-10-10 02:47:08 +0000325 self.initrd = self.boot_dir + '/initrd-' + tag
326 self.mkinitrd(self.get_kernel_build_ver(), self.image, \
327 self.system_map, self.initrd)
328
329
330 def add_to_bootloader(self, tag='autotest', args=''):
331 """ add this kernel to bootloader, taking an
332 optional parameter of space separated parameters
333 e.g.: kernel.add_to_bootloader('mykernel', 'ro acpi=off')
334 """
335
336 # remove existing entry if present
337 self.job.bootloader.remove_kernel(tag)
338
apwcbe32572006-11-28 10:00:23 +0000339 # pull the base argument set from the job config,
apwcbe32572006-11-28 10:00:23 +0000340 baseargs = self.job.config_get('boot.default_args')
mbligh78bc05e2006-12-25 02:29:59 +0000341 if baseargs:
342 args = baseargs + " " + args
343
344 # otherwise populate from /proc/cmdline
345 # if not baseargs:
346 # baseargs = open('/proc/cmdline', 'r').readline().strip()
347 # NOTE: This is unnecessary, because boottool does it.
apwcbe32572006-11-28 10:00:23 +0000348
mbligh78bc05e2006-12-25 02:29:59 +0000349 root = None
350 roots = [x for x in args.split() if x.startswith('root=')]
351 if roots:
352 root = re.sub('^root=', '', roots[0])
353 arglist = [x for x in args.split() if not x.startswith('root=')]
354 args = ' '.join(arglist)
mbligha87116f2006-10-10 02:47:08 +0000355
mbligh78bc05e2006-12-25 02:29:59 +0000356 # add the kernel entry
357 # add_kernel(image, title='autotest', initrd='')
358 self.job.bootloader.add_kernel(self.image, tag, self.initrd, \
359 args = args, root = root)
mbligh6a1d4db2006-10-06 04:30:16 +0000360
mbligh201aa892006-10-29 04:02:05 +0000361
mbligh548f29a2006-10-17 04:55:12 +0000362 def get_kernel_build_arch(self, arch=None):
mbligh201aa892006-10-29 04:02:05 +0000363 """
364 Work out the current kernel architecture (as a kernel arch)
365 """
mbligh548f29a2006-10-17 04:55:12 +0000366 if not arch:
367 arch = get_current_kernel_arch()
368 if re.match('i.86', arch):
369 return 'i386'
370 elif re.match('sun4u', arch):
371 return 'sparc64'
372 elif re.match('arm.*', arch):
373 return 'arm'
374 elif re.match('sa110', arch):
375 return 'arm'
376 elif re.match('s390x', arch):
377 return 's390'
378 elif re.match('parisc64', arch):
379 return 'parisc'
380 elif re.match('ppc.*', arch):
381 return 'powerpc'
382 elif re.match('mips.*', arch):
383 return 'mips'
384 else:
385 return arch
386
mbligh6a1d4db2006-10-06 04:30:16 +0000387
mblighda76b212007-07-19 16:50:41 +0000388 def boot(self, args='', once=True):
apw1b5dc362006-10-31 11:24:26 +0000389 """ install and boot this kernel, do not care how
390 just make it happen.
391 """
392
393 # Install this kernel.
394 self.install()
mblighda76b212007-07-19 16:50:41 +0000395 self.add_to_bootloader(args=args, tag='autotest')
396 if once:
397 self.job.bootloader.boot_once('autotest')
apw1b5dc362006-10-31 11:24:26 +0000398
399 # Boot it.
400 self.job.reboot()
401
402
mblighfdbcaec2006-10-01 23:28:57 +0000403 def get_kernel_build_ver(self):
mblighe11f5fc2006-10-04 04:42:22 +0000404 """Check Makefile and .config to return kernel version"""
405 version = patchlevel = sublevel = extraversion = localversion = ''
406
407 for line in open(self.build_dir + '/Makefile', 'r').readlines():
408 if line.startswith('VERSION'):
409 version = line[line.index('=') + 1:].strip()
410 if line.startswith('PATCHLEVEL'):
411 patchlevel = line[line.index('=') + 1:].strip()
412 if line.startswith('SUBLEVEL'):
413 sublevel = line[line.index('=') + 1:].strip()
414 if line.startswith('EXTRAVERSION'):
415 extraversion = line[line.index('=') + 1:].strip()
416
417 for line in open(self.build_dir + '/.config', 'r').readlines():
418 if line.startswith('CONFIG_LOCALVERSION='):
419 localversion = line.rstrip().split('"')[1]
420
mbligh72b88fc2006-12-16 18:41:35 +0000421 return "%s.%s.%s%s%s" %(version, patchlevel, sublevel, extraversion, localversion)
mblighfdbcaec2006-10-01 23:28:57 +0000422
423
mbligh8baa2ea2006-12-17 23:01:24 +0000424 def set_build_target(self, build_target):
425 if build_target:
426 self.build_target = build_target
427 print 'BUILD TARGET: %s' % self.build_target
428
429
mbligh5970cf02006-08-06 15:39:22 +0000430 def set_cross_cc(self, target_arch=None, cross_compile=None,
431 build_target='bzImage'):
mblighc86b0b42006-07-28 17:35:28 +0000432 """Set up to cross-compile.
mblighcc2e6662006-09-14 01:24:07 +0000433 This is broken. We need to work out what the default
434 compile produces, and if not, THEN set the cross
435 compiler.
mblighc86b0b42006-07-28 17:35:28 +0000436 """
mblighcc2e6662006-09-14 01:24:07 +0000437
mbligh5970cf02006-08-06 15:39:22 +0000438 if self.target_arch:
439 return
mbligh678823f2006-12-07 18:49:00 +0000440
mbligh8baa2ea2006-12-17 23:01:24 +0000441 # if someone has set build_target, don't clobber in set_cross_cc
442 # run set_build_target before calling set_cross_cc
443 if not self.build_target:
444 self.set_build_target(build_target)
mbligh72b88fc2006-12-16 18:41:35 +0000445
mbligh5970cf02006-08-06 15:39:22 +0000446 # If no 'target_arch' given assume native compilation
447 if target_arch == None:
mbligh548f29a2006-10-17 04:55:12 +0000448 target_arch = get_current_kernel_arch()
mbligh5970cf02006-08-06 15:39:22 +0000449 if target_arch == 'ppc64':
mbligh5970cf02006-08-06 15:39:22 +0000450 if self.build_target == 'bzImage':
apw9a61c5b2006-11-28 10:03:15 +0000451 self.build_target = 'vmlinux'
mbligh678823f2006-12-07 18:49:00 +0000452
453 if not cross_compile:
454 cross_compile = self.job.config_get('kernel.cross_cc')
455
456 if cross_compile:
457 os.environ['CROSS_COMPILE'] = cross_compile
458 else:
459 if os.environ.has_key('CROSS_COMPILE'):
460 del os.environ['CROSS_COMPILE']
461
mblighcc2e6662006-09-14 01:24:07 +0000462 return # HACK. Crap out for now.
mblighf4c35322006-03-13 01:01:10 +0000463
mblighcc2e6662006-09-14 01:24:07 +0000464 # At this point I know what arch I *want* to build for
465 # but have no way of working out what arch the default
466 # compiler DOES build for.
467
468 # Oh, and BTW, install_package() doesn't exist yet.
mbligh72b88fc2006-12-16 18:41:35 +0000469
mblighcc2e6662006-09-14 01:24:07 +0000470 if target_arch == 'ppc64':
471 install_package('ppc64-cross')
mbligh678823f2006-12-07 18:49:00 +0000472 cross_compile = os.path.join(self.autodir, 'sources/ppc64-cross/bin')
mblighcc2e6662006-09-14 01:24:07 +0000473
474 elif target_arch == 'x86_64':
475 install_package('x86_64-cross')
mbligh678823f2006-12-07 18:49:00 +0000476 cross_compile = os.path.join(self.autodir, 'sources/x86_64-cross/bin')
mblighb8a14e32006-05-06 00:17:35 +0000477
mbligh5970cf02006-08-06 15:39:22 +0000478 os.environ['ARCH'] = self.target_arch = target_arch
479
480 self.cross_compile = cross_compile
481 if self.cross_compile:
482 os.environ['CROSS_COMPILE'] = self.cross_compile
mblighcc2e6662006-09-14 01:24:07 +0000483
mbligh72b88fc2006-12-16 18:41:35 +0000484
mblighb8a14e32006-05-06 00:17:35 +0000485 def pickle_dump(self, filename):
mblighc86b0b42006-07-28 17:35:28 +0000486 """dump a pickle of ourself out to the specified filename
487
488 we can't pickle the backreference to job (it contains fd's),
mbligh709bb9b2006-10-12 04:32:16 +0000489 nor would we want to. Same for logfile (fd's).
mblighc86b0b42006-07-28 17:35:28 +0000490 """
mblighb8a14e32006-05-06 00:17:35 +0000491 temp = copy.copy(self)
492 temp.job = None
mbligh709bb9b2006-10-12 04:32:16 +0000493 temp.logfile = None
mblighb8a14e32006-05-06 00:17:35 +0000494 pickle.dump(temp, open(filename, 'w'))