Skip to content

Commit

Permalink
kernel headers: Update comparison logic
Browse files Browse the repository at this point in the history
Update comparison logic used to figure out the headers
that need to be added or removed from the corresponding
blueprint file.

Change-Id: I1f8eeea9750074d57868593a9693c016644e3682
Signed-off-by: Siddharth Gupta <[email protected]>
Signed-off-by: Rishabh Bhatnagar <[email protected]>
Signed-off-by: Naitik Bharadiya <[email protected]>
  • Loading branch information
Siddharth Gupta authored and Naitik Bharadiya committed Apr 9, 2020
1 parent 7347e05 commit cbb01b5
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions kernel_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,50 @@ def gen_blueprints(

return 0

def parse_bp_for_headers(file_name, headers):
parsing_headers = False
pattern = re.compile("gen_headers_[a-zA-Z0-9]+\s*=\s*\[\s*")
with open(file_name, 'r') as f:
for line in f:
line = line.strip()
if pattern.match(line):
parsing_headers = True
continue

if line.find("]") != -1 and parsing_headers:
break

if not parsing_headers:
continue

if line.find("//") == 0:
continue

headers.add(line[1:-2])

def headers_diff(old_file, new_file):
old_headers = set()
new_headers = set()
diff_detected = False

parse_bp_for_headers(old_file, old_headers)
parse_bp_for_headers(new_file, new_headers)

diff = old_headers - new_headers
if len(diff):
diff_detected = True
print("Headers to remove:")
for x in diff:
print("\t{}".format(x))

diff = new_headers - old_headers
if len(diff):
diff_detected = True
print("Headers to add:")
for x in diff:
print("\t{}".format(x))

return diff_detected

def gen_headers(
verbose, header_arch, gen_dir, arch_asm_kbuild, asm_generic_kbuild, module_dir,
Expand Down Expand Up @@ -799,9 +843,9 @@ def gen_headers(
The number of errors encountered.
"""

if not filecmp.cmp(old_gen_headers_bp, new_gen_headers_bp):
if headers_diff(old_gen_headers_bp, new_gen_headers_bp):
print('error: gen_headers blueprints file is out of date, suggested fix:')
print('cp %s %s' % (new_gen_headers_bp, old_gen_headers_bp))
print('#######Please add or remove the above mentioned headers from %s' % (old_gen_headers_bp))
print('then re-run the build')
return 1

Expand Down

0 comments on commit cbb01b5

Please sign in to comment.