summaryrefslogtreecommitdiff
path: root/Tools/gtk/check-for-webkitdom-api-breaks
blob: 2f4237b5111acdc590ce2fca15a2e9aab42813cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# Copyright (C) 2013, 2014 Igalia S.L.
# Copyright (C) 2013 Gustavo Noronha Silva <gns@gnome.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import argparse
import common
import os
import sys
import webkitdom

EXPECTED_API_PATH = common.top_level_path('Source', 'WebCore', 'bindings', 'gobject', 'webkitdom.symbols')

def read_built_api():
    apis = set()
    for file_path in webkitdom.get_all_webkitdom_symbol_files():
        with open(file_path) as file_handle:
            apis.update(set(file_handle.readlines()))
    return apis

def read_expected_api():
    with open(EXPECTED_API_PATH) as file_handle:
        return set(file_handle.readlines())

def write_expected_api(new_expected_api):
    with open(EXPECTED_API_PATH, 'w') as file_handle:
        file_handle.writelines(new_expected_api)

def check_api(options, expected_api, built_api):
    missing_api = expected_api.difference(built_api)
    new_api = built_api.difference(expected_api)

    if missing_api:
        sys.stderr.write("Missing API (API break!) detected in GObject DOM bindings\n")
        sys.stderr.write("    %s\n" % "    ".join(missing_api))
        sys.stderr.flush()

    if new_api:
        sys.stdout.write("New API detected in GObject DOM bindings\n")
        sys.stdout.write("    %s\n" % "    ".join(new_api))

    if missing_api:
        # This test can give false positives because the GObject
        # DOM bindings API varies depending on the compilation options.
        # So this shouldn't be made fatal until we figure out a way to handle it.
        # See https://bugs.webkit.org/show_bug.cgi?id=121481
        sys.stderr.write("Re-add the missing API and rerun the %s.\n" % __file__)
        return 0

    if new_api:
        if options.reset_results:
            sys.stdout.write("Resetting expected API\n")
            write_expected_api(built_api)
        else:
            sys.stdout.write("API compatible changes found in GObject DOM bindings.\n")
            sys.stdout.write("To update the symbols file, run %s --reset-results.\n" % __file__)

    return 0

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Detect API breakage in the WebKitGTK+ GObject DOM bindings.')
    parser.add_argument('--reset-results', action='store_true',
                        help='When specified, rest the expected results file with the built results.')
    options = parser.parse_args()
    sys.exit(check_api(options, read_expected_api(), read_built_api()))