bisdef/bisdef.py
2024-02-13 16:07:59 -05:00

77 lines
3.2 KiB
Python

#!/usr/bin/python
import sys, os, math, linecache, re
# change numerator and denominator variables progressively to perform a proper bissection search manually
numerator = 1
denominator = 2
defconfig_file_name = "defconfig_clean"
def usage():
print("""Usage: bissect_conf [<input_comparison_file> <config_in>]
Will output a defconfig file with the changes detected from the comparison_file to the config_in file
Example usage:
$ bissect_conf comparison_file defconfig_not_working
""")
sys.exit(0)
def main():
global merge_style
outup_f = open("defconfig", "w")
# parse command line args
if ("-h" in sys.argv or "--help" in sys.argv):
usage()
compare_file = open("compare.defconfig")
compare_file_data = compare_file.readlines()
compare_file_num = len(compare_file_data)
defconfig_file = open(defconfig_file_name)
defconfig_data = defconfig_file.readlines()
# split into number of chunks equal to denominator
denomi_lines = math.ceil(compare_file_num/denominator)
for i in range(denomi_lines*(numerator-1), denomi_lines*(numerator)): # first line is at 1
compare_file_line = compare_file_data[i]
##############################################################################################################
# the comparison file describes a change which starts with a "-"
if compare_file_line.startswith("-"):
compare_file_line = compare_file_line[1:]
current_config_name = "CONFIG_" + compare_file_line.split(" ")[0]
# cycle through entire defconfig file and search for config_name
for j in range(0, len(defconfig_data)):
if current_config_name+" " in defconfig_data[j] or current_config_name+"=" in defconfig_data[j]:
defconfig_data[j] = current_config_name+"="+compare_file_line.split(" ")[1]
if j == len(defconfig_data) - 1:
defconfig_data.append(current_config_name+"="+compare_file_line.split(" ")[1])
##############################################################################################################
# the comparison file describes a change which starts with a "+"
elif compare_file_line.startswith("+"):
compare_file_line = compare_file_line[1:]
current_config_name = "CONFIG_" + compare_file_line.split(" ")[0]
#current_config_name = current_config_name.strip()
# cycle through entire defconfig file and search for config_name
for j in range(0, len(defconfig_data)):
if current_config_name in defconfig_data[j]:
defconfig_data[j] = ""
##############################################################################################################
else:
current_config_name = "CONFIG_" + compare_file_line.split(" ")[1]
print(compare_file_line)
for j in range(0, len(defconfig_data)):
if current_config_name+" " in defconfig_data[j] or current_config_name+"=" in defconfig_data[j]:
defconfig_data[j] = current_config_name+"="+compare_file_line.split(" ")[2]+"\n"
outup_f.writelines(defconfig_data)
main()