]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/initialize.py
Export int values to conf.mk
[linux-conf-perf.git] / scripts / initialize.py
1 #!/usr/bin/env python3
2 import os
3 import sys
4 import subprocess
5 import shutil
6
7 import utils
8 import database
9 from conf import conf
10 from conf import sf
11 import exceptions
12
13 def all():
14         try:
15                 utils.dirtycheck()
16         except exceptions.DirtyRepository as e:
17                 print("Warning: " + str(e))
18         base()
19         parse_kconfig()
20         gen_fixed()
21         # check if database is initialized
22         database.database()
23
24 def base():
25         print('Initialize base...')
26         try:
27                 os.mkdir(sf(conf.build_folder))
28         except FileExistsError:
29                 pass
30         try:
31                 os.mkdir(sf(conf.log_folder))
32         except FileExistsError:
33                 pass
34
35 def parse_kconfig():
36         "Execute parse_kconfig in linux_sources directory."
37         if os.path.isfile(sf(conf.symbol_map_file)) and \
38                         os.path.isfile(sf(conf.rules_file)) and \
39                         os.path.isfile(sf(conf.variable_count_file)):
40                 print('Warning: parse_kconfig not executed. Files already exists.')
41                 return
42         print('Executing parse_kconfig...')
43         wd = os.getcwd()
44         os.chdir(sf(conf.linux_sources))
45         parse_kconfig_cmd = [sf(conf.parse_kconfig)]
46         parse_kconfig_cmd += [sf(conf.linux_kconfig_head), sf(conf.build_folder)]
47         parse_kconfig_cmd += ['-v', '-v']
48         utils.callsubprocess("parse_kconfig", parse_kconfig_cmd,
49                         conf.parse_kconfig_output, env=utils.get_kernel_env())
50         os.chdir(wd)
51
52
53 def __gen_allconfig_fixed__():
54         wd = os.getcwd()
55         os.chdir(sf(conf.linux_sources))
56         allconfig_cmd = [sf(conf.allconfig)]
57         allconfig_cmd += ['Kconfig', sf(conf.dot_config), sf(conf.dot_measure_file)]
58         allconfig_cmd += ['--inv']
59         utils.callsubprocess("allconfig_fixed", allconfig_cmd, False,
60                         env = utils.get_kernel_env())
61         os.chdir(wd)
62
63 def gen_fixed():
64         "Generates fixed depenpency from dot_config file."
65         print('Generating required configuration...')
66
67         if not os.path.isfile(sf(conf.dot_config)):
68                 raise exceptions.MissingFile(sf(conf.dot_config),
69                                 'Generate fixed configuration. Use make dot_config.')
70
71         utils.build_symbol_map() # Ensure smap existence
72         srmap = {value:key for key, value in utils.smap.items()} # swap dictionary
73
74         shutil.copy(sf(conf.dot_config), sf(conf.dot_config_back_file))
75         __gen_allconfig_fixed__()
76
77         with open(sf(conf.dot_config), 'r') as f:
78                 with open(sf(conf.fixed_file), 'w') as ffix:
79                         for line in f:
80                                 if (line[0] == '#') or (not '=' in line):
81                                         continue
82                                 indx = line.index('=')
83                                 if (line[indx + 1] == 'y'):
84                                         if line[7:indx] == "MODULES": # exception if modules set
85                                                 raise exceptions.ConfigurationError("Fixed kernel configuration must have MODULES disabled.")
86                                         ffix.write(str(srmap[line[7:indx]]) + "\n")
87                                 elif (line[indx + 1] == 'n' or line[indx + 1] == 'm'):
88                                         ffix.write("-" + str(srmap[line[7:indx]]) + "\n")
89         with open(sf(conf.dot_measure_file), 'r') as f:
90                 with open(sf(conf.measure_file), 'w') as fmes:
91                         for line in f:
92                                 if (line[0] == '#') or (not '=' in line):
93                                         continue
94                                 indx = line.index('=')
95                                 if line[7:indx] == "MODULES":
96                                         raise exceptions.ConfigurationError("Can't measure configuraion option MODULES. Not supported.")
97                                 fmes.write(str(srmap[line[7:indx]]) + "\n")
98
99
100 #################################################################################
101
102 if __name__ == '__main__':
103         all()