17 except exceptions.DirtyRepository as e:
18 print("Warning: " + str(e))
23 database.database() # check if database is initialized
26 print('Initialize base...')
28 os.mkdir(sf(conf.build_folder))
29 except FileExistsError:
32 os.mkdir(sf(conf.log_folder))
33 except FileExistsError:
37 "Execute parse_kconfig in linux_sources directory."
38 if os.path.isfile(sf(conf.symbol_map_file)) and \
39 os.path.isfile(sf(conf.rules_file)) and \
40 os.path.isfile(sf(conf.variable_count_file)):
41 print('Warning: parse_kconfig not executed. Files already exists.')
43 print('Executing parse_kconfig...')
45 os.chdir(sf(conf.linux_sources))
46 parse_kconfig_cmd = [sf(conf.parse_kconfig)]
47 parse_kconfig_cmd += [sf(conf.linux_kconfig_head), sf(conf.build_folder)]
48 parse_kconfig_cmd += ['-v', '-v']
49 utils.callsubprocess("parse_kconfig", parse_kconfig_cmd,
50 conf.parse_kconfig_output, env=utils.get_kernel_env())
54 def __gen_allconfig_fixed__():
56 os.chdir(sf(conf.linux_sources))
57 allconfig_cmd = [sf(conf.allconfig)]
58 allconfig_cmd += ['Kconfig', sf(conf.dot_config), sf(conf.dot_measure_file)]
59 allconfig_cmd += ['--inv']
60 utils.callsubprocess("allconfig_fixed", allconfig_cmd, False,
61 env = utils.get_kernel_env())
65 "Generates fixed depenpency from dot_config file."
66 print('Generating required configuration...')
68 if not os.path.isfile(sf(conf.dot_config)):
69 raise exceptions.MissingFile(sf(conf.dot_config),
70 'Generate fixed configuration. Use make dot_config.')
72 utils.build_symbol_map() # Ensure smap existence
73 srmap = {value:key for key, value in utils.smap.items()} # swap dictionary
75 shutil.copy(sf(conf.dot_config), sf(conf.dot_config_back_file))
76 __gen_allconfig_fixed__()
78 with open(sf(conf.dot_config), 'r') as f:
79 with open(sf(conf.fixed_file), 'w') as ffix:
81 if (line[0] == '#') or (not '=' in line):
83 indx = line.index('=')
84 if (line[indx + 1] == 'y'):
85 if line[7:indx] == "MODULES": # exception if modules set
86 raise exceptions.ConfigurationError("Fixed kernel configuration must have MODULES disabled.")
87 ffix.write(str(srmap[line[7:indx]]) + "\n")
88 elif (line[indx + 1] == 'n' or line[indx + 1] == 'm'):
89 ffix.write("-" + str(srmap[line[7:indx]]) + "\n")
90 with open(sf(conf.dot_measure_file), 'r') as f:
91 with open(sf(conf.measure_file), 'w') as fmes:
93 if (line[0] == '#') or (not '=' in line):
95 indx = line.index('=')
96 if line[7:indx] == "MODULES":
97 raise exceptions.ConfigurationError("Can't measure configuraion option MODULES. Not supported.")
98 fmes.write(str(srmap[line[7:indx]]) + "\n")
101 print("Checking if all configurations can be measured...")
102 utils.build_symbol_map()
104 with open(sf(conf.variable_count_file)) as f:
105 var_num = f.readline().rstrip()
106 conf_num = f.readline().rstrip()
107 with open(sf(conf.measure_file), 'r') as fi:
109 measure_list.add(int(ln))
110 for measure in measure_list:
111 tfile1 = configurations.__buildtempcnf__(var_num, (sf(conf.rules_file),
112 sf(conf.fixed_file)), [str(measure)])
113 tfile2 = configurations.__buildtempcnf__(var_num, (sf(conf.rules_file),
114 sf(conf.fixed_file)), [str(-1 * measure)])
116 configurations.__exec_sat__(tfile1, [], conf_num)
117 configurations.__exec_sat__(tfile2, [], conf_num)
118 except exceptions.NoSolution:
119 print("W: " + utils.smap[measure] + " won't be measured!")
121 #################################################################################
123 if __name__ == '__main__':