Allow specification of a local mirror

Signed-off-by: Martin J. Bligh <[email protected]>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@352 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/bin/autotest_utils.py b/bin/autotest_utils.py
index 5bac532..13a8a68 100755
--- a/bin/autotest_utils.py
+++ b/bin/autotest_utils.py
@@ -242,13 +242,9 @@
 		return 'i386'
 
 
-def get_kernel_arch():
-	"""Work out the current kernel architecture (as a kernel arch)"""
-	arch = os.popen('uname -m').read().rstrip()
-	if ((arch == 'i586') or (arch == 'i686')):
-		return 'i386'
-	else:
-		return arch
+def get_current_kernel_arch():
+	"""Get the machine architecture, now just a wrap of 'uname -m'."""
+	return os.popen('uname -m').read().rstrip()
 
 
 def get_file_arch(filename):
@@ -259,11 +255,13 @@
 	return None
 
 
-def kernelexpand(kernel):
+def kernelexpand(kernel, args=None):
 	# if not (kernel.startswith('http://') or kernel.startswith('ftp://') or os.path.isfile(kernel)):
 	if kernel.find('/') < 0:     # contains no path.
 		autodir = os.environ['AUTODIR']
 		kernelexpand = os.path.join(autodir, 'tools/kernelexpand')
+		if args:
+			kernelexpand += ' ' + args
 		w, r = os.popen2(kernelexpand + ' ' + kernel)
 
 		kernel = r.readline().strip()
diff --git a/bin/kernel.py b/bin/kernel.py
index d808d78..116f524 100755
--- a/bin/kernel.py
+++ b/bin/kernel.py
@@ -78,7 +78,10 @@
 		if os.path.exists(base_tree):
 			self.get_kernel_tree(base_tree)
 		else:
- 			base_components = kernelexpand(base_tree)
+			args = self.job.config.get('local_mirror')
+			if args:
+				args = '-l ' + args
+ 			base_components = kernelexpand(base_tree, args)
 			print 'kernelexpand: '
 			print base_components
 			self.get_kernel_tree(base_components.pop(0))
@@ -294,6 +297,29 @@
 		for a in args.split(' '):
 			self.job.bootloader.add_args(tag, a)
 
+	def get_kernel_build_arch(self, arch=None):
+		"""Work out the current kernel architecture (as a kernel arch)"""
+		if not arch:
+			arch = get_current_kernel_arch()
+		if re.match('i.86', arch):
+			return 'i386'
+		elif re.match('sun4u', arch):
+			return 'sparc64'
+		elif re.match('arm.*', arch):
+			return 'arm'
+		elif re.match('sa110', arch):
+			return 'arm'
+		elif re.match('s390x', arch):
+			return 's390'
+		elif re.match('parisc64', arch):
+			return 'parisc'
+		elif re.match('ppc.*', arch):
+			return 'powerpc'
+		elif re.match('mips.*', arch):
+			return 'mips'
+		else:
+			return arch
+
 
 	def get_kernel_build_ver(self):
 		"""Check Makefile and .config to return kernel version"""
@@ -331,7 +357,7 @@
 		
 		# If no 'target_arch' given assume native compilation
 		if target_arch == None:
-			target_arch = get_kernel_arch()
+			target_arch = get_current_kernel_arch()
 			if target_arch == 'ppc64':
 				if self.build_target == 'bzImage':
 					self.build_target = 'zImage'
diff --git a/samples/mirror b/samples/mirror
new file mode 100644
index 0000000..d3049a0
--- /dev/null
+++ b/samples/mirror
@@ -0,0 +1,3 @@
+testkernel = job.kernel(job.tmpdir+'/build', '2.6.14-rc1-mm1')
+job.config_set('local_mirror', 'http://foo/bar')
+testkernel = job.kernel(job.tmpdir+'/build', '2.6.14-rc1-mm1')
diff --git a/tools/kernelexpand b/tools/kernelexpand
index 7ae8b1f..2ffe47c 100755
--- a/tools/kernelexpand
+++ b/tools/kernelexpand
@@ -6,14 +6,14 @@
 use Getopt::Long;
 
 my $mirror = "ftp://ftp.kernel.org/pub/linux/kernel";
-my $local_mirror = "http://kernel.beaverton.ibm.com/mirror";
 my $kernelpset;
 my $relative;
+my $local_mirror;
 
 GetOptions("mirror|m=s" =>		\$mirror,
 	   "debug|d"	=>		\$debug,
 	   "relative|r"	=>		\$relative,
-	   "local|l"	=>		\$local);
+	   "local|l=s"	=>		\$local_mirror);
 
 ($kernelpset, @patches) = @ARGV;
 
@@ -26,7 +26,7 @@
 	$mirror = ""; 
 }
 
-if ($local) {
+if ($local_mirror) {
 	$mirror = "$local_mirror/kernel";
 	$akpm = "$local_mirror/akpm";
 	$mbligh = "$local_mirror/mbligh";
@@ -68,7 +68,7 @@
 	print "Found patchset $pset, type $psettype\n" if ($debug);
 
 	if ($psettype eq "mm") {
-		if ($local) {
+		if ($local_mirror) {
 			$patch = "$akpm/$kernel/$kernelpset/$kernelpset.bz2";
 		} else {
 			$patch = "$akpm/2.$minor/$kernel/$kernelpset/$kernelpset.bz2";