13 """Collect boolean equations from files: rules, solved and required
14 And get solution with picosat
16 # Check if rules_file exist. If it was generated.
17 if not os.path.isfile(sf(conf.rules_file)):
18 raise exceptions.MissingFile(conf.rules_file,"Run parse_kconfig.")
20 if os.path.isfile(sf(conf.solution_file)):
21 raise exceptions.SolutionGenerated()
23 w_file = tempfile.NamedTemporaryFile(delete=False)
24 # Join files to one single temporary file
26 with open(sf(conf.rules_file), 'r') as f:
27 for lnn in open(sf(conf.rules_file), 'r'):
31 if os.path.isfile(sf(conf.required_file)):
32 for lnn in open(sf(conf.required_file), 'r'):
37 with open(sf(conf.variable_count_file)) as f:
38 var_num = f.readline()
39 lines_count = len(lines)
41 first_line = "p cnf " + var_num + " " + str(lines_count)
42 w_file.write(bytes(first_line + '\n', 'UTF-8'))
44 w_file.write(bytes(ln + ' 0\n', 'UTF-8'))
50 os.mkdir(sf(conf.log_folder))
54 picosat_cmd = [sf(conf.picosat), w_file.name]
55 picosat_cmd += conf.picosat_args
57 satprc = subprocess.Popen(picosat_cmd, stdout = subprocess.PIPE)
58 with open(os.path.join(sf(conf.log_folder), "picosat.log"), 'a') as f:
59 f.write("::" + time.strftime("%y-%m-%d-%H-%M-%S") + "::\n")
61 for linen in satprc.stdout:
62 line = linen.decode(sys.getdefaultencoding())
64 if conf.picosat_output:
69 with open(sf(conf.config_map_file), 'a') as fm:
70 fm.write(str(utils.hash_config(solut)) + ':')
72 fm.write(str(sl) + ' ')
77 if not line.rstrip() == 's SATISFIABLE':
78 os.remove(w_file.name)
79 raise exceptions.NoSolution()
81 for sl in line[2:].split():
84 os.remove(w_file.name)
87 """Apply generated solution to kernel source.
89 utils.build_symbol_map() # Ensure smap existence
93 # Load set of solved solutions
94 if os.path.isfile(sf(conf.config_solved_file)):
95 with open(sf(conf.config_solved_file)) as f:
97 solved.add(ln.strip())
99 # Load one solution if it is not in solved
101 with open(sf(conf.config_map_file)) as f:
103 w = f.readline().split(sep=':')
106 if not w[0] in solved:
107 solution = utils.config_strtoint(w[1], True)
111 raise exceptions.NoApplicableSolution()
113 # Write hash to config_solved
114 with open(sf(conf.config_solved_file), 'a') as f:
118 # Load variable count
119 with open(sf(conf.symbol_map_file)) as f:
120 for var_num, l in enumerate(f):
123 # Write solution to .config file in linux source folder
124 with open(sf(conf.linux_dot_config), 'w') as f:
133 if 'NONAMEGEN' in utils.smap[s]: # ignore generated names
136 f.write('CONFIG_' + utils.smap[s] + '=')