1
#!/usr/bin/env python
2
# This script is a workaround the RVCT compiler and linker crashes while compiling WebKit in debug
3
4
import os
5
import os.path
6
import re
7
8
# Do not aglomerate these directories
9
exceptionDirs = [
10
    '../JavaScriptCore/API',
11
    '../WebKit/qt/Api',
12
    '../WebKit/qt/WebCoreSupport',
13
    ]
14
15
# In these directories, create separate aglomerate files for sources matching each pattern
16
dirExtraSplits = {
17
    'generated': (# These splits are trial/error until armcc stoped reporting Internal faults...
18
                  re.compile(r'^JSHTML'),
19
                  re.compile(r'^JSCss'),
20
                  re.compile(r'^JSSVGAnimated'),
21
                  re.compile(r'^JSSVGFE'),
22
                  re.compile(r'^JSSVGPathSeg'),
23
                  re.compile(r'^JSSVG'),
24
                  re.compile(r'^JSD'),
25
                  re.compile(r'^JSX'),
26
                  re.compile(r'^JS'),
27
                  ),
28
    # Because of Token being defined twice
29
    'xml': (re.compile(r'^XSL'),)
30
    }
31
32
# Compile these files alone
33
exceptionFiles = [
34
    '../JavaScriptCore/wtf/CurrentTime.cpp',
35
    # Bacause of WebCore::finalize
36
    'bindings/js/JavaScriptProfileNode.cpp',
37
    # Because of WebCore::handleException
38
    'bindings/js/ScriptObject.cpp',
39
    # Because of JSType being defined in JSC/API and JSC/runtime
40
    'bindings/js/JavaScriptProfile.cpp',
41
    'bindings/js/ScriptValue.cpp',
42
    # Because FontFallbackList.h have expicitely no include gard
43
    'platform/graphics/FontFallbackList.cpp',
44
    'platform/graphics/Font.cpp',
45
    'platform/graphics/FontCache.cpp',
46
47
    # Stand-alone files with no documented reason
48
    'accessibility/qt/AccessibilityObjectQt.cpp',
49
    'bindings/js/ScriptControllerQt.cpp',
50
    'bridge/IdentifierRep.cpp',
51
    'bridge/NP_jsobject.cpp',
52
    'bridge/c/c_instance.cpp',
53
    'bridge/c/c_runtime.cpp',
54
    'bridge/c/c_utility.cpp',
55
    'bridge/qt/qt_class.cpp',
56
    'bridge/qt/qt_instance.cpp',
57
    'bridge/qt/qt_runtime.cpp',
58
    'css/FontFamilyValue.cpp',
59
    'css/MediaFeatureNames.cpp',
60
    'css/SVGCSSStyleSelector.cpp',
61
    'dom/NamedAttrMap.cpp',
62
    'dom/NamedMappedAttrMap.cpp',
63
    'dom/NamedNodeMap.cpp',
64
    'dom/Node.cpp',
65
    'dom/QualifiedName.cpp',
66
    'editing/qt/EditorQt.cpp',
67
    'generated/HTMLElementFactory.cpp',
68
    'generated/HTMLEntityNames.cpp',
69
    'generated/HTMLNames.cpp',
70
    'generated/JSElement.cpp',
71
    'generated/JSHTMLElementWrapperFactory.cpp',
72
    'generated/SVGNames.cpp',
73
    'generated/XLinkNames.cpp',
74
    'generated/XPathGrammar.cpp',
75
    'generated/XPathGrammar.tab.c',
76
    'history/BackForwardList.cpp',
77
    'history/CachedFrame.cpp',
78
    'history/CachedPage.cpp',
79
    'html/File.cpp',
80
    'html/FileList.cpp',
81
    'html/FormDataList.cpp',
82
    'html/HTMLAllCollection.cpp',
83
    'html/HTMLCollection.cpp',
84
    'html/HTMLDataListElement.cpp',
85
    'html/HTMLDocument.cpp',
86
    'html/HTMLFormCollection.cpp',
87
    'html/HTMLImageLoader.cpp',
88
    'html/HTMLNameCollection.cpp',
89
    'html/HTMLOptionsCollection.cpp',
90
    'html/HTMLParser.cpp',
91
    'html/HTMLParserErrorCodes.cpp',
92
    'html/HTMLTableRowsCollection.cpp',
93
    'html/HTMLTokenizer.cpp',
94
    'html/HTMLViewSourceDocument.cpp',
95
    'html/ImageData.cpp',
96
    'html/LegacyHTMLDocumentParser.cpp',
97
    'html/LegacyPreloadScanner.cpp',
98
    'html/PreloadScanner.cpp',
99
    'html/TimeRanges.cpp',
100
    'html/ValidityState.cpp',
101
    'inspector/InspectorFrontendClientLocal.cpp',
102
    'loader/FrameLoader.cpp',
103
    'loader/FTPDirectoryDocument.cpp',
104
    'loader/ImageDocument.cpp',
105
    'loader/MediaDocument.cpp',
106
    'loader/PluginDocument.cpp',
107
    'loader/TextResourceDecoder.cpp',
108
    'page/Frame.cpp',
109
    'page/qt/DragControllerQt.cpp',
110
    'page/qt/EventHandlerQt.cpp',
111
    'page/qt/FrameQt.cpp',
112
    'platform/ContextMenu.cpp',
113
    'platform/KURL.cpp',
114
    'platform/Scrollbar.cpp',
115
    'platform/ScrollbarThemeComposite.cpp',
116
    'platform/graphics/Color.cpp',
117
    'platform/graphics/MediaPlayer.cpp',
118
    'platform/graphics/SimpleFontData.cpp',
119
    'platform/qt/PasteboardQt.cpp',
120
    'platform/qt/PlatformQtAllInOne.cpp',
121
    'plugins/qt/PluginDataQt.cpp',
122
    'rendering/MediaControlElements.cpp',
123
    'rendering/PointerEventsHitRules.cpp',
124
    'rendering/RenderListItem.cpp',
125
    'rendering/RenderImage.cpp',
126
    'rendering/RenderLayer.cpp',
127
    'rendering/RenderLayerBacking.cpp',
128
    'rendering/RenderVideo.cpp',
129
    'rendering/RenderObjectChildList.cpp',
130
    'rendering/RenderingSVGAllInOne.cpp',
131
    'rendering/SVGRenderTreeAsText.cpp',
132
    'svg/SVGDocumentExtensions.cpp',
133
    'svg/SVGFontFaceElement.cpp',
134
    'svg/SVGGlyphElement.cpp',
135
    'svg/SVGHKernElement.cpp',
136
    'svg/SVGImageLoader.cpp',
137
    'svg/SVGStyleElement.cpp',
138
    'svg/SVGStyledElement.cpp',
139
    ]
140
141
# Find WebCore's directory
142
print('... Seeking the WebCore directory')
143
while not os.path.exists('WebCore/WebCore.pro'):
144
    if os.path.realpath('.') == os.path.realpath('..'):
145
        raise Exception("Could not find WebKit's root directory within parent directories. Are you in WebKit's tree?") 
146
    os.chdir('..')
147
os.chdir('WebCore')
148
149
# Read the .mmp file name from bld.inf
150
mmpFileNamePattern = re.compile(r'.*\.mmp$', re.IGNORECASE)
151
if not os.path.exists('bld.inf'):
152
    raise Exception('Could not find WebCore/bld.inf. Did you run build-webkit or qmake using Qt configured for symbian-sbsv2?')
153
with open('bld.inf') as bldFile:
154
    for line in bldFile:
155
        m = mmpFileNamePattern.match(line)
156
        if m:
157
            mmpFileName = m.group()
158
            break
159
160
newContentLines = []
161
sourcePathPattern = re.compile(r'SOURCEPATH\s+(.+)$')
162
sourcePattern = re.compile(r'SOURCE\s+(.+)$')
163
allInOneFilePattern = re.compile(r'SOURCE\s+AllInOne_')
164
pathChunkPattern = re.compile(r'\w+')
165
dirCombinedFilesSubGroups = [] # Each group is a tuple of its file pattern along with the opened aglomerate file
166
dirIsExcluded = False
167
168
if not os.path.exists(mmpFileName):
169
    raise Exception('Could not find the {0} file specified in WebCore/bld.inf. Did you run build-webkit or qmake using Qt configured for symbian-sbsv2?'.format(mmpFileName))
170
with open(mmpFileName) as mmpFile:
171
    for line in mmpFile:
172
        if allInOneFilePattern.match(line):
173
            raise Exception("This script has already been ran. Please re-run qmake or restore a backup copy of the WebCore's mmp file if you want to force a refresh.")
174
    mmpFile.seek(0)
175
176
    for line in mmpFile:
177
        # Look for SOURCEPATH...-like lines
178
        pathMatch = sourcePathPattern.match(line)
179
        if pathMatch:
180
            currentSourcePath = pathMatch.group(1)
181
182
            newContentLines.append(line)
183
            if currentSourcePath in exceptionDirs:
184
                dirIsExcluded = True
185
            else:
186
                dirIsExcluded = False
187
188
                sourceSuffix = '_'.join(pathChunkPattern.findall(currentSourcePath))
189
190
                # Close aglomerate files and reset the sub groups list
191
                for group in dirCombinedFilesSubGroups:
192
                    group[1].close()
193
                dirCombinedFilesSubGroups = []
194
195
                # The additional subgroup, if specified. armcc doesn't seem to like huge files
196
                if currentSourcePath in dirExtraSplits.keys():
197
                    patterns = dirExtraSplits[currentSourcePath]
198
                    for i in range(len(patterns)):
199
                        allInOneFileName = 'AllInOne_{0}{1}.cpp'.format(sourceSuffix, i)
200
                        print('--- Creating aglomerate file [{0}]'.format(currentSourcePath + '/' + allInOneFileName))
201
                        dirCombinedFilesSubGroups.append((patterns[i], open(currentSourcePath + '/' + allInOneFileName, 'w')))
202
                        newContentLines.append("SOURCE\t\t{0}\n".format(allInOneFileName))
203
204
                # The default aglomerate source file which include cpp files
205
                # Append it as the last group with no pattern to be used when no other sub-group pattern matched
206
                allInOneFileName = 'AllInOne_{0}.cpp'.format(sourceSuffix)
207
                print('--- Creating aglomerate file [{0}]'.format(currentSourcePath + '/' + allInOneFileName))
208
                dirCombinedFilesSubGroups.append((None, open(currentSourcePath + '/' + allInOneFileName, 'w')))
209
                newContentLines.append("SOURCE\t\t{0}\n".format(allInOneFileName))
210
211
            continue # for line in mmpFile:
212
213
        # Look for SOURCE...-like lines
214
        sourceMatch = sourcePattern.match(line)
215
        if not dirIsExcluded and sourceMatch:
216
            sourceFileName = sourceMatch.group(1)
217
            sourceFilePath = currentSourcePath + '/' + sourceFileName
218
            if not sourceFilePath in exceptionFiles:
219
                for group in dirCombinedFilesSubGroups:
220
                    if group[0] is None or group[0].match(sourceFileName):
221
                        group[1].write("#include \"{0}\"\n".format(sourceFileName))
222
                        break # for group in dirCombinedFilesSubGroups: 
223
                continue # for line in mmpFile:
224
225
        # Else
226
        newContentLines.append(line)
227
228
for group in dirCombinedFilesSubGroups:
229
    group[1].close()
230
231
print('=== Patching the MMP file [{0}]'.format(mmpFileName))
232
mmpFile = open(mmpFileName, 'w')
233
mmpFile.writelines(newContentLines)
234
mmpFile.close()