9 from exceptions import NoSolution
12 """Collect boolean equations from files: rules, solved and required
13 And get solution with minisat
15 Relevant configurations
21 # Check if rules_file exist. If it was generated.
22 if not os.path.isfile(sf(conf.rules_file)):
23 raise Exception("Rules file missing. Run parse_kconfig and check ecistence of " + rules_file)
25 w_file = tempfile.NamedTemporaryFile(delete=False)
26 # Join files to one single temporary file
28 with open(sf(conf.rules_file), 'r') as f:
29 for lnn in open(sf(conf.rules_file), 'r'):
33 if os.path.isfile(sf(conf.solved_file)):
34 for lnn in open(sf(conf.solved_file), 'r'):
38 if os.path.isfile(sf(conf.required_file)):
39 for lnn in open(sf(conf.required_file), 'r'):
44 with open(sf(conf.variable_count_file)) as f:
45 var_num = f.readline()
46 lines_count = len(lines)
48 first_line = "p cnf " + var_num + " " + str(lines_count)
49 w_file.write(bytes(first_line + '\n', 'UTF-8'))
51 w_file.write(bytes(ln + ' 0\n', 'UTF-8'))
56 if conf.minisat_output:
57 subprocess.call([conf.picosat, w_file.name, '-o',
58 sf(conf.solution_file)] + conf.picosat_args)
60 subprocess.call([conf.picosat, w_file.name, '-o',
61 sf(conf.solution_file)] + conf.picosat_args,
62 stdout=subprocess.DEVNULL)
64 os.remove(w_file.name)
67 """Apply generated solution to kernel source.
69 # Check if solution_file exist
70 if not os.path.isfile(sf(conf.solution_file)):
71 raise Exception("Solution file is missing. Run sat_solution and check existence of " + sf(conf.solution_file))
73 utils.build_symbol_map() # Ensure smap existence
75 # Read solution if satisfiable
77 with open(sf(conf.solution_file), 'r') as f:
78 if not f.readline().rstrip() == 's SATISFIABLE':
82 solut += line[2:].split()
83 solut.remove('0') # Remove 0 at the end
85 # Write solution to output_confs file
86 with open(sf(conf.output_confs), 'a') as f:
88 with open(sf(conf.iteration_file)) as ff:
89 iteration = int(ff.readline())
90 f.write(str(iteration) + ':')
95 # Write negotation solution to solver_file
96 with open(sf(conf.solved_file), 'a') as f:
103 f.write( ntx + txt + " ")
106 # Load variable count
107 with open(sf(conf.symbol_map_file)) as f:
108 for var_num, l in enumerate(f):
111 # Write solution to .config file in linux source folder
112 with open(sf(conf.linux_dot_config), 'w') as f:
119 if int(txt) >= var_num:
121 if 'NONAMEGEN' in utils.smap[txt]: # ignore generated names
124 f.write('CONFIG_' + utils.smap[txt] + '=')