1 # Copyright (C) 2009 Kevin Ollivier All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
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.
12 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
13 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
16 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
17 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20 # 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.
24 # Helper functions for the WebKit build.
37 def get_output(command):
39 Windows-compatible function for getting output from a command.
41 if sys.platform.startswith('win'):
43 return f.read().strip()
45 return commands.getoutput(command)
48 def get_excludes(root, patterns):
50 Get a list of exclude patterns going down several dirs.
51 TODO: Make this fully recursive.
55 for pattern in patterns:
56 subdir_pattern = os.sep + '*'
57 for subdir in [subdir_pattern, subdir_pattern * 2, subdir_pattern * 3]:
58 adir = root + subdir + os.sep + pattern
59 files = glob.glob(adir)
61 excludes.append(os.path.basename(afile))
66 def get_dirs_for_features(root, features, dirs):
68 Find which directories to include in the list of build dirs based upon the
69 enabled port(s) and features.
73 for feature in features:
74 relpath = os.path.join(adir, feature)
75 featuredir = os.path.join(root, relpath)
76 if os.path.exists(featuredir) and not relpath in outdirs:
77 outdirs.append(relpath)
82 def download_if_newer(url, destdir):
84 Checks if the file on the server is newer than the one in the user's tree,
85 and if so, downloads it.
87 Returns the filename of the downloaded file if downloaded, or None if
88 the existing file matches the one on the server.
90 obj = urlparse.urlparse(url)
91 filename = os.path.basename(obj.path)
92 destfile = os.path.join(destdir, filename)
94 urlobj = urllib.urlopen(url)
95 size = long(urlobj.info().getheader('Content-Length'))
97 def download_callback(downloaded, block_size, total_size):
98 downloaded = block_size * downloaded
99 if downloaded > total_size:
100 downloaded = total_size
101 sys.stdout.write('%s %d of %d bytes downloaded\r' % (filename, downloaded, total_size))
103 # NB: We don't check modified time as Python doesn't yet handle timezone conversion
104 # properly when converting strings to time objects.
105 if not os.path.exists(destfile) or os.path.getsize(destfile) != size:
106 urllib.urlretrieve(url, destfile, download_callback)
113 def update_wx_deps(conf, wk_root, msvc_version='msvc2008'):
115 Download and update tools needed to build the wx port.
118 Logs.info('Ensuring wxWebKit dependencies are up-to-date.')
120 wklibs_dir = os.path.join(wk_root, 'WebKitLibraries')
121 waf = download_if_newer('http://wxwebkit.wxcommunity.com/downloads/deps/waf', os.path.join(wk_root, 'Tools', 'wx'))
123 # TODO: Make the build restart itself after an update.
124 Logs.warn('Build system updated, please restart build.')
127 # since this module is still experimental
128 wxpy_dir = os.path.join(wk_root, 'Source', 'WebKit', 'wx', 'bindings', 'python')
129 swig_module = download_if_newer('http://wxwebkit.wxcommunity.com/downloads/deps/swig.py.txt', wxpy_dir)
131 shutil.copy(os.path.join(wxpy_dir, 'swig.py.txt'), os.path.join(wxpy_dir, 'swig.py'))
133 if sys.platform.startswith('win'):
134 Logs.info('downloading deps package')
135 archive = download_if_newer('http://wxwebkit.wxcommunity.com/downloads/deps/wxWebKitDeps-%s.zip' % msvc_version, wklibs_dir)
136 if archive and os.path.exists(archive):
137 os.system('unzip -o %s -d %s' % (archive, os.path.join(wklibs_dir, msvc_version)))
139 elif sys.platform.startswith('darwin'):
140 # export the right compiler for building the dependencies
141 if platform.release().startswith('10'): # Snow Leopard
142 os.environ['CC'] = conf.env['CC'][0]
143 os.environ['CXX'] = conf.env['CXX'][0]
144 os.system('%s/Tools/wx/install-unix-extras' % wk_root)
147 def includeDirsForSources(sources):
149 for group in sources:
151 dirname = os.path.dirname(source)
152 if not dirname in include_dirs:
153 include_dirs.append(dirname)
158 def flattenSources(sources):
160 for group in sources:
161 flat_sources.extend(group)
165 def git_branch_name():
167 branches = commands.getoutput("git branch --no-color")
168 match = re.search('^\* (.*)', branches, re.MULTILINE)
170 return "%s" % match.group(1)
176 def is_git_branch_build():
177 branch = git_branch_name()
178 is_branch_build = commands.getoutput("git config --bool branch.%s.webKitBranchBuild" % branch)
179 if is_branch_build == "true":
181 elif is_branch_build == "false":
184 # not defined for this branch, use the default
185 is_branch_build = commands.getoutput("git config --bool core.webKitBranchBuild")
186 return is_branch_build == "true"
188 def get_base_product_dir(wk_root):
189 build_dir = os.path.join(wk_root, 'WebKitBuild')
190 git_branch = git_branch_name()
191 if git_branch != "" and is_git_branch_build():
192 build_dir = os.path.join(build_dir, git_branch)
196 def get_config(wk_root):
197 config_file = os.path.join(get_base_product_dir(wk_root), 'Configuration')
200 if os.path.exists(config_file):
201 config = open(config_file).read()
206 def get_arch(wk_root):
207 arch_file = os.path.join(get_base_product_dir(wk_root), 'Architecture')
210 if os.path.exists(arch_file):
211 arch = open(arch_file).read()
217 if os.system("git-svn info") == 0:
218 info = commands.getoutput("git-svn info ../..")
220 info = commands.getoutput("svn info")
222 for line in info.split("\n"):
223 if line.startswith("Revision: "):
224 return line.replace("Revision: ", "").strip()