10 """Collect boolean equations from files: rules, solved and required
11 And get solution with minisat
13 Relevant configurations
19 # Check if rules_file exist. If it was generated.
20 if not os.path.isfile(conf.rules_file):
21 raise Exception("Rules file missing. Run kconfig_parse and check ecistence of " + rules_file)
23 w_file = tempfile.NamedTemporaryFile(delete=False)
24 # Join files to one single temporary file
26 with open(conf.rules_file, 'r') as f:
27 for lnn in open(conf.rules_file, 'r'):
31 if os.path.isfile(conf.solved_file):
32 for lnn in open(conf.solved_file, 'r'):
36 if os.path.isfile(conf.required_file):
37 for lnn in open(conf.required_file, 'r'):
42 with open(conf.symbol_map_file) as f:
43 for var_num, l in enumerate(f):
46 lines_count = len(lines)
48 first_line = "p cnf " + str(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 subprocess.call(['minisat', w_file.name, conf.solution_file])
58 os.remove(w_file.name)
61 """Apply generated solution to kernel source.
63 # Check if solution_file exist
64 if not os.path.isfile(conf.solution_file):
65 raise Exception("Solution file is missing. Run sat_solution and check existence of " + conf.solution_file)
67 utils.build_symbol_map() # Ensure smap existence
69 # Read solution if satisfiable
70 with open(conf.solution_file, 'r') as f:
71 if not f.readline().rstrip() == 'SAT':
73 solut = f.readline().split()
74 solut.remove('0') # Remove 0 at the end
76 # Write negotation solution to solver_file
77 with open(conf.solved_file, 'a') as f:
84 f.write( ntx + txt + " ")
87 # Write solution to .config file in linux source folder
88 with open(conf.linux_sources + '/.config', 'w') as f:
95 if 'NONAMEGEN' in txt: # ignore generated names
98 f.write('CONFIG_' + utils.smap[txt] + '=')