Created
February 13, 2020 16:02
-
-
Save mbolivar/af8256b7b6d2ea448e634075b262f883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
from collections import namedtuple | |
from pathlib import Path | |
import colorama | |
STRICT_REDEFINITION = False | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--a-files', nargs='+', required=True) | |
parser.add_argument('--b-files', nargs='+', required=True) | |
args = parser.parse_args() | |
# print('a_files:\n\t', | |
# '\n\t'.join(args.a_files)) | |
# print('b_files:\n\t', | |
# '\n\t'.join(args.b_files)) | |
value_and_line = namedtuple('value_and_line', 'value line') | |
whoopsie = namedtuple('whoopsie', 'macro avl bvl') | |
filediff = namedtuple('filediff', 'a_only b_only whoopsies') | |
def get_macros(path): | |
with open(path, 'r') as f: | |
lines = f.readlines() | |
ret = {} | |
for i, line in enumerate(lines): | |
line_num = i + 1 | |
line = line.strip() | |
if not line.startswith('#define'): | |
continue | |
macro_value = line.split(' ', 1)[1] | |
macro, value = macro_value.split(' ', 1) | |
value = value.strip() | |
if macro in ret: | |
if ret[macro][0] != value or STRICT_REDEFINITION: | |
print(f'REDEFINITION: {macro}') | |
print(f'\tin: {path}:{line_num}') | |
print(f'\twas: {ret[macro][0]}') | |
print(f'\tis now: {value}') | |
ret[macro] = value_and_line(value, line_num) | |
return ret | |
def get_diff(a, b): | |
a_macros = get_macros(a) | |
b_macros = get_macros(b) | |
a_only = [] | |
b_only = [] | |
whoopsies = set() | |
for macro, avl in a_macros.items(): | |
if macro not in b_macros: | |
a_only.append((macro, avl)) | |
else: | |
bvl = b_macros[macro] | |
if avl.value != bvl.value: | |
whoopsies.add(whoopsie(macro, avl, bvl)) | |
for macro, bvl in b_macros.items(): | |
if macro not in a_macros: | |
b_only.append((macro, bvl)) | |
else: | |
avl = a_macros[macro] | |
if avl.value != bvl.value: | |
whoopsies.add(whoopsie(macro, avl, bvl)) | |
return filediff(a_only, b_only, whoopsies) | |
for a, b in zip(args.a_files, args.b_files): | |
diff = get_diff(a, b) | |
if not any(diff): | |
continue | |
print(colorama.Fore.LIGHTRED_EX, end='') | |
print('='*80) | |
print(f'diff detected between a: {Path(a).resolve()}\n' | |
f' b: {Path(b).resolve()}') | |
print('='*80) | |
print(colorama.Style.RESET_ALL, end='', flush=True) | |
if diff.a_only: | |
print() | |
print('-'*80) | |
print(f'MISSING VALUES ({len(diff.a_only)}):') | |
print('-'*80) | |
for macro, vl in diff.a_only: | |
print(f"[a line {vl.line:05}] {macro} -- {vl.value} --") | |
if diff.b_only: | |
print() | |
print('-'*80) | |
print(f'NEW ADDITIONS ({len(diff.b_only)}):') | |
print('-'*80) | |
for macro, vl in diff.b_only: | |
print(f"[b line {vl.line:05}] {macro} -- {vl.value} --") | |
if diff.whoopsies: | |
print() | |
print('-'*80) | |
print('INCORRECT VALUES') | |
print('-'*80) | |
for whoops in diff.whoopsies: | |
print(f'- {whoops.macro}:\n\t' | |
f'a={whoops.avl.value} at line {whoops.avl.line}\n\t' | |
f'vs.\n\t' | |
f'b={whoops.bvl.value} at line {whoops.bvl.line}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -o pipefail | |
COMMIT_A=3b60f09583 | |
COMMIT_B=905349ef0d | |
function cleanup() { | |
echo resetting tree | |
git checkout dt-augment-and-regs | |
} | |
trap cleanup EXIT | |
function banner() { | |
echo | |
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
echo $@ | |
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
} | |
function do_sanitycheck() { | |
sanitycheck --outdir $1 --cmake-only -T samples | |
} | |
tput reset | |
banner getting a baseline | |
git checkout $COMMIT_A | |
do_sanitycheck a | |
a_files=$(fd devicetree_unfixed a | sort) | |
banner getting updated macros | |
git checkout $COMMIT_B | |
do_sanitycheck b | |
b_files=$(fd devicetree_unfixed b | sort) | |
banner differences | |
differ --a-files $a_files --b-files $b_files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment