8 from exceptions import NoSolution
11 """Collect boolean equations from files: rules, solved and required
12 And get solution with minisat
14 Relevant configurations
20 # Check if rules_file exist. If it was generated.
21 if not os.path.isfile(conf.rules_file):
22 raise Exception("Rules file missing. Run kconfig_parse and check ecistence of " + rules_file)
24 w_file = tempfile.NamedTemporaryFile(delete=False)
25 # Join files to one single temporary file
27 with open(conf.rules_file, 'r') as f:
28 for lnn in open(conf.rules_file, 'r'):
32 if os.path.isfile(conf.solved_file):
33 for lnn in open(conf.solved_file, 'r'):
37 if os.path.isfile(conf.required_file):
38 for lnn in open(conf.required_file, 'r'):
43 with open(conf.symbol_map_file) as f:
44 for var_num, l in enumerate(f):
47 lines_count = len(lines)
49 first_line = "p cnf " + str(var_num) + " " + str(lines_count)
50 w_file.write(bytes(first_line + '\n', 'UTF-8'))
52 w_file.write(bytes(ln + ' 0\n', 'UTF-8'))
57 if conf.minisat_output:
58 subprocess.call(['minisat', w_file.name, conf.solution_file])
60 subprocess.call(['minisat', w_file.name, conf.solution_file], stdout=subprocess.DEVNULL)
62 os.remove(w_file.name)
65 """Apply generated solution to kernel source.
67 # Check if solution_file exist
68 if not os.path.isfile(conf.solution_file):
69 raise Exception("Solution file is missing. Run sat_solution and check existence of " + conf.solution_file)
71 utils.build_symbol_map() # Ensure smap existence
73 # Read solution if satisfiable
74 with open(conf.solution_file, 'r') as f:
75 if not f.readline().rstrip() == 'SAT':
77 solut = f.readline().split()
78 solut.remove('0') # Remove 0 at the end
80 # Write negotation solution to solver_file
81 with open(conf.solved_file, 'a') as f:
88 f.write( ntx + txt + " ")
91 # Write solution to .config file in linux source folder
92 with open(conf.linux_sources + '/.config', 'w') as f:
93 with open(conf.dot_config_file, 'r') as fconf:
103 if 'NONAMEGEN' in utils.smap[txt]: # ignore generated names
106 f.write('CONFIG_' + utils.smap[txt] + '=')