SDK_VARIANT build destinations should be separate from non-SDK_VARIANT builds
[WebKit-https.git] / Tools / Scripts / webkitpy / style / checkers / sdkvariant.py
1 # Copyright (C) 2018 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24
25 """Supports ensuring equality of SDKVariant.xcconfig files."""
26
27 import os
28
29 from webkitpy.common.system.systemhost import SystemHost
30
31 SDK_VARIANT_FILES = [
32     "PerformanceTests/MediaTime/Configurations/SDKVariant.xcconfig",
33     "Tools/ImageDiff/cg/Configurations/SDKVariant.xcconfig",
34     "Tools/WebEditingTester/Configurations/SDKVariant.xcconfig",
35     "Tools/MiniBrowser/Configurations/SDKVariant.xcconfig",
36     "Tools/WebKitLauncher/Configurations/SDKVariant.xcconfig",
37     "Tools/lldb/lldbWebKitTester/Configurations/SDKVariant.xcconfig",
38     "Tools/DumpRenderTree/mac/Configurations/SDKVariant.xcconfig",
39     "Tools/ContentExtensionTester/Configurations/SDKVariant.xcconfig",
40     "Tools/WebKitTestRunner/Configurations/SDKVariant.xcconfig",
41     "Tools/MobileMiniBrowser/Configurations/SDKVariant.xcconfig",
42     "Tools/TestWebKitAPI/Configurations/SDKVariant.xcconfig",
43     "Source/bmalloc/Configurations/SDKVariant.xcconfig",
44     "Source/WTF/Configurations/SDKVariant.xcconfig",
45     "Source/WebKitLegacy/mac/Configurations/SDKVariant.xcconfig",
46     "Source/WebInspectorUI/Configurations/SDKVariant.xcconfig",
47     "Source/WebKit/Configurations/SDKVariant.xcconfig",
48     "Source/JavaScriptCore/Configurations/SDKVariant.xcconfig",
49     "Source/WebCore/Configurations/SDKVariant.xcconfig",
50     "Source/WebCore/PAL/Configurations/SDKVariant.xcconfig",
51     "Source/ThirdParty/ANGLE/Configurations/SDKVariant.xcconfig",
52     "Source/ThirdParty/libwebrtc/Configurations/SDKVariant.xcconfig",
53 ]
54
55
56 class SDKVariantChecker(object):
57     categories = set(['SDKVariant/new', 'SDKVariant/equality'])
58
59     def __init__(self, file_path, handle_style_error):
60         self._file_path = file_path
61         self._handle_style_error = handle_style_error
62         self._handle_style_error.turn_off_line_filtering()
63         self._host = SystemHost()
64         self._fs = self._host.filesystem
65
66     def check(self, inline=None):
67         if self._file_path not in SDK_VARIANT_FILES:
68             self._handle_style_error(0, 'SDKVariant/new', 5, "Patch introduces a new SDKVariant.xcconfig, which check-webkit-style doesn't know about. Please add it to the list in SDKVariant.py.")
69             return
70
71         with self._fs.open_binary_file_for_reading(self._file_path) as filehandle:
72             baseline_content = filehandle.read()
73
74         other_SDK_VARIANTs_files = SDK_VARIANT_FILES
75         other_SDK_VARIANTs_files.remove(self._file_path)
76
77         for path in other_SDK_VARIANTs_files:
78             with self._fs.open_binary_file_for_reading(path) as filehandle:
79                 test_content = filehandle.read()
80                 if baseline_content != test_content:
81                     self._handle_style_error(0, 'SDKVariant/equality', 5, "Any changes made to SDKVariant should be made to all of them (changed file does not match {0}).".format(path))