import argparse
import os
-import filecmp
import yaml
from collections import OrderedDict
return filtered_files
+# because EOL may not be LF(\n) on some environment (e.g. Windows),
+# normalize EOL from CRLF/CR to LF and compare both files.
+def cmpfiles_with_eol_normalization(a, b, names):
+ results = ([], [], []) # match, mismatch, error
+ for x in names:
+ try:
+ ax = open(os.path.join(a, x), 'r').read().replace('\r\n', '\n').replace('\r', '\n')
+ bx = open(os.path.join(b, x), 'r').read().replace('\r\n', '\n').replace('\r', '\n')
+ if ax == bx:
+ results[0].append(x)
+ else:
+ results[1].append(x)
+ except OSError:
+ results[2].append(x)
+ return results
+
+
def generate_outputs():
cwrap_files = filter_by_extension(options.files, '.cwrap')
nn_files = filter_by_extension(options.files, 'nn.yaml', '.h')
# check that generated files match source files
core_source_path = os.path.join(options.source_path, 'core')
- match, mismatch, errors = filecmp.cmpfiles(core_install_dir, core_source_path, core_files.keys(), shallow=False)
+ match, mismatch, errors = cmpfiles_with_eol_normalization(core_install_dir, core_source_path, core_files.keys())
if errors:
raise RuntimeError("Error while trying to compare source and generated files for {}. "
"Source directory: {}. Generated directory: {}."