mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 1 | # TODO: need a function to get the newest config file older than us from |
| 2 | # the repo. |
| 3 | |
| 4 | from autotest_utils import * |
| 5 | |
| 6 | def apply_overrides(orig_file, changes_file, output_file): |
| 7 | # First suck all the changes into a dictionary. |
| 8 | input = file(changes_file, 'r') |
| 9 | for line in input.readlines(): |
| 10 | [key] = line.split('=')[0:1] |
| 11 | if key.startswith('CONFIG_'): |
| 12 | override[key] = line; |
| 13 | input.close() |
| 14 | |
| 15 | # Now go through the input file, overriding lines where need be |
| 16 | input = file(orig_file, 'r') |
| 17 | ouput = file(output_file, 'w') |
| 18 | for line in input.readlines(): |
| 19 | key = line.split('=')[0:1] |
| 20 | if override[key]: |
| 21 | output.write(override[key]) |
| 22 | else: |
| 23 | output.write(line) |
| 24 | input.close() |
| 25 | output.close() |
| 26 | |
| 27 | |
| 28 | def diff_configs(old, new): |
mbligh | fd9ee23 | 2006-05-03 16:36:33 +0000 | [diff] [blame] | 29 | system('diff -u %s %s > %s' % (old, new, new + '.diff'), ignorestatus=1) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | |
| 33 | def modules_needed(config): |
| 34 | return (grep('CONFIG_MODULES=y', config) and grep('=m', config)) |
| 35 | |
| 36 | class kernel_config: |
| 37 | # Build directory must be ready before init'ing config. |
| 38 | # |
| 39 | # Stages: |
| 40 | # 1. Get original config file |
| 41 | # 2. Apply overrides |
| 42 | # 3. Do 'make oldconfig' to update it to current source code |
| 43 | # (gets done implicitly during the process) |
| 44 | # |
| 45 | # You may specifiy the a defconfig within the tree to build, |
| 46 | # or a custom config file you want, or None, to get machine's |
| 47 | # default config file from the repo. |
| 48 | |
| 49 | build_dir = '' # the directory we're building in |
| 50 | config_dir = '' # local repository for config_file data |
| 51 | |
| 52 | build_config = '' # the config file in the build directory |
| 53 | orig_config = '' # the original config file |
| 54 | over_config = '' # config file + overrides |
| 55 | |
| 56 | def __init__(self, build_dir, config_dir, orig_file, overrides): |
| 57 | self.build_dir = build_dir |
| 58 | self.config_dir = config_dir |
| 59 | |
| 60 | # 1. Get original config file |
| 61 | self.build_config = build_dir + '/.config' |
mbligh | 43cd6d0 | 2006-08-31 14:38:09 +0000 | [diff] [blame] | 62 | if (orig_file == ''): # use defconfig |
| 63 | os.chdir(build_dir) |
| 64 | system('make defconfig') |
| 65 | else: |
| 66 | self.orig_config = config_dir + '/config.orig' |
| 67 | get_file(orig_file, self.orig_config) |
| 68 | self.update_config(self.orig_config, self.orig_config+'.new') |
| 69 | diff_configs(self.orig_config, self.orig_config+'.new') |
| 70 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 71 | |
| 72 | # 2. Apply overrides |
| 73 | if overrides: |
| 74 | self.over_config = config_dir + '/config.over' |
| 75 | apply_overrides(self.orig_config, overrides, over_config) |
| 76 | self.update_config(self.over_config, self.over_config+'.new') |
| 77 | diff_configs(self.over_config, self.over_config+'.new') |
| 78 | else: |
| 79 | self.over_config = self.orig_config |
| 80 | |
| 81 | |
| 82 | def update_config(self, old_config, new_config = 'None'): |
| 83 | os.chdir(self.build_dir) |
| 84 | shutil.copyfile(old_config, self.build_config) |
| 85 | system('yes "" | make oldconfig > /dev/null') |
| 86 | if new_config: |
| 87 | shutil.copyfile(self.build_config, new_config) |
| 88 | |