Commit 98f98e42 authored by Allison Pastewka's avatar Allison Pastewka Committed by Commit Bot

Make run_bindings_tests.py presubmit test run on Windows

Added checks to see if the test is being run on windows and if so
replaced the backslashes with forward slashes. I also changed the file
open to write the file in binary so that line endings are not
converted.

Change diffing tool being used from diff(1) to Python's difflib module.
diff(1) is a Unix diffing tool so it does not run on Windows.
Python's difflib module will work on all computers and the speed of
the module won't be an issue because there is a fairly small number
of test files.

Bug: 929019
Change-Id: I24e43f6599a8ce839af4dc2cec18dc56acd13bad
Reviewed-on: https://chromium-review.googlesource.com/c/1479309Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Commit-Queue: Allison Pastewka <alpastew@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#636956}
parent ea6f759a
......@@ -19,7 +19,7 @@ from v8_methods import method_filters
from v8_utilities import capitalize
from utilities import (idl_filename_to_component, is_valid_component_dependency,
format_remove_duplicates, format_blink_cpp_source_code,
to_snake_case)
to_snake_case, normalize_path)
import v8_utilities
# Path handling for libraries and templates
......@@ -124,6 +124,8 @@ def normalize_and_sort_includes(include_paths):
def render_template(template, context):
filename = str(template.filename)
filename = filename[filename.rfind('third_party'):]
filename = normalize_path(filename)
context['jinja_template_filename'] = filename
return template.render(context)
......@@ -180,6 +182,7 @@ class CodeGeneratorBase(object):
raise NotImplementedError()
def normalize_this_header_path(self, header_path):
header_path = normalize_path(header_path)
match = re.search('(third_party/blink/.*)$', header_path)
assert match, 'Unkown style of path to output: ' + header_path
return match.group(1)
......
......@@ -313,7 +313,9 @@ def write_file(new_text, destination_filename):
destination_dirname = os.path.dirname(destination_filename)
if not os.path.exists(destination_dirname):
os.makedirs(destination_dirname)
with open(destination_filename, 'w') as destination_file:
# Write file in binary so that when run on Windows, line endings are not
# converted
with open(destination_filename, 'wb') as destination_file:
destination_file.write(new_text)
......@@ -473,6 +475,10 @@ def to_header_guard(path):
return NameStyleConverter(path).to_header_guard()
def normalize_path(path):
return path.replace("\\", "/")
def format_remove_duplicates(text, patterns):
"""Removes duplicated line-basis patterns.
......
......@@ -23,6 +23,7 @@
#
from contextlib import contextmanager
import difflib
import filecmp
import fnmatch
import os
......@@ -210,16 +211,13 @@ def bindings_tests(output_directory, verbose, suppress_diff):
return files
def diff(filename1, filename2):
# Python's difflib module is too slow, especially on long output, so
# run external diff(1) command
cmd = ['diff',
'-u', # unified format
'-N', # treat absent files as empty
filename1,
filename2]
# Return output and don't raise exception, even though diff(1) has
# non-zero exit if files differ.
return executive.run_command(cmd, error_handler=lambda x: None)
with open(filename1) as file1:
file1_lines = file1.readlines()
with open(filename2) as file2:
file2_lines = file2.readlines()
# Use Python's difflib module so that diffing works across platforms
return ''.join(difflib.context_diff(file1_lines, file2_lines))
def is_cache_file(filename):
return filename.endswith('.cache')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment