[GTK] Simplify the GObject DOM bindings API break check into one step
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Mar 2014 18:43:54 +0000 (18:43 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Mar 2014 18:43:54 +0000 (18:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129571

Reviewed by Carlos Garcia Campos.

.:

* Source/PlatformGTK.cmake: We don't need to run the API break check before gtkdoc generation.
Add the check to 'make check.'

Source/WebCore:

* bindings/gobject/GNUmakefile.am: We no longer generate the webkitdom.symbols file in the
DerivedSources directory. All the logic is handled internally in the script now.
* bindings/scripts/gobject-run-api-break-test: Removed.

Tools:

* GNUmakefile.am: Add the API break check to 'make check.'
* gtk/check-for-webkitdom-api-breaks: Added. A combination of the two removed scripts.
* gtk/check-gdom-symbols: Removed.
* gtk/webkitdom.py: Added.
(header_name_list_from_gtkdoc_config_file): Gets the names of all headers from the gtkdoc config file.
(get_all_webkitdom_symbol_files): Find the symbol files from the names.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@165060 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
ChangeLog
Source/PlatformGTK.cmake
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.am
Source/WebCore/PlatformGTK.cmake
Source/WebCore/bindings/gobject/GNUmakefile.am
Source/WebCore/bindings/scripts/gobject-run-api-break-test [deleted file]
Tools/ChangeLog
Tools/GNUmakefile.am
Tools/gtk/GNUmakefile.am
Tools/gtk/check-for-webkitdom-api-breaks [new file with mode: 0755]
Tools/gtk/check-gdom-symbols [deleted file]
Tools/gtk/webkitdom.py [new file with mode: 0755]

index d7dbb63..1ad7a93 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2014-03-04  Martin Robinson  <mrobinson@igalia.com>
 
+        [GTK] Simplify the GObject DOM bindings API break check into one step
+        https://bugs.webkit.org/show_bug.cgi?id=129571
+
+        Reviewed by Carlos Garcia Campos.
+
+        * Source/PlatformGTK.cmake: We don't need to run the API break check before gtkdoc generation.
+        Add the check to 'make check.'
+
+2014-03-04  Martin Robinson  <mrobinson@igalia.com>
+
         [GTK][CMake] ENABLE_NAVIGATOR_CONTENT_UTILS is mistakenly enabled for the CMake build
         https://bugs.webkit.org/show_bug.cgi?id=129502
 
index a51b08f..64cf50f 100644 (file)
@@ -4,7 +4,6 @@ add_subdirectory(${WEBCORE_DIR}/platform/gtk/po)
 add_custom_target(gir ALL DEPENDS ${GObjectIntrospectionTargets})
 
 set(DocumentationDependencies
-    generate-gdom-symbols-file
     "${CMAKE_SOURCE_DIR}/Source/WebKit/gtk/docs/webkitenvironment.xml"
 )
 
@@ -51,7 +50,8 @@ if (ENABLE_WEBKIT2)
 endif ()
 
 add_custom_target(check
-    COMMAND "${TOOLS_DIR}/Scripts/run-gtk-tests"
+    COMMAND ${TOOLS_DIR}/Scripts/run-gtk-tests
+    COMMAND ${TOOLS_DIR}/gtk/check-for-webkitdom-api-breaks
 )
 
 if (ENABLE_WEBKIT AND ENABLE_WEBKIT2)
index ce3763f..326f99a 100644 (file)
@@ -1,3 +1,14 @@
+2014-03-04  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] Simplify the GObject DOM bindings API break check into one step
+        https://bugs.webkit.org/show_bug.cgi?id=129571
+
+        Reviewed by Carlos Garcia Campos.
+
+        * bindings/gobject/GNUmakefile.am: We no longer generate the webkitdom.symbols file in the
+        DerivedSources directory. All the logic is handled internally in the script now.
+        * bindings/scripts/gobject-run-api-break-test: Removed.
+
 2014-03-04  Zalan Bujtas  <zalan@apple.com>
 
         Build fix for iOS.
index a978c6c..51d172c 100644 (file)
@@ -663,7 +663,6 @@ EXTRA_DIST += \
        Source/WebCore/bindings/scripts/StaticString.pm \
        Source/WebCore/bindings/scripts/generate-bindings.pl \
        Source/WebCore/bindings/scripts/gobject-generate-headers.pl \
-       Source/WebCore/bindings/scripts/gobject-run-api-break-test \
        Source/WebCore/bindings/scripts/preprocessor.pm \
        Source/WebCore/bindings/scripts/preprocess-idls.pl \
        Source/WebCore/ChangeLog \
index 7ba9b43..39d1aa0 100644 (file)
@@ -732,16 +732,5 @@ if (ENABLE_WEBKIT2)
                   bindings/gobject/WebKitDOMObject.h
             DESTINATION "${WEBKITGTK_HEADER_INSTALL_DIR}/webkitdom"
     )
-
-    add_custom_command(
-        OUTPUT ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdom.symbols
-        DEPENDS ${GObjectDOMBindingsSymbolsFiles} ${CMAKE_SOURCE_DIR}/Tools/gtk/check-gdom-symbols
-        COMMAND ln -n -s -f ${WEBCORE_DIR}/bindings/gobject/WebKitDOM*.symbols ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}
-        COMMAND ${CMAKE_SOURCE_DIR}/Tools/gtk/check-gdom-symbols
-    )
-
-    add_custom_target(generate-gdom-symbols-file
-        DEPENDS GObjectDOMBindings ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdom.symbols
-    )
 endif ()
 
index a17416a..c84fe17 100644 (file)
@@ -480,7 +480,6 @@ DerivedSources/webkitdom/webkitdom.h: $(WebCore)/bindings/scripts/gobject-genera
 DerivedSources/webkitdom/webkitdomdefines.h: $(WebCore)/bindings/scripts/gobject-generate-headers.pl $(WebCore)/bindings/gobject/GNUmakefile.am
        $(AM_V_GEN)echo $(gdom_class_list) | $(PERL) $< defines > $@
 
-noinst_DATA += DerivedSources/webkitdom/webkitdom.symbols
 gdom_symbol_files += $(patsubst %.h,%.symbols, $(filter DerivedSources/webkitdom/WebKitDOM%.h, $(webkitgtk_gdom_built_h_api)))
 
 $(top_builddir)/DerivedSources/webkitdom/WebKitDOMObject.symbols: $(WebCore)/bindings/gobject/WebKitDOMObject.symbols
@@ -498,9 +497,6 @@ $(top_builddir)/DerivedSources/webkitdom/WebKitDOMDeprecated.symbols: $(WebCore)
 DerivedSources/webkitdom/WebKitDOM%.symbols: DerivedSources/webkitdom/WebKitDOM%.h
        @true
 
-DerivedSources/webkitdom/webkitdom.symbols: $(gdom_symbol_files) $(WebCore)/bindings/gobject/webkitdom.symbols $(WebCore)/bindings/scripts/gobject-run-api-break-test $(srcdir)/Tools/gtk/check-gdom-symbols
-       $(AM_V_GEN)$(srcdir)/Tools/gtk/check-gdom-symbols
-
 EXTRA_DIST += \
        $(WebCore)/bindings/gobject/WebKitDOMCustom.symbols \
        $(WebCore)/bindings/gobject/WebKitDOMDeprecated.symbols \
diff --git a/Source/WebCore/bindings/scripts/gobject-run-api-break-test b/Source/WebCore/bindings/scripts/gobject-run-api-break-test
deleted file mode 100755 (executable)
index 3208e63..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env python
-# Copyright (C) 2013 Igalia S.L.
-#
-# 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 difflib
-import optparse
-import shutil
-import sys
-
-def check_api(options, from_file, to_file):
-    from_lines = open(from_file, 'r').readlines()
-    from_lines.sort()
-    to_lines = open(to_file, 'r').readlines()
-    to_lines.sort()
-
-    diff = difflib.unified_diff(from_lines, to_lines)
-
-    diff_out = ""
-    failed = False
-    for line in diff:
-        # Ignore initial lines since we don't use from/file filenames.
-        if line.startswith('+++') or line.startswith('---'):
-            continue
-
-        diff_out += line
-        if line[0] == '-':
-            failed = True
-
-    if diff_out:
-        if failed:
-            sys.stderr.write("API incompatibility detected in GObject DOM bindings\n")
-            sys.stderr.write(diff_out)
-            # 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
-            return 0
-
-        if options.reset_results:
-            sys.stdout.write("Reset results: %s\n" % from_file)
-            shutil.copyfile(to_file, from_file)
-        else:
-            sys.stdout.write("API compatible changes found in GObject DOM bindings\n")
-            sys.stdout.write("To update the symbols file, execute %s --reset-results %s DerivedSources/webkitdom/webkitdom.symbols\n" % (sys.argv[0], from_file))
-            sys.stdout.write(diff_out)
-
-    return 0
-
-
-option_parser = optparse.OptionParser(usage='usage: %prog [options] FROM_FILE TO_FILE')
-option_parser.add_option('--reset-results', action='store_true', dest='reset_results')
-options, args = option_parser.parse_args()
-sys.exit(check_api(options, args[0], args[1]))
-
index b57b846..75be975 100644 (file)
@@ -1,3 +1,17 @@
+2014-03-04  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] Simplify the GObject DOM bindings API break check into one step
+        https://bugs.webkit.org/show_bug.cgi?id=129571
+
+        Reviewed by Carlos Garcia Campos.
+
+        * GNUmakefile.am: Add the API break check to 'make check.'
+        * gtk/check-for-webkitdom-api-breaks: Added. A combination of the two removed scripts.
+        * gtk/check-gdom-symbols: Removed.
+        * gtk/webkitdom.py: Added.
+        (header_name_list_from_gtkdoc_config_file): Gets the names of all headers from the gtkdoc config file.
+        (get_all_webkitdom_symbol_files): Find the symbol files from the names.
+
 2014-03-03  Simon Fraser  <simon.fraser@apple.com>
 
         Add Jeremy Jones to the contributors list as a contributor.
index 1470f6b..115e09b 100644 (file)
@@ -267,6 +267,7 @@ endif
 
 check-local:
        $(top_srcdir)/Tools/Scripts/run-gtk-tests --timeout=-1
+       $(top_srcdir)/Tools/gtk/check-for-webkitdom-api-breaks
 
 EXTRA_DIST += \
        Tools/jhbuild/jhbuildutils.py \
index f250929..dd3978c 100644 (file)
@@ -1,4 +1,5 @@
 EXTRA_DIST += \
+       Tools/gtk/check-for-webkitdom-api-breaks \
        Tools/gtk/common.py \
        Tools/gtk/generate-feature-defines-files \
        Tools/gtk/generate-gtkdoc \
diff --git a/Tools/gtk/check-for-webkitdom-api-breaks b/Tools/gtk/check-for-webkitdom-api-breaks
new file mode 100755 (executable)
index 0000000..2f4237b
--- /dev/null
@@ -0,0 +1,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()))
diff --git a/Tools/gtk/check-gdom-symbols b/Tools/gtk/check-gdom-symbols
deleted file mode 100755 (executable)
index bf35c21..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-# 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 common
-import glob
-import os
-import subprocess
-import sys
-import tempfile
-
-def should_update_symbols_file(new, old):
-    if not os.path.exists(old):
-        return False
-
-    new = open(new).read()
-    old = open(old).read()
-
-    if len(new) != len(old):
-        return False
-
-    for i, byte in enumerate(new):
-        if byte != old[i]:
-            return False
-
-    return True
-
-if __name__ == '__main__':
-    with tempfile.NamedTemporaryFile() as tmp:
-        for file_path in glob.glob(os.path.join(common.build_path('DerivedSources'), 'webkitdom', '*.h')):
-            if not os.path.basename(file_path).startswith('WebKit') or file_path.endswith('Private.h'):
-                continue
-
-            file_path = file_path.replace('.h', '.symbols')
-            with open(file_path) as file_handle:
-                tmp.write(file_handle.read())
-        tmp.flush()
-
-        gdom_source_path = common.top_level_path('Source', 'WebCore', 'bindings')
-        api_break_test_path = os.path.join(gdom_source_path, 'scripts', 'gobject-run-api-break-test')
-        subprocess.call([sys.executable, api_break_test_path, os.path.join(gdom_source_path, 'gobject',  'webkitdom.symbols'), tmp.name])
-
-        generated_gdom_symbols_path = os.path.join(common.build_path('DerivedSources'), 'webkitdom', 'webkitdom.symbols')
-        if not should_update_symbols_file(tmp.name, generated_gdom_symbols_path):
-            source = open(tmp.name, 'r')
-            destination = open(generated_gdom_symbols_path, 'w')
-            destination.write(source.read())
-            destination.close()
-            source.close()
diff --git a/Tools/gtk/webkitdom.py b/Tools/gtk/webkitdom.py
new file mode 100755 (executable)
index 0000000..441942e
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# Copyright (C) 2013 Igalia S.L.
+#
+# 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 common
+import os
+import sys
+
+from ConfigParser import SafeConfigParser
+
+
+def header_name_list_from_gtkdoc_config_file():
+    config_file = common.build_path('gtkdoc-webkitdom.cfg')
+    if not os.path.isfile(config_file):
+        sys.stderr.write("Could not find config file at %s\n" % config_file)
+        return sys.exit(1)
+
+    config = SafeConfigParser()
+    config.read(config_file)
+    module_name = config.sections()[0]
+    return [os.path.basename(f) for f in str(config.get(module_name, 'headers')).replace(';', ' ').split()]
+
+
+def get_all_webkitdom_symbol_files():
+    static_symbol_files_path = common.top_level_path('Source', 'WebCore', 'bindings', 'gobject')
+    generated_symbol_files_path = common.build_path('DerivedSources', 'webkitdom')
+
+    symbol_files = []
+    for header_name in header_name_list_from_gtkdoc_config_file():
+        # webkitdomdefines.h doesn't have a corresponding symbols file and webkitdom.symbols is a
+        # file containing the expected symbols results.
+        if header_name in ("webkitdom.h", "webkitdomdefines.h"):
+            continue
+
+        symbol_file = header_name.replace(".h", ".symbols")
+        path = os.path.join(static_symbol_files_path, symbol_file)
+        if os.path.exists(path):
+            symbol_files.append(path)
+            continue
+        path = os.path.join(generated_symbol_files_path, symbol_file)
+        if os.path.exists(path):
+            symbol_files.append(path)
+            continue
+        sys.stderr.write("Could not find symbol file for header: %s\n" % header_name)
+        sys.exit(1)
+
+    return symbol_files