]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/initialize.py
Chnage conf paths from absolute to relative
[linux-conf-perf.git] / scripts / initialize.py
1 import os
2 import sys
3 import subprocess
4 import shutil
5
6 import utils
7 from conf import conf
8 from conf import sf
9 from exceptions import MissingFile
10
11 def parse_kconfig():
12         "Execute parse_kconfig in linux_sources directory."
13         env = dict(os.environ)
14         wd = os.getcwd()
15         os.chdir(sf(conf.linux_sources))
16         if conf.parse_kconfig_output:
17                 subprocess.call([sf(conf.parse_kconfig), sf(conf.linux_kconfig_head), sf(conf.build_folder), "-v", "-v"], env=utils.get_kernel_env())
18         else:
19                 subprocess.call([sf(conf.parse_kconfig), sf(conf.linux_kconfig_head), sf(conf.build_folder)], env=utils.get_kernel_env())
20
21         os.chdir(wd)
22
23 def gen_requred():
24         "Generates required depenpency from .config file in linux source tree."
25
26         if not os.path.isfile(sf(conf.linux_dot_config)):
27                 raise MissingFile(sf(conf.linux_dot_config),
28                                 'Generate initial configuration. Execute make defconfig in linux folder. Or use make menuconfig and change configuration.')
29
30         utils.build_symbol_map() # Ensure smap existence
31         srmap = {value:key for key, value in utils.smap.items()}
32
33         try:
34                 os.remove(sf(conf.required_file))
35                 os.remove(sf(conf.dot_config_fragment_file))
36         except OSError:
37                 pass
38
39         shutil.copy(sf(conf.linux_dot_config), sf(conf.dot_config_back_file))
40
41         with open(sf(conf.linux_dot_config), 'r') as f:
42                 with open(sf(conf.required_file), 'w') as freq:
43                         with open(sf(conf.dot_config_fragment_file), 'w') as fconf:
44                                 for line in f:
45                                         if (line[0] == '#') or (not '=' in line):
46                                                 continue
47                                         indx = line.index('=')
48                                         if (line[7:indx] == "MODULES"): # skip if modules set
49                                                 raise exceptions.ConfigurationError("Initial kernel configuration must have MODULES disabled.")
50                                         if (line[indx + 1] == 'y'):
51                                                 freq.write(srmap[line[7:indx]] + "\n")
52                                         elif (line[indx + 1] == 'n' or line[indx + 1] == 'm'):
53                                                 freq.write("-" + srmap[line[7:indx]] + "\n")
54                                         else:
55                                                 fconf.write(line);
56                         freq.write("-" + srmap["MODULES"] + "\n"); # force modules no