summaryrefslogtreecommitdiffstats
path: root/tools/export_tarball
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 23:32:46 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 23:32:46 +0000
commit67fcfa1303798cc746281af87a177512eada8185 (patch)
tree4681b29750659154fb336d51c1ad5dfc636d4108 /tools/export_tarball
parent113477069f29abf38b773b66e29cbd404175ca9f (diff)
downloadchromium_src-67fcfa1303798cc746281af87a177512eada8185.zip
chromium_src-67fcfa1303798cc746281af87a177512eada8185.tar.gz
chromium_src-67fcfa1303798cc746281af87a177512eada8185.tar.bz2
Add export_v8_tarball.py, a new tool to also export
standalone tarballs for V8. This will be useful for Linux distributions packaging shared library packages for V8. BUG=none Review URL: http://codereview.chromium.org/7600011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/export_tarball')
-rw-r--r--tools/export_tarball/export_v8_tarball.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/tools/export_tarball/export_v8_tarball.py b/tools/export_tarball/export_v8_tarball.py
new file mode 100644
index 0000000..9715591
--- /dev/null
+++ b/tools/export_tarball/export_v8_tarball.py
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+# 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:
+
+export_v8_tarball.py /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+(.*)')
+
+_V8_PATTERNS = [
+ _V8_MAJOR_VERSION_PATTERN,
+ _V8_MINOR_VERSION_PATTERN,
+ _V8_BUILD_NUMBER_PATTERN,
+ _V8_PATCH_LEVEL_PATTERN]
+
+def GetV8Version(v8_directory):
+ """
+ Returns version number as string based on the string
+ contents of version.cc file.
+ """
+ with open(os.path.join(v8_directory, 'src', 'version.cc')) as version_file:
+ version_contents = version_file.read()
+
+ version_components = []
+ for pattern in _V8_PATTERNS:
+ version_components.append(pattern.search(version_contents).group(1).strip())
+
+ if version_components[len(version_components) - 1] == '0':
+ version_components.pop()
+
+ 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'):
+ return
+
+ 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
+
+ archive = MyTarFile.open(output_fullname, 'w:bz2')
+ try:
+ archive.add(v8_directory, arcname=output_basename)
+ finally:
+ archive.close()
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))