1# Copyright (C) 2010 Apple Inc. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions
5# are met:
6# 1.  Redistributions of source code must retain the above copyright
7#     notice, this list of conditions and the following disclaimer.
8# 2.  Redistributions in binary form must reproduce the above copyright
9#     notice, this list of conditions and the following disclaimer in the
10#     documentation and/or other materials provided with the distribution.
11#
12# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23"""Functions relating to building WebKit"""
24
25import re
26
27
28def _should_file_trigger_build(target_platform, file):
29    # The directories and patterns lists below map directory names or
30    # regexp patterns to the bot platforms for which they should trigger a
31    # build. Mapping to the empty list means that no builds should be
32    # triggered on any platforms. Earlier directories/patterns take
33    # precendence over later ones.
34
35    # FIXME: The patterns below have only been verified to be correct on
36    # the platforms listed below. We should implement this for other platforms
37    # and start using it for their bots. Someone familiar with each platform
38    # will have to figure out what the right set of directories/patterns is for
39    # that platform.
40    assert(target_platform in ("mac-leopard", "mac-snowleopard", "win"))
41
42    directories = [
43        # Directories that shouldn't trigger builds on any bots.
44        ("Examples", []),
45        ("PerformanceTests", []),
46        ("Source/WebCore/manual-tests", []),
47        ("Tools/BuildSlaveSupport/build.webkit.org-config/public_html", []),
48        ("Websites", []),
49        ("android", []),
50        ("brew", []),
51        ("efl", []),
52        ("haiku", []),
53        ("iphone", []),
54        ("opengl", []),
55        ("opentype", []),
56        ("openvg", []),
57        ("wince", []),
58        ("wx", []),
59
60        # Directories that should trigger builds on only some bots.
61        ("Source/JavaScriptGlue", ["mac"]),
62        ("Source/WebCore/image-decoders", ["chromium"]),
63        ("LayoutTests/platform/mac", ["mac", "win"]),
64        ("cairo", ["gtk", "wincairo"]),
65        ("cf", ["chromium-mac", "mac", "qt", "win"]),
66        ("chromium", ["chromium"]),
67        ("cocoa", ["chromium-mac", "mac"]),
68        ("curl", ["gtk", "wincairo"]),
69        ("gobject", ["gtk"]),
70        ("gpu", ["chromium", "mac"]),
71        ("gstreamer", ["gtk"]),
72        ("gtk", ["gtk"]),
73        ("mac", ["chromium-mac", "mac"]),
74        ("mac-leopard", ["mac-leopard"]),
75        ("mac-snowleopard", ["mac", "win"]),
76        ("mac-wk2", ["mac-snowleopard", "win"]),
77        ("objc", ["mac"]),
78        ("qt", ["qt"]),
79        ("skia", ["chromium"]),
80        ("soup", ["gtk"]),
81        ("v8", ["chromium"]),
82        ("win", ["chromium-win", "win"]),
83    ]
84    patterns = [
85        # Patterns that shouldn't trigger builds on any bots.
86        (r"(?:^|/)ChangeLog.*$", []),
87        (r"(?:^|/)Makefile$", []),
88        (r"/ARM", []),
89        (r"/CMake.*", []),
90        (r"/LICENSE[^/]+$", []),
91        (r"ARM(?:v7)?\.(?:cpp|h)$", []),
92        (r"MIPS\.(?:cpp|h)$", []),
93        (r"WinCE\.(?:cpp|h|mm)$", []),
94        (r"\.(?:bkl|mk)$", []),
95
96        # Patterns that should trigger builds on only some bots.
97        (r"(?:^|/)GNUmakefile\.am$", ["gtk"]),
98        (r"/\w+Chromium\w*\.(?:cpp|h|mm)$", ["chromium"]),
99        (r"Mac\.(?:cpp|h|mm)$", ["mac"]),
100        (r"\.(?:vcproj|vsprops|sln)$", ["win"]),
101        (r"\.exp(?:\.in)?$", ["mac"]),
102        (r"\.gypi?", ["chromium"]),
103        (r"\.order$", ["mac"]),
104        (r"\.pr[io]$", ["qt"]),
105        (r"\.vcproj/", ["win"]),
106        (r"\.xcconfig$", ["mac"]),
107        (r"\.xcodeproj/", ["mac"]),
108    ]
109
110    base_platform = target_platform.split("-")[0]
111
112    # See if the file is in one of the known directories.
113    for directory, platforms in directories:
114        if re.search(r"(?:^|/)%s/" % directory, file):
115            return target_platform in platforms or base_platform in platforms
116
117    # See if the file matches a known pattern.
118    for pattern, platforms in patterns:
119        if re.search(pattern, file):
120            return target_platform in platforms or base_platform in platforms
121
122    # See if the file is a platform-specific test result.
123    match = re.match("LayoutTests/platform/(?P<platform>[^/]+)/", file)
124    if match:
125        # See if the file is a test result for this platform, our base
126        # platform, or one of our sub-platforms.
127        return match.group("platform") in (target_platform, base_platform) or match.group("platform").startswith("%s-" % target_platform)
128
129    # The file isn't one we know about specifically, so we should assume we
130    # have to build.
131    return True
132
133
134def should_build(target_platform, changed_files):
135    """Returns true if the changed files affect the given platform, and
136    thus a build should be performed. target_platform should be one of the
137    platforms used in the build.webkit.org master's config.json file."""
138    return any(_should_file_trigger_build(target_platform, file) for file in changed_files)
139