[GTK] [CMake] Add a "make dist" target
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jan 2014 22:34:15 +0000 (22:34 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jan 2014 22:34:15 +0000 (22:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=116378

Reviewed by Gustavo Noronha Silva.

.:

* Source/PlatformGTK.cmake: A CMake support for executing the make-dist
script and then turning the tarfile into a LZMA compressed file.

Source/WebCore:

* CMakeLists.txt: Don't build WebKitVersion.h for WebKitGTK+. We don't use it
and we don't want to distribute the dependency.

Tools:

Added a script that reads a manifest file an produces a tarball. Also add
the manifest.

* gtk/make-dist.py: Added.
* gtk/manifest.txt: Added.

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

ChangeLog
Source/PlatformGTK.cmake
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Tools/ChangeLog
Tools/gtk/make-dist.py [new file with mode: 0755]
Tools/gtk/manifest.txt [new file with mode: 0644]

index 9448b95..3e1c677 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-01-30  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] [CMake] Add a "make dist" target
+        https://bugs.webkit.org/show_bug.cgi?id=116378
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * Source/PlatformGTK.cmake: A CMake support for executing the make-dist
+        script and then turning the tarfile into a LZMA compressed file.
+
 2014-01-30  Zan Dobersek  <zdobersek@igalia.com>
 
         [GTK] Only disable -ftree-dce optimization when compiling with GCC
index cd0bd7d..96a27e1 100644 (file)
@@ -52,3 +52,29 @@ endif ()
 add_custom_target(check
     COMMAND "${TOOLS_DIR}/Scripts/run-gtk-tests"
 )
+
+if (ENABLE_WEBKIT AND ENABLE_WEBKIT2)
+    add_custom_command(
+        OUTPUT ${CMAKE_BINARY_DIR}/webkitgtk-${PROJECT_VERSION}.tar
+        DEPENDS ${TOOLS_DIR}/gtk/make-dist.py
+        DEPENDS ${TOOLS_DIR}/gtk/manifest.txt
+        DEPENDS WebKit
+        DEPENDS WebKit2
+        COMMAND ${TOOLS_DIR}/gtk/make-dist.py
+                --source-dir=${CMAKE_SOURCE_DIR}
+                --build-dir=${CMAKE_BINARY_DIR}
+                --tarball-root=/webkitgtk-${PROJECT_VERSION}
+                -o ${CMAKE_BINARY_DIR}/webkitgtk-${PROJECT_VERSION}.tar
+                ${TOOLS_DIR}/gtk/manifest.txt
+    )
+
+    add_custom_command(
+        OUTPUT ${CMAKE_BINARY_DIR}/webkitgtk-${PROJECT_VERSION}.tar.xz
+        DEPENDS ${CMAKE_BINARY_DIR}/webkitgtk-${PROJECT_VERSION}.tar
+        COMMAND xz -f ${CMAKE_BINARY_DIR}/webkitgtk-${PROJECT_VERSION}.tar
+    )
+
+    add_custom_target(dist
+        DEPENDS ${CMAKE_BINARY_DIR}/webkitgtk-${PROJECT_VERSION}.tar.xz
+    )
+endif ()
index bf661f6..f80005f 100644 (file)
@@ -3232,13 +3232,15 @@ list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/XMLNSNames.cpp)
 GENERATE_DOM_NAMES(XML ${WEBCORE_DIR}/xml/xmlattrs.in)
 list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/XMLNames.cpp)
 
-add_custom_command(
-    OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitVersion.h
-    MAIN_DEPENDENCY ${WEBKIT_DIR}/scripts/generate-webkitversion.pl
-    DEPENDS ${WEBKIT_DIR}/mac/Configurations/Version.xcconfig
-    COMMAND ${PERL_EXECUTABLE} ${WEBKIT_DIR}/scripts/generate-webkitversion.pl --config ${WEBKIT_DIR}/mac/Configurations/Version.xcconfig --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
-    VERBATIM)
-list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitVersion.h)
+if (NOT PORT STREQUAL "GTK")
+    add_custom_command(
+        OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitVersion.h
+        MAIN_DEPENDENCY ${WEBKIT_DIR}/scripts/generate-webkitversion.pl
+        DEPENDS ${WEBKIT_DIR}/mac/Configurations/Version.xcconfig
+        COMMAND ${PERL_EXECUTABLE} ${WEBKIT_DIR}/scripts/generate-webkitversion.pl --config ${WEBKIT_DIR}/mac/Configurations/Version.xcconfig --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
+        VERBATIM)
+    list(APPEND WebCore_SOURCES ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitVersion.h)
+endif ()
 
 WEBKIT_WRAP_SOURCELIST(${WebCore_IDL_FILES} ${WebCore_SOURCES})
 WEBKIT_WRAP_SOURCELIST(${WebCoreTestSupport_IDL_FILES} ${WebCoreTestSupport_SOURCES})
index 392117b..06a2b52 100644 (file)
@@ -1,3 +1,13 @@
+2014-01-30  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] [CMake] Add a "make dist" target
+        https://bugs.webkit.org/show_bug.cgi?id=116378
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * CMakeLists.txt: Don't build WebKitVersion.h for WebKitGTK+. We don't use it
+        and we don't want to distribute the dependency.
+
 2014-01-30  Brady Eidson  <beidson@apple.com>
 
         IDB: ObjectStore cursor advance() support
index 0fa080f..cb70c0c 100644 (file)
@@ -1,3 +1,16 @@
+2014-01-30  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] [CMake] Add a "make dist" target
+        https://bugs.webkit.org/show_bug.cgi?id=116378
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Added a script that reads a manifest file an produces a tarball. Also add
+        the manifest.
+
+        * gtk/make-dist.py: Added.
+        * gtk/manifest.txt: Added.
+
 2014-01-30  David Farler  <dfarler@apple.com>
 
         Move OTHER_LDFLAGS erasure to DumpRenderTreeLibrary.xcconfig.
diff --git a/Tools/gtk/make-dist.py b/Tools/gtk/make-dist.py
new file mode 100755 (executable)
index 0000000..fd0f1ce
--- /dev/null
@@ -0,0 +1,223 @@
+#!/usr/bin/env python
+# Copyright (C) 2014 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
+
+from __future__ import print_function
+from contextlib import closing
+
+import argparse
+import os
+import re
+import sys
+import tarfile
+
+
+def enum(**enums):
+    return type('Enum', (), enums)
+
+
+class Rule(object):
+    Result = enum(INCLUDE=1, EXCLUDE=2, NO_MATCH=3)
+
+    def __init__(self, type, pattern):
+        self.type = type
+        self.original_pattern = pattern
+        self.pattern = re.compile(pattern)
+
+    def test(self, file):
+        if not(self.pattern.search(file)):
+            return Rule.Result.NO_MATCH
+        return self.type
+
+
+class Ruleset(object):
+    _global_rules = None
+
+    def __init__(self):
+        # By default, accept all files.
+        self.rules = [Rule(Rule.Result.INCLUDE, '.*')]
+
+    @classmethod
+    def global_rules(cls):
+        if not cls._global_rules:
+            cls._global_rules = Ruleset()
+        return cls._global_rules
+
+    @classmethod
+    def add_global_rule(cls, rule):
+        cls.global_rules().add_rule(rule)
+
+    def add_rule(self, rule):
+        self.rules.append(rule)
+
+    def passes(self, file):
+        allowed = False
+        for rule in self.rules:
+            result = rule.test(file)
+            if result == Rule.Result.NO_MATCH:
+                continue
+            allowed = Rule.Result.INCLUDE == result
+        return allowed
+
+
+class File(object):
+    def __init__(self, source_root, tarball_root):
+        self.source_root = source_root
+        self.tarball_root = tarball_root
+
+    def get_files(self):
+        yield (self.source_root, self.tarball_root)
+
+
+class Directory(object):
+    def __init__(self, source_root, tarball_root):
+        self.source_root = source_root
+        self.tarball_root = tarball_root
+        self.rules = Ruleset()
+
+    def add_rule(self, rule):
+        self.rules.add_rule(rule)
+
+    def get_tarball_path(self, filename):
+        return filename.replace(self.source_root, self.tarball_root, 1)
+
+    def get_files(self):
+        for root, dirs, files in os.walk(self.source_root):
+
+            def passes_all_rules(entry):
+                return Ruleset.global_rules().passes(entry) and self.rules.passes(entry)
+
+            to_keep = filter(passes_all_rules, dirs)
+            del dirs[:]
+            dirs.extend(to_keep)
+
+            for file in files:
+                file = os.path.join(root, file)
+                if not passes_all_rules(file):
+                    continue
+                yield (file, self.get_tarball_path(file))
+
+
+class Manifest(object):
+    def __init__(self, manifest_filename, source_root, build_root, tarball_root='/'):
+        self.current_directory = None
+        self.directories = []
+        self.tarball_root = tarball_root
+        self.source_root = os.path.abspath(source_root)
+        self.build_root = os.path.abspath(build_root)
+
+        # Normalize the tarball root so that it starts and ends with a slash.
+        if self.tarball_root.endswith('/'):
+            self.tarball_root = self.tarball_root + '/'
+        if self.tarball_root.startswith('/'):
+            self.tarball_root = '/' + self.tarball_root
+
+        with open(manifest_filename, 'r') as file:
+            for line in file.readlines():
+                self.process_line(line)
+
+    def add_rule(self, rule):
+        if self.current_directory is not None:
+            self.current_directory.add_rule(rule)
+        else:
+            Ruleset.add_global_rule(rule)
+
+    def add_directory(self, directory):
+        self.current_directory = directory
+        self.directories.append(directory)
+
+    def resolve_variables(self, string, strip=False):
+        if strip:
+            return string.replace('$source', '').replace('$build', '')
+
+        string = string.replace('$source', self.source_root)
+        if self.build_root:
+            string = string.replace('$build', self.build_root)
+        elif string.find('$build') != -1:
+            raise Exception('Manifest has $build but build root not given.')
+        return string
+
+    def get_full_source_path(self, source_path):
+        full_source_path = self.resolve_variables(source_path)
+        if not os.path.exists(full_source_path):
+            full_source_path = os.path.join(self.source_root, source_path)
+        if not os.path.exists(full_source_path):
+            raise Exception('Could not find directory %s' % full_source_path)
+        return full_source_path
+
+    def get_full_tarball_path(self, path):
+        path = self.resolve_variables(path, strip=True)
+        return self.tarball_root + path
+
+    def get_source_and_tarball_paths_from_parts(self, parts):
+        full_source_path = self.get_full_source_path(parts[1])
+        if len(parts) > 2:
+            full_tarball_path = self.get_full_tarball_path(parts[2])
+        else:
+            full_tarball_path = self.get_full_tarball_path(parts[1])
+        return (full_source_path, full_tarball_path)
+
+    def process_line(self, line):
+        parts = line.split()
+        if not parts:
+            return
+        if parts[0].startswith("#"):
+            return
+
+        if parts[0] == "directory" and len(parts) > 1:
+            self.add_directory(Directory(*self.get_source_and_tarball_paths_from_parts(parts)))
+        elif parts[0] == "file" and len(parts) > 1:
+            self.add_directory(File(*self.get_source_and_tarball_paths_from_parts(parts)))
+        elif parts[0] == "exclude" and len(parts) > 1:
+            self.add_rule(Rule(Rule.Result.EXCLUDE, self.resolve_variables(parts[1])))
+        elif parts[0] == "include" and len(parts) > 1:
+            self.add_rule(Rule(Rule.Result.INCLUDE, self.resolve_variables(parts[1])))
+
+    def get_files(self):
+        for directory in self.directories:
+            for file_tuple in directory.get_files():
+                yield file_tuple
+
+    def create_tarfile(self, output):
+        count = 0
+        for file_tuple in self.get_files():
+            count = count + 1
+
+        with closing(tarfile.open(output, 'w')) as tarball:
+            for i, (file_path, tarball_path) in enumerate(self.get_files(), start=1):
+                print('Tarring file {0} of {1}'.format(i, count).ljust(40), end='\r')
+                tarball.add(file_path, tarball_path)
+        print("Wrote {0}".format(output).ljust(40))
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description='Build a distribution bundle.')
+    parser.add_argument('-s', '--source-directory', type=str, default=os.getcwd(),
+                        help='The top-level directory of the source distribution. ' + \
+                              'Directory for relative paths. Defaults to current directory.')
+    parser.add_argument('--tarball-root', type=str, default='/',
+                        help='The top-level path of the tarball. By default files are added to the root of the tarball.')
+    parser.add_argument('-b', '--build-directory', type=str, default=None,
+                        help='The top-level path of directory of the build root. ' + \
+                              'By default there is no build root.')
+    parser.add_argument('-o', type=str, default='out.tar', dest="output_filename",
+                        help='The tarfile to produce. By default this is "out.tar"')
+    parser.add_argument('manifest_filename', metavar="manifest", type=str, help='The path to the manifest file.')
+
+    arguments = parser.parse_args()
+
+    manifest = Manifest(arguments.manifest_filename, arguments.source_directory, arguments.build_directory, arguments.tarball_root)
+    manifest.create_tarfile(arguments.output_filename)
diff --git a/Tools/gtk/manifest.txt b/Tools/gtk/manifest.txt
new file mode 100644 (file)
index 0000000..8c61df3
--- /dev/null
@@ -0,0 +1,74 @@
+# Global rules
+exclude #$
+exclude ChangeLog
+exclude GNUmakefile
+exclude Makefile
+exclude tags$
+exclude ~$
+exclude \.#$
+exclude \.bak$
+exclude \.cproject$
+exclude \.git$
+exclude \.gitattributes$
+exclude \.gitignore$
+exclude \.gyp$
+exclude \.icns$
+exclude \.lproj$
+exclude \.nib$
+exclude \.o$
+exclude \.order$
+exclude \.pdf$
+exclude \.plist$
+exlucde \.pro\.user$
+exclude \.project$
+exclude \.props$
+exclude \.pyc$
+exclude \.pyo$
+exclude \.settings$
+exclude \.svn$
+exclude \.sw[a-p]$
+exclude \.vcxproj$
+exclude \.xcconfig$
+exclude \.xcodeproj$
+
+directory Source
+exclude Source/WebCore/platform/audio/resources/IRC_Composite_.*\.wav$
+exclude Source/WebCore/bindings/scripts/test
+exclude Source/WebCore/platform/efl/DefaultTheme
+exclude Source/autotools$
+
+# Most of the files in Source/WebKit are not necessary to build GTK+ and
+# the directory includes lots of images, so we're a bit more picky here.
+exclude Source/WebKit/.*
+include Source/WebKit/CMakeLists.txt
+include Source/WebKit/PlatformGTK.cmake
+include Source/WebKit/gtk
+exclude Source/WebKit/gtk/NEWS$
+
+# We do want to include the NEWS, but we want it to be in the root of the archive.
+file Source/WebKit/gtk/NEWS NEWS
+
+directory Tools/gtk
+directory Tools/GtkLauncher
+directory Tools/ImageDiff
+directory Tools/MiniBrowser
+directory Tools/TestWebKitAPI
+
+directory Tools/DumpRenderTree
+exclude Tools/DumpRenderTree/fonts
+
+directory Tools/WebKitTestRunner
+exclude Tools/WebKitTestRunner/fonts/
+
+file CMakeLists.txt
+file Tools/CMakeLists.txt
+file Tools/Scripts/VCSUtils.pm
+file Tools/Scripts/run-gtk-tests
+file Tools/Scripts/webkit-build-directory
+file Tools/Scripts/webkitdirs.pm
+file Tools/jhbuild/jhbuildutils.py
+
+directory $build/Documentation/webkit2gtk/html Documentation/webkit2gtk/html
+directory $build/Documentation/webkit2gtk/html Documentation/webkit2gtk/html
+directory $build/Documentation/webkitgtk/tmpl Documentation/webkitgtk/tmpl
+directory $build/Documentation/webkitgtk/tmpl Documentation/webkitgtk/tmpl