]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/initialize.py
Add implementation of hash indexing of configurations
[linux-conf-perf.git] / scripts / initialize.py
1 #!/bin/env python3
2 import os
3 import sys
4 import subprocess
5 import shutil
6
7 import utils
8 from conf import conf
9 from conf import sf
10 import exceptions
11 import loop
12 import solution
13
14 def all():
15         base()
16         gen_nbscript()
17         parse_kconfig()
18         gen_requred()
19         if conf.gen_all_solution_oninit:
20                 solution.generate()
21
22 def base():
23         try: os.mkdir(sf(conf.build_folder))
24         except FileExistsError:
25                 pass
26
27         if os.path.isfile(sf(conf.phase_file)):
28                 print("Warning: file " + conf.phase_file + " already exists. Not overwritten.")
29         else:
30                 loop.phase_set(1)
31
32         if os.path.isfile(sf(conf.iteration_file)):
33                 print("Warning: file " + conf.iteration_file + " already exists. Not overwritten.")
34         else:
35                 loop.iteration_reset()
36
37
38 def parse_kconfig():
39         "Execute parse_kconfig in linux_sources directory."
40         env = dict(os.environ)
41         wd = os.getcwd()
42         os.chdir(sf(conf.linux_sources))
43         parse_kconfig_cmd = [sf(conf.parse_kconfig)]
44         parse_kconfig_cmd += [sf(conf.linux_kconfig_head), sf(conf.build_folder)]
45         parse_kconfig_cmd += ['-v', '-v']
46         utils.callsubprocess("parse_kconfig", parse_kconfig_cmd,
47                         conf.parse_kconfig_output, env=utils.get_kernel_env())
48         os.chdir(wd)
49
50
51 def gen_requred():
52         "Generates required depenpency from .config file in linux source tree."
53
54         if not os.path.isfile(sf(conf.linux_dot_config)):
55                 raise exceptions.MissingFile(sf(conf.linux_dot_config),
56                                 'Generate initial configuration. Execute make defconfig in linux folder. Or use make menuconfig and change configuration.')
57
58         utils.build_symbol_map() # Ensure smap existence
59         srmap = {value:key for key, value in utils.smap.items()}
60
61         shutil.copy(sf(conf.linux_dot_config), sf(conf.dot_config_back_file))
62
63         with open(sf(conf.linux_dot_config), 'r') as f:
64                 with open(sf(conf.required_file), 'w') as freq:
65                         with open(sf(conf.dot_config_fragment_file), 'w') as fconf:
66                                 for line in f:
67                                         if (line[0] == '#') or (not '=' in line):
68                                                 continue
69                                         indx = line.index('=')
70                                         if (line[7:indx] == "MODULES"): # skip if modules set
71                                                 raise exceptions.ConfigurationError("Initial kernel configuration must have MODULES disabled.")
72                                         if (line[indx + 1] == 'y'):
73                                                 freq.write(str(srmap[line[7:indx]]) + "\n")
74                                         elif (line[indx + 1] == 'n' or line[indx + 1] == 'm'):
75                                                 freq.write("-" + str(srmap[line[7:indx]]) + "\n")
76                                         else:
77                                                 fconf.write(line);
78                         freq.write("-" + str(srmap["MODULES"]) + "\n"); # force modules no
79
80
81 def gen_nbscript():
82         if os.path.isfile(sf(conf.nbscript)):
83                 print("Warning: file " + conf.nbscript +
84                                 " already exists. Generation skipped.")
85                 return
86
87         with open(sf(conf.nbscript), 'w') as f:
88                 f.write('# generated novaboot script. Please don\'t edit unless you know what are you doing.\n')
89                 f.write('load ' + sf(conf.linux_image) + ' console=ttyS0,115200\n')
90                 f.write('load ' + sf(conf.buildroot_initram) + '\n')
91
92 #################################################################################
93
94 if __name__ == '__main__':
95         all()