Commit e1b1fb56 authored by bashi's avatar bashi Committed by Commit bot

Move bindings tooling scripts to Tools/Scripts/webkitpy/bindings

These scripts are not a part of code generator so it would be
better to put them in Tools/Scripts/webkitpy/bindings.

BUG=617899

Review-Url: https://codereview.chromium.org/2169673003
Cr-Commit-Position: refs/heads/master@{#406957}
parent 70b502ae
......@@ -10,11 +10,19 @@ This script collects and organizes interface information and that information du
import json
import os
import sys
import utilities
_bindings_path = os.path.normpath(
os.path.join(os.path.dirname(__file__),
os.pardir, os.pardir, os.pardir, os.pardir,
'Source', 'bindings', 'scripts'))
if _bindings_path not in sys.path:
sys.path.append(_bindings_path)
import utilities
from blink_idl_parser import parse_file, BlinkIDLParser
_INTERFACE = 'Interface'
_IMPLEMENT = 'Implements'
_PARTIAL = 'Partial'
......
#!/usr/bin/env python
import os
import unittest
import collect_idls_into_json
from webkitpy.bindings import collect_idls_into_json
import utilities
from blink_idl_parser import parse_file, BlinkIDLParser
_FILE = 'Source/bindings/scripts/testdata/test_filepath.txt'
testdata_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'testdata')
_FILE = os.path.join(testdata_path, 'test_filepath.txt')
_KEY_SET = set(['Operations', 'Name', 'FilePath', 'Inherit', 'Consts', 'ExtAttributes', 'Attributes'])
_PARTIAL = {'Node': {'Operations': [], 'Name': 'Node', 'FilePath': 'Source/core/timing/WorkerGlobalScopePerformance.idl', 'Inherit': [], 'Consts': [], 'ExtAttributes': [], 'Attributes': [{'Static': False, 'Readonly': True, 'Type': 'WorkerPerformance', 'Name': 'performance', 'ExtAttributes': []}]}}
......@@ -14,21 +18,18 @@ _PARTIAL = {'Node': {'Operations': [], 'Name': 'Node', 'FilePath': 'Source/core/
class TestFunctions(unittest.TestCase):
def setUp(self):
parser = BlinkIDLParser()
path = utilities.read_file_to_list(_FILE)[0]
path = os.path.join(
testdata_path, utilities.read_file_to_list(_FILE)[0])
definitions = parse_file(parser, path)
self.definition = definitions.GetChildren()[0]
def test_get_definitions(self):
pathfile = utilities.read_file_to_list(_FILE)
pathfile = [os.path.join(testdata_path, filename)
for filename in pathfile]
for actual in collect_idls_into_json.get_definitions(pathfile):
self.assertEqual(actual.GetName(), self.definition.GetName())
def test_is_non_partial(self):
if self.definition.GetClass() == 'Interface' and not self.definition.GetProperty('Partial'):
self.assertTrue(collect_idls_into_json.is_non_partial(self.definition))
else:
self.assertFalse(collect_idls_into_json.is_non_partial(self.definition))
def test_is_partial(self):
if self.definition.GetClass() == 'Interface' and self.definition.GetProperty('Partial'):
self.assertTrue(collect_idls_into_json.is_partial(self.definition))
......@@ -37,7 +38,6 @@ class TestFunctions(unittest.TestCase):
def test_get_filepaths(self):
filepath = collect_idls_into_json.get_filepath(self.definition)
self.assertTrue(filepath.startswith('Source'))
self.assertTrue(filepath.endswith('.idl'))
def test_const_node_to_dict(self):
......@@ -105,7 +105,9 @@ class TestFunctions(unittest.TestCase):
def test_merge_partial_dicts(self):
key_name = self.definition.GetName()
self.assertEqual(collect_idls_into_json.merge_partial_dicts({key_name: collect_idls_into_json.interface_node_to_dict(self.definition)}, _PARTIAL)[key_name]['Partial_FilePaths'], ['Source/core/timing/WorkerGlobalScopePerformance.idl'])
merged = collect_idls_into_json.merge_partial_dicts({key_name: collect_idls_into_json.interface_node_to_dict(self.definition)}, _PARTIAL)[key_name]['Partial_FilePaths']
expected = ['Source/core/timing/WorkerGlobalScopePerformance.idl', 'Source/core/timing/WorkerGlobalScopePerformance.idl', 'Source/core/timing/WorkerGlobalScopePerformance.idl']
self.assertEqual(merged, expected)
if __name__ == '__main__':
......
......@@ -12,10 +12,9 @@ Usage: generate_idl_diff.py old_file.json new_file.json diff_file.json
"""
import json
import os
import sys
# pylint: disable=W0105
"""Data structure of input files of this script.
The format of the json files is as follows. Each json file contains multiple
"interface"s. Each "interface" contains 'ExtAttributes', 'Consts', 'Attributes'
......
......@@ -3,27 +3,26 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import generate_idl_diff
import os
import sys
import unittest
from generate_idl_diff import DIFF_TAG
from generate_idl_diff import DIFF_TAG_DELETED
from generate_idl_diff import DIFF_TAG_ADDED
from webkitpy.bindings import generate_idl_diff
from webkitpy.bindings.generate_idl_diff import DIFF_TAG
from webkitpy.bindings.generate_idl_diff import DIFF_TAG_DELETED
from webkitpy.bindings.generate_idl_diff import DIFF_TAG_ADDED
testdata_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'testdata')
old_data_path = os.path.join(testdata_path, 'old_chrome.json')
new_data_path = os.path.join(testdata_path, 'new_chrome.json')
old_data_path = os.path.join(testdata_path, 'old_blink_idls.json')
new_data_path = os.path.join(testdata_path, 'new_blink_idls.json')
class TestGenerateIDLDiff(unittest.TestCase):
def setUp(self):
old = generate_idl_diff.load_json_file('old_chrome.json')
new = generate_idl_diff.load_json_file('new_chrome.json')
old = generate_idl_diff.load_json_file(old_data_path)
new = generate_idl_diff.load_json_file(new_data_path)
self.diff = generate_idl_diff.interfaces_diff(old, new)
def test_deleted_interface(self):
......
......@@ -16,16 +16,16 @@ Usage: print_idl_diff.py diff_file.json order
"""
from collections import OrderedDict
import json
import sys
from generate_idl_diff import load_json_file
from generate_idl_diff import EXTATTRIBUTES_AND_MEMBER_TYPES
from generate_idl_diff import DIFF_TAG
from generate_idl_diff import DIFF_TAG_ADDED
from generate_idl_diff import DIFF_TAG_DELETED
from webkitpy.bindings.generate_idl_diff import load_json_file
from webkitpy.bindings.generate_idl_diff import EXTATTRIBUTES_AND_MEMBER_TYPES
from webkitpy.bindings.generate_idl_diff import DIFF_TAG
from webkitpy.bindings.generate_idl_diff import DIFF_TAG_ADDED
from webkitpy.bindings.generate_idl_diff import DIFF_TAG_DELETED
# pylint: disable=W0105
"""Refer to the explanation of generate_idl_diff.py's input files.
The deffference between the input structure of generate_idl_diff.py and
that of print_diff.py is whether diffing tags are included or not.
......@@ -190,8 +190,11 @@ def sort_interface_names_by_tags(interfaces):
"""
interface_list = interfaces.values()
removed, added, unspecified = group_by_tag(interface_list)
# pylint: disable=W0110
removed = map(lambda interface: interface['Name'], removed)
# pylint: disable=W0110
added = map(lambda interface: interface['Name'], added)
# pylint: disable=W0110
unspecified = map(lambda interface: interface['Name'], unspecified)
sorted_interface_names = removed + added + unspecified
return sorted_interface_names
......
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