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 ...@@ -19,7 +19,7 @@ from v8_methods import method_filters
from v8_utilities import capitalize from v8_utilities import capitalize
from utilities import (idl_filename_to_component, is_valid_component_dependency, from utilities import (idl_filename_to_component, is_valid_component_dependency,
format_remove_duplicates, format_blink_cpp_source_code, format_remove_duplicates, format_blink_cpp_source_code,
to_snake_case) to_snake_case, normalize_path)
import v8_utilities import v8_utilities
# Path handling for libraries and templates # Path handling for libraries and templates
...@@ -124,6 +124,8 @@ def normalize_and_sort_includes(include_paths): ...@@ -124,6 +124,8 @@ def normalize_and_sort_includes(include_paths):
def render_template(template, context): def render_template(template, context):
filename = str(template.filename) filename = str(template.filename)
filename = filename[filename.rfind('third_party'):] filename = filename[filename.rfind('third_party'):]
filename = normalize_path(filename)
context['jinja_template_filename'] = filename context['jinja_template_filename'] = filename
return template.render(context) return template.render(context)
...@@ -180,6 +182,7 @@ class CodeGeneratorBase(object): ...@@ -180,6 +182,7 @@ class CodeGeneratorBase(object):
raise NotImplementedError() raise NotImplementedError()
def normalize_this_header_path(self, header_path): def normalize_this_header_path(self, header_path):
header_path = normalize_path(header_path)
match = re.search('(third_party/blink/.*)$', header_path) match = re.search('(third_party/blink/.*)$', header_path)
assert match, 'Unkown style of path to output: ' + header_path assert match, 'Unkown style of path to output: ' + header_path
return match.group(1) return match.group(1)
......
...@@ -313,7 +313,9 @@ def write_file(new_text, destination_filename): ...@@ -313,7 +313,9 @@ def write_file(new_text, destination_filename):
destination_dirname = os.path.dirname(destination_filename) destination_dirname = os.path.dirname(destination_filename)
if not os.path.exists(destination_dirname): if not os.path.exists(destination_dirname):
os.makedirs(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) destination_file.write(new_text)
...@@ -473,6 +475,10 @@ def to_header_guard(path): ...@@ -473,6 +475,10 @@ def to_header_guard(path):
return NameStyleConverter(path).to_header_guard() return NameStyleConverter(path).to_header_guard()
def normalize_path(path):
return path.replace("\\", "/")
def format_remove_duplicates(text, patterns): def format_remove_duplicates(text, patterns):
"""Removes duplicated line-basis patterns. """Removes duplicated line-basis patterns.
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# #
from contextlib import contextmanager from contextlib import contextmanager
import difflib
import filecmp import filecmp
import fnmatch import fnmatch
import os import os
...@@ -210,16 +211,13 @@ def bindings_tests(output_directory, verbose, suppress_diff): ...@@ -210,16 +211,13 @@ def bindings_tests(output_directory, verbose, suppress_diff):
return files return files
def diff(filename1, filename2): def diff(filename1, filename2):
# Python's difflib module is too slow, especially on long output, so with open(filename1) as file1:
# run external diff(1) command file1_lines = file1.readlines()
cmd = ['diff', with open(filename2) as file2:
'-u', # unified format file2_lines = file2.readlines()
'-N', # treat absent files as empty
filename1, # Use Python's difflib module so that diffing works across platforms
filename2] return ''.join(difflib.context_diff(file1_lines, file2_lines))
# 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)
def is_cache_file(filename): def is_cache_file(filename):
return filename.endswith('.cache') 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