blob: 3119954328394bc6fcefea7dd8f294c3710a7b03 [file] [log] [blame]
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
This tool creates a tarball with V8 sources, but without .svn directories.
This allows easy packaging of V8, synchronized with browser releases.
Example usage: /foo/bar
The above will create file /foo/bar/v8-VERSION.tar.bz2 if it doesn't exist.
import optparse
import os
import re
import subprocess
import sys
import tarfile
_V8_MAJOR_VERSION_PATTERN = re.compile(r'#define\s+MAJOR_VERSION\s+(.*)')
_V8_MINOR_VERSION_PATTERN = re.compile(r'#define\s+MINOR_VERSION\s+(.*)')
_V8_BUILD_NUMBER_PATTERN = re.compile(r'#define\s+BUILD_NUMBER\s+(.*)')
_V8_PATCH_LEVEL_PATTERN = re.compile(r'#define\s+PATCH_LEVEL\s+(.*)')
def GetV8Version(v8_directory):
Returns version number as string based on the string
contents of file.
with open(os.path.join(v8_directory, 'src', '')) as version_file:
version_contents =
version_components = []
for pattern in _V8_PATTERNS:
if version_components[len(version_components) - 1] == '0':
return '.'.join(version_components)
def GetSourceDirectory():
return os.path.realpath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src'))
def GetV8Directory():
return os.path.join(GetSourceDirectory(), 'v8')
# Workaround lack of the exclude parameter in add method in python-2.4.
# TODO(phajdan.jr): remove the workaround when it's not needed on the bot.
class MyTarFile(tarfile.TarFile):
def add(self, name, arcname=None, recursive=True, exclude=None):
head, tail = os.path.split(name)
if tail in ('.svn', '.git'):
tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive)
def main(argv):
parser = optparse.OptionParser()
options, args = parser.parse_args(argv)
if len(args) != 1:
print 'You must provide only one argument: output file directory'
return 1
v8_directory = GetV8Directory()
if not os.path.exists(v8_directory):
print 'Cannot find the v8 directory.'
return 1
v8_version = GetV8Version(v8_directory)
print 'Packaging V8 version %s...' % v8_version
output_basename = 'v8-%s' % v8_version
output_fullname = os.path.join(args[0], output_basename + '.tar.bz2')
if os.path.exists(output_fullname):
print 'Already packaged, exiting.'
return 0
subprocess.check_call(["make", "dependencies"], cwd=v8_directory)
archive =, 'w:bz2')
archive.add(v8_directory, arcname=output_basename)
return 0
if __name__ == '__main__':