Use after free in JSC::DFG::ByteCodeParser::processPhiStack
[WebKit-https.git] / wscript
1 #! /usr/bin/env python
2
3 # Copyright (C) 2009 Kevin Ollivier  All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25 #
26 # WebCore build script for the waf build system
27
28 import glob
29 import os
30 import subprocess
31
32 import Options
33
34 from settings import *
35 import wxpresets
36
37 import TaskGen
38 from TaskGen import taskgen, feature, after
39 import Task, ccroot
40
41 def clean_derived_sources(ds_cmd):
42     cmd = ds_cmd + " -qp | grep -v '^# ' | grep -v '^[[:space:]]' | grep --only-matching '^.*:'"
43     output = subprocess.check_output(cmd, shell=True)
44     
45     targets = []
46     lines = output.split("\n")
47     for line in lines:
48         line = line.replace(":", "")
49         base = os.path.splitext(os.path.basename(line))[0]
50         if not base in targets:
51             targets.append(base)
52             if base == "UserAgentsStyleSheet":
53                 targets.append("UserAgentsStyleSheetData")
54     
55     # we're in the DerivedSources directory when this command is run.
56     ds_files = glob.glob("*.*")
57     for ds_file in ds_files:
58         filename = os.path.basename(ds_file)
59         basename = os.path.splitext(filename)[0]
60         # For now, just remove JS*.h/.cpp and WebDOM*.h/.cpp when there are no longer targets
61         # for them. Other targets may generate supplemental files so we can't reliably clean them.
62         if not basename in targets and (basename.startswith("JS") or basename.startswith("WebDOM")):
63             print "INFO: %s is no longer generated but present in generated files directory. Removing." % filename
64             os.remove(ds_file)
65     
66 def generate_webcore_derived_sources(conf):
67     # build the derived sources
68     derived_sources_dir = os.path.join(webcore_dir, 'DerivedSources')
69     wc_dir = webcore_dir
70     if building_on_win32:
71         wc_dir = get_output('cygpath --unix "%s"' % wc_dir)
72     if not os.path.exists(derived_sources_dir):
73         os.mkdir(derived_sources_dir)
74
75     olddir = os.getcwd()
76     os.chdir(derived_sources_dir)
77     
78     # DerivedSources.make expects Cygwin (i.e. Unix-style) python, so use that instead.
79     if building_on_win32:
80         oldpath = os.environ["PATH"]
81         os.environ["PATH"] = "/usr/bin" + os.pathsep + os.environ["PATH"]
82     command = 'make -f %s/DerivedSources.make WebCore=%s SOURCE_ROOT=%s all FEATURE_DEFINES="%s"' % (wc_dir, wc_dir, wc_dir, conf.env["FEATURE_DEFINES"])
83     clean_derived_sources(command)
84     os.system(command)
85     if building_on_win32:
86         os.environ["PATH"] = oldpath
87     
88     os.chdir(olddir)
89
90 def generate_jscore_derived_sources(conf):
91     # build the derived sources
92     js_dir = jscore_dir
93     if building_on_win32:
94         js_dir = get_output('cygpath --unix "%s"' % js_dir)
95     derived_sources_dir = os.path.join(jscore_dir, 'DerivedSources')
96     if not os.path.exists(derived_sources_dir):
97         os.mkdir(derived_sources_dir)
98
99     olddir = os.getcwd()
100     os.chdir(derived_sources_dir)
101
102     # DerivedSources.make expects Cygwin (i.e. Unix-style) python, so use that instead.
103     if building_on_win32:
104         oldpath = os.environ["PATH"]
105         os.environ["PATH"] = "/usr/bin" + os.pathsep + os.environ["PATH"]
106     command = 'make -f %s/DerivedSources.make JavaScriptCore=%s BUILT_PRODUCTS_DIR=%s all FEATURE_DEFINES="%s"' % (js_dir, js_dir, js_dir, conf.env["FEATURE_DEFINES"])
107     os.system(command)
108     if building_on_win32:
109         os.environ["PATH"] = oldpath
110     os.chdir(olddir)
111
112 def set_options(opt):
113     common_set_options(opt)
114
115 def configure(conf):
116     common_configure(conf)
117     generate_jscore_derived_sources(conf)
118     generate_webcore_derived_sources(conf)
119     if Options.options.port == "wx" and sys.platform.startswith('win'):
120         graphics_dir = os.path.join(wk_root, 'Source', 'WebCore', 'platform', 'graphics')
121         # we used to copy these files into the graphics/wx directory due to 
122         # both wx and win directories having FontPlatformData.h. That is no 
123         # longer the case, so we remove the old files if they exist.
124         for afile in ['UniscribeController.h', 'UniscribeController.cpp', 'GlyphPageTreeNodeCairoWin.cpp']:
125             wx_copy = os.path.join(graphics_dir, 'wx', afile)
126             if os.path.exists(wx_copy):
127                 os.remove(wx_copy)
128
129     webcore_out_dir = os.path.join(output_dir, 'WebCore')
130     if not os.path.exists(webcore_out_dir):
131         os.makedirs(webcore_out_dir)
132     shutil.copy('Source/WebCore/platform/mac/WebCoreSystemInterface.h', os.path.join(output_dir, 'WebCore', 'WebCoreSystemInterface.h'))
133     jscore_out_dir = os.path.join(output_dir, 'JavaScriptCore')
134     if not os.path.exists(jscore_out_dir):
135         os.makedirs(jscore_out_dir)
136     for api_file in glob.glob(os.path.join(jscore_dir, 'API/*.h')):
137         shutil.copy(api_file, os.path.join(jscore_out_dir, os.path.basename(api_file)))
138
139     if Options.options.port == "wx" and Options.options.wxpython:
140         common_configure(conf)
141         conf.check_tool('swig', tooldir='Source/WebKit/wx/bindings/python')
142         conf.check_swig_version('1.3.29')
143
144 def build(bld):
145
146     webcore_dirs = list(webcore_dirs_common)
147
148     # auto-generate WebKitVersion.h if needed before we start the build.
149     # Also, remove the file from the old location where we generated it before running
150     wk_version_h = 'Source/WebCore/DerivedSources/WebKitVersion.h'
151     if os.path.exists(wk_version_h):
152         os.remove(wk_version_h)
153     bld.new_task_gen(source = "Source/WebKit/mac/Configurations/Version.xcconfig",
154                      target = wk_version_h,
155                      rule = 'perl %s/Source/WebKit/scripts/generate-webkitversion.pl --outputDir=${TGT[0].dir(env)} --config ${SRC}' % wk_root)
156     bld.add_group()
157
158     if Options.options.port == "wx":
159         webcore_dirs.extend(['Source/WebKit/wx', 'Source/WebKit/wx/WebKitSupport'])
160     
161     wk_includes = ['.',
162                     os.path.join(wk_root, 'Source', 'WTF'),
163                     os.path.join(wk_root, 'Source', 'WTF', 'wtf'),
164                     os.path.join(wk_root, 'Source', 'JavaScriptCore'),
165                     os.path.join(wk_root, 'Source', 'WebCore'),
166                     os.path.join(wk_root, 'Source', 'WebCore', 'DerivedSources'),
167                     os.path.join(wk_root, 'Source', 'WebCore', 'platform', 'image-decoders'),
168                     os.path.join(wk_root, 'Source', 'WebCore', 'platform', 'win'),
169                     os.path.join(wk_root, 'Source', 'WebCore', 'workers'),
170                     os.path.join(output_dir),
171             ]
172     
173     if Options.options.port == "wx":
174         wk_includes.append(os.path.join(wk_root, 'Source', 'WebKit', 'wx'))
175         wk_includes.append(os.path.join(wk_root, 'Source', 'WebCore', 'platform', 'wx', 'wxcode'))
176     
177     if sys.platform.startswith("win"):
178         wk_includes.append(os.path.join(wk_root, 'Source', 'WebCore', 'platform', 'win'))
179         wk_includes.append(os.path.join(wk_root, 'Source', 'WebCore', 'platform', 'graphics', 'win'))
180     
181     windows_deps = [
182                     'lib/pthreadVC2.dll',
183                     'bin/icuuc40.dll', 'bin/icudt40.dll', 'bin/icuin40.dll',
184                     'bin/libcurl.dll', 'bin/libeay32.dll', 'bin/ssleay32.dll', 'bin/zlib1.dll',
185                     'lib/sqlite3.dll', 'bin/libxml2.dll', 'bin/libxslt.dll', 'bin/iconv.dll',
186                     ]
187     
188     webcore_sources = {}
189     
190     if Options.options.port == "wx":
191         webcore_sources['wx'] = [
192             'Source/WebCore/bindings/cpp/WebDOMEventTarget.cpp',
193             'Source/WebCore/platform/KillRingNone.cpp',
194             'Source/WebCore/platform/text/LocalizedDateNone.cpp',
195             'Source/WebCore/platform/text/LocalizedNumberNone.cpp',
196             'Source/WebCore/page/scrolling/ScrollingCoordinatorNone.cpp',
197         ]  
198     
199         if building_on_win32:
200             # make sure platform/wx comes after this so we get the right
201             # FontPlatformData.h
202             webcore_dirs.extend(['Source/WebCore/platform/wx/wxcode/win', 'Source/WebCore/plugins/win'])
203             webcore_sources['wx-win'] = [
204                    'Source/WebCore/platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp',
205                    'Source/WebCore/platform/graphics/win/TransformationMatrixWin.cpp',
206                    'Source/WebCore/platform/graphics/win/UniscribeController.cpp',
207                    'Source/WebCore/platform/ScrollAnimatorNone.cpp',
208                    # wxTimer on Windows has a bug that causes it to eat crashes in callbacks
209                    # so we need to use the Win port's implementation until the wx bug fix is
210                    # widely available (it was fixed in 2.8.10).
211                    'Source/WebCore/platform/win/SharedTimerWin.cpp',
212                    'Source/WebCore/platform/win/SystemInfo.cpp',
213                    'Source/WebCore/platform/win/WebCoreInstanceHandle.cpp',
214                    # Use the Windows plugin architecture
215                    #'Source/WebCore/plugins/win/PluginDataWin.cpp',
216                    'Source/WebCore/plugins/win/PluginDatabaseWin.cpp',
217                    'Source/WebCore/plugins/win/PluginMessageThrottlerWin.cpp',
218                    'Source/WebCore/plugins/win/PluginPackageWin.cpp',
219                    'Source/WebCore/plugins/win/PluginViewWin.cpp',
220             ]
221             if Options.options.cairo:
222                 webcore_dirs.append('Source/WebCore/platform/wx/wxcode/cairo')
223             else:
224                 webcore_dirs.append('Source/WebCore/platform/wx/wxcode/gdiplus')
225         elif sys.platform.startswith('darwin'):
226             webcore_dirs.append('Source/WebCore/plugins/mac')
227             webcore_dirs.append('Source/WebCore/platform/wx/wxcode/mac/carbon')
228             webcore_dirs.append('Source/WebCore/platform/text/mac')
229             webcore_sources['wx-mac'] = [
230                    'Source/WebCore/platform/mac/PurgeableBufferMac.cpp',
231                    'Source/WebCore/platform/mac/WebCoreNSStringExtras.mm',
232                    'Source/WebCore/platform/mac/WebCoreSystemInterface.mm',
233                    'Source/WebCore/platform/graphics/cg/FloatSizeCG.cpp',
234                    'Source/WebCore/platform/graphics/mac/ComplexTextController.cpp',
235                    'Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm',
236                    'Source/WebCore/platform/graphics/mac/ComplexTextControllerATSUI.cpp',
237                    'Source/WebCore/platform/graphics/mac/GlyphPageTreeNodeMac.cpp',
238                    'Source/WebCore/platform/graphics/mac/SimpleFontDataATSUI.mm',
239                    'Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp',
240                    'Source/WebCore/platform/graphics/wx/FontPlatformDataWxMac.mm',
241                    'Source/WebCore/platform/wx/wxcode/mac/carbon/fontprops.mm',
242                    'Source/WebCore/plugins/mac/PluginPackageMac.cpp',
243                    'Source/WebCore/plugins/mac/PluginViewMac.mm'
244             ]
245         else:
246             webcore_sources['wx-gtk'] = [
247                    'Source/WebCore/plugins/PluginViewNone.cpp',
248                    'Source/WebCore/plugins/PluginPackageNone.cpp'
249             ]
250             webcore_dirs.append('Source/WebCore/platform/wx/wxcode/gtk')
251             webcore_dirs.append('Source/WebCore/platform/wx/wxcode/cairo')
252         
253
254     import TaskGen
255
256     bld.add_subdirs('Source/JavaScriptCore')
257
258     if sys.platform.startswith('darwin'):
259         TaskGen.task_gen.mappings['.mm'] = TaskGen.task_gen.mappings['.cxx']
260         TaskGen.task_gen.mappings['.m'] = TaskGen.task_gen.mappings['.cxx']
261
262     features = [Options.options.port.lower()]
263     thisport = Options.options.port
264     
265     exclude_patterns = ['*AllInOne.cpp', '*None.cpp',]
266
267     if sys.platform.startswith('darwin'):
268         features.append('cf')
269
270     # exclude the filename patterns for all other ports.
271     exclude_patterns.extend(get_port_excludes(Options.options.port))
272             
273     if Options.options.port == 'wx':
274         features.append('curl')
275         exclude_patterns.extend(['*CFNet.cpp', 'test*bindings.*', "WebDOMCanvas*.cpp", "WebDOMSVG*.cpp"])
276         
277     full_dirs = get_dirs_for_features(wk_root, features=features, dirs=webcore_dirs)
278
279     # make sure we don't use the CF networking engine
280     if Options.options.port == 'wx' and sys.platform.startswith('darwin'):
281         full_dirs.remove('Source/WebCore/platform/network/cf')
282         
283     jscore_dir = os.path.join(wk_root, 'Source', 'JavaScriptCore')
284     for item in os.listdir(jscore_dir):
285         fullpath = os.path.join(jscore_dir, item)
286         if os.path.isdir(fullpath) and not item == "os-win32" and not item == 'icu':
287             wk_includes.append(fullpath)
288
289     wk_includes.append('Source')
290     wk_includes.append(os.path.join(jscore_dir, 'collector', 'handles'))
291     wk_includes += common_includes + full_dirs
292     if sys.platform.startswith('darwin'):
293         wk_includes.append(os.path.join(webcore_dir, 'icu'))
294
295     cxxflags = []
296     if building_on_win32:
297         cxxflags.append('/FIWebCorePrefix.h')
298         # FIXME: We do this because in waf, local include dirs take precedence
299         # over global ones. This makes sense, but because unicode/utf8.h is both
300         # an ICU header name and a WebKit header name (in Source/JavaScriptCore/wtf)
301         # we have to make sure <unicode/utf8.h> picks up the ICU one first.
302         global msvclibs_dir
303         wk_includes.append(os.path.join(msvclibs_dir, 'include'))
304         wk_includes.append('Source/WebCore/platform/graphics/win')
305     else:
306         cxxflags.extend(['-include', 'WebCorePrefix.h'])
307
308     webcore = bld.new_task_gen(
309         features = 'cc cxx cshlib',
310         includes = ' '.join(wk_includes),
311         source = ' '.join(flattenSources(webcore_sources.values())),
312         cxxflags = cxxflags,
313         defines = ['WXMAKINGDLL_WEBKIT', 'BUILDING_WebCore'],
314         libpath = [output_dir],
315         target = 'wxwebkit',
316         uselib = 'WX ICU XML XSLT CURL SQLITE3 WKINTERFACE ' + get_config(),
317         uselib_local = 'jscore',
318         install_path = output_dir,
319         )
320         
321     excludes = []
322     
323     if Options.options.port == 'wx':
324         excludes = get_excludes(webcore_dir, exclude_patterns)
325         excludes.extend(['UserStyleSheetLoader.cpp', 'RenderMediaControls.cpp'])
326
327         # intermediate sources
328         excludes.append('DocTypeStrings.cpp')
329         excludes.append('HTMLEntityNames.cpp')
330
331         # Qt specific file in common sources
332         excludes.append('ContextShadow.cpp')
333
334         # FIXME: these require headers that I can't seem to find in trunk.
335         # Investigate how to resolve these issues.
336         excludes.append('JSAbstractView.cpp')
337         excludes.append('JSIntentConstructor.cpp')
338         excludes.append('JSPositionCallback.cpp')
339         excludes.append('JSInspectorController.cpp')
340         
341         # The bindings generator seems to think these are ref-counted, while they aren't in trunk.
342         excludes.append('JSElementTimeControl.cpp')
343         excludes.append('JSSVGAnimatedPathData.cpp')
344         excludes.append('JSSVGAnimatedPoints.cpp')
345         excludes.append('JSSVGExternalResourcesRequired.cpp')
346         excludes.append('JSSVGFilterPrimitiveStandardAttributes.cpp')
347         excludes.append('JSSVGLocatable.cpp')
348         excludes.append('JSSVGStyleTable.cpp')
349         excludes.append('JSSVGTests.cpp')
350         excludes.append('JSSVGStylable.cpp')
351         excludes.append('JSSVGZoomAndPan.cpp')
352         
353         # These are files that expect methods not in the base C++ class, usually XYZAnimated methods.
354         excludes.append('JSSVGFitToViewBox.cpp')
355         excludes.append('JSSVGLangSpace.cpp')
356         excludes.append('JSSVGTransformable.cpp')
357         excludes.append('JSSVGURIReference.cpp')
358         
359         # These are C++ DOM Bindings that won't compile because they look for things not in trunk.
360         excludes.append('WebDOMEventTarget.cpp')
361         excludes.append('WebDOMAbstractView.cpp')
362         excludes.append('WebDOMBlobBuilder.cpp')
363         excludes.append('WebDOMEventListenerCustom.cpp')
364         excludes.append('WebDOMElementTimeControl.cpp')
365         excludes.append('WebDOMImageData.cpp')
366         excludes.append('WebDOMInspectorBackend.cpp')
367         excludes.append('WebDOMScriptProfile.cpp')
368         excludes.append('WebDOMScriptProfileNode.cpp')
369         excludes.append('WebNativeEventListener.cpp')
370         
371         # FIXME: It appears these are no longer needed by any port, once this is confirmed,
372         # we should remove these sources from the tree.
373         excludes.append('WebDOMDOMWindowCustom.cpp')
374         excludes.append('WebDOMHTMLOptionsCollectionCustom.cpp')
375         excludes.append('WebDOMNodeCustom.cpp')
376         excludes.append('WebDOMHTMLDocumentCustom.cpp')
377         excludes.append('WebDOMHTMLCollectionCustom.cpp')
378         excludes.append('WebNativeNodeFilterCondition.cpp')
379         excludes.append('WebDOMNodeFilterCustom.cpp')
380         
381         # this file is unused by any port, not sure why it was
382         # left in the tree
383         excludes.append('GeneratedImage.cpp')
384         
385         # features we don't build / use
386         excludes.append('JSNavigatorCustom.cpp')
387         excludes.append('WebGLContextEvent.cpp')
388         excludes.append('FileSystemPOSIX.cpp')
389         excludes.append('LocaleICU.cpp')
390         excludes.append('LocalizedDateICU.cpp')
391         excludes.append('PlatformGestureRecognizer.cpp')
392         excludes.append('SharedBufferPOSIX.cpp')
393         excludes.append('TouchAdjustment.cpp')
394         excludes.append('DNSResolveQueue.cpp')
395         excludes.append('WebDOMRadioNodeList.cpp')
396         
397         # These files appear not to build with older versions of ICU
398         excludes.append('LocalizedNumberICU.cpp')
399         excludes.append('LocaleToScriptMappingICU.cpp')
400         
401         if building_on_win32:
402             excludes.append('SharedTimerWx.cpp')
403             excludes.append('RenderThemeWin.cpp')
404             excludes.append('KeyEventWin.cpp')
405             
406         if building_on_win32 or sys.platform.startswith('darwin'):
407             excludes.append('GlyphMapWx.cpp')
408         excludes.append('AuthenticationCF.cpp')
409         excludes.append('LoaderRunLoopCF.cpp')
410         excludes.append('ResourceErrorCF.cpp')
411         excludes.append('RunLoopCF.cpp')
412         
413         # once we move over to the new FPD implementation, remove this.
414         excludes.append('FontPlatformData.cpp')
415         
416         # we need a better system to exclude CF stuff
417         excludes.append('HyphenationCF.cpp')
418         
419         if sys.platform.startswith('darwin'):
420             webcore.includes += ' Source/WebKit/mac/WebCoreSupport Source/WebCore/platform/mac'
421             webcore.source += ' Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm'
422             
423         if building_on_win32:
424             for wxlib in bld.env['LIB_WX']:
425                 wx_version = wxpresets.get_wx_version(os.environ['WXWIN'])
426                 if int(wx_version[1]) % 2 == 1:
427                     wxlib = wxlib.replace(''.join(wx_version[:2]), ''.join(wx_version))
428                 wxlibname = os.path.join(bld.env['LIBPATH_WX'][0], wxlib + '_vc.dll')
429                 print "Copying %s" % wxlibname
430                 if os.path.exists(wxlibname):
431                     bld.install_files(webcore.install_path, [wxlibname])
432         
433             for dep in windows_deps:
434                 bld.install_files(webcore.install_path, [os.path.join(msvclibs_dir, dep)])
435             
436             if "CAIRO_ROOT" in os.environ and Options.options.cairo:
437                 cairo_bin_dir = os.path.join(os.environ["CAIRO_ROOT"], "bin") 
438                 for dep in glob.glob(os.path.join(cairo_bin_dir, "*.dll")):
439                     bld.install_files(webcore.install_path, [os.path.join(cairo_bin_dir, dep)])
440                     
441     webcore.find_sources_in_dirs(full_dirs, excludes = excludes, exts=['.c', '.cpp'])
442
443     bld.add_group()
444     
445     if Options.options.port == "wx":    
446         bld.add_subdirs(['Tools/DumpRenderTree', 'Tools/wx/browser', 'Source/WebKit/wx/bindings/python'])