r3491 - trunk/scripts
Andres Salomon
dilinger@costa.debian.org
Fri, 15 Jul 2005 09:26:51 +0000
Author: dilinger
Date: 2005-07-15 09:26:46 +0000 (Fri, 15 Jul 2005)
New Revision: 3491
Added:
trunk/scripts/split-config
Log:
commit what i've got so far; it's lunchtime
Added: trunk/scripts/split-config
===================================================================
--- trunk/scripts/split-config 2005-07-15 09:09:27 UTC (rev 3490)
+++ trunk/scripts/split-config 2005-07-15 09:26:46 UTC (rev 3491)
@@ -0,0 +1,156 @@
+#!/usr/bin/ruby -w
+# split-config - manage kernel configs split out for each arch
+#
+# Copyright (C) 2005 Andres Salomon <dilinger@debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+require 'getoptlong'
+require 'open3'
+
+class Shell
+ def Shell.quote(s)
+ "'" + s.gsub("'") { |i| "'\\''" } + "'"
+ end
+
+ def Shell.quote!(s)
+ s.replace(quote(s))
+ end
+
+ def Shell.command(cmd)
+ if cmd.class == Array
+ s = cmd.shift
+ cmd.each { |arg|
+ s += ' ' + Shell.quote(arg)
+ }
+ cmd = s
+ end
+
+ ret = Open3.popen3(cmd + ';echo $?') { |si,so,se|
+ [ so.readlines, se.readlines ]
+ }
+ errno = ret[0].pop.to_i
+ raise "Error: cannot execute command #{cmd}: #{ret[1].join('')}" if errno != 0
+ ret
+ end
+end
+
+def parse_config(file, kconf)
+ File.open(file).each { |line|
+ if line =~ /^(CONFIG_\w+)=(\w)$/
+ kconf[$1.upcase] = $2.downcase
+ elsif line =~ /^\s*#\s*(CONFIG_\w+) is not set\s*$/
+ kconf[$1.upcase] = 'n'
+ end
+ }
+ kconf
+end
+
+def configline(key, val)
+ if val == 'n'
+ "# #{key.upcase} is not set\n"
+ else
+ "#{key.upcase}=#{val.downcase}\n"
+ end
+end
+
+def collect(path, archdirs, flavour)
+ kconf = {}
+ if File.exists?("#{path}/config")
+ puts "parsing #{path}/config"
+ kconf = parse_config("#{path}/config", kconf)
+ end
+ archdirs.split(Regexp.new('/+')).each { |piece|
+ path += piece + '/'
+ if File.exists?("#{path}/config")
+ puts "parsing #{path}/config"
+ kconf = parse_config("#{path}/config", kconf)
+ end
+ }
+ puts "parsing #{path}/config.#{flavour}"
+ parse_config("#{path}/config.#{flavour}", kconf)
+end
+
+def mkconfig(kconf)
+ File.open('.config', 'w') { |f|
+ kconf.each { |key,val|
+ f << configline(key, val)
+ }
+ }
+ Shell.command("make #{OPTIONS['configtype']} ARCH=#{OPTIONS['arch']}")
+end
+
+def usage(errno)
+ s = errno == 0 ? $stdout : $stderr
+ s.puts "Usage: #{$0} [options] <config dir> <flavour>\n"
+ s.puts "\t-a, --arch <arch> select architecture [#{OPTIONS['arch']}]"
+ s.puts "\t-s, --subarch <arch> select sub-architecture [#{OPTIONS['subarch']}]"
+ s.puts "\t-c, --configtype <type> select config type [#{OPTIONS['configtype']}]"
+ s.puts "\t-h, --help display this help screen"
+ exit(errno)
+end
+
+opts = GetoptLong.new(
+ [ '--arch', '-a', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--subarch', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--configtype', '-c', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ]
+)
+OPTIONS =
+{
+ 'arch' => `dpkg-architecture -qDEB_HOST_ARCH`.chomp,
+ 'subarch' => nil,
+ 'configtype' => 'menuconfig',
+ 'dir' => nil,
+ 'flavour' => nil,
+}
+
+begin
+ opts.each { |opt, arg|
+ case opt
+ when '--arch'
+ OPTIONS['arch'] = arg
+ when '--subarch'
+ OPTIONS['subarch'] = arg
+ when '--configtype'
+ OPTIONS['configtype'] = arg
+ when '--help'
+ usage(0)
+ end
+ }
+
+ if ARGV.length == 2
+ OPTIONS['dir'] = ARGV[0]
+ OPTIONS['flavour'] = ARGV[1]
+ else
+ usage(1)
+ end
+rescue => e
+ usage(1)
+end
+
+path = OPTIONS['arch']
+path += '/' + OPTIONS['subarch'] unless OPTIONS['subarch'].nil?
+kconf = collect(OPTIONS['dir'], path, OPTIONS['flavour'])
+mkconfig(kconf)
+#kconf.each {|key, val|
+# puts "key: #{key}, val: #{val}"
+#}
+newconf = parse_config('.config', {})
+diff = newconf - kconf
+puts diff.inspect
+
+exit(0)
Property changes on: trunk/scripts/split-config
___________________________________________________________________
Name: svn:executable
+ *