| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """Creates a tarball with V8 sources, but without .svn directories. |
| 7 This tool creates a tarball with V8 sources, but without .svn directories. | |
| 8 | 7 |
| 9 This allows easy packaging of V8, synchronized with browser releases. | 8 This allows easy packaging of V8, synchronized with browser releases. |
| 10 | 9 |
| 11 Example usage: | 10 Example usage: |
| 12 | 11 |
| 13 export_v8_tarball.py /foo/bar | 12 export_v8_tarball.py /foo/bar |
| 14 | 13 |
| 15 The above will create file /foo/bar/v8-VERSION.tar.bz2 if it doesn't exist. | 14 The above will create file /foo/bar/v8-VERSION.tar.bz2 if it doesn't exist. |
| 16 """ | 15 """ |
| 17 | 16 |
| 18 import optparse | 17 import optparse |
| 19 import os | 18 import os |
| 20 import re | 19 import re |
| 21 import subprocess | 20 import subprocess |
| 22 import sys | 21 import sys |
| 23 import tarfile | 22 import tarfile |
| 24 | 23 |
| 25 _V8_MAJOR_VERSION_PATTERN = re.compile(r'#define\s+MAJOR_VERSION\s+(.*)') | 24 _V8_MAJOR_VERSION_PATTERN = re.compile(r'#define\s+MAJOR_VERSION\s+(.*)') |
| 26 _V8_MINOR_VERSION_PATTERN = re.compile(r'#define\s+MINOR_VERSION\s+(.*)') | 25 _V8_MINOR_VERSION_PATTERN = re.compile(r'#define\s+MINOR_VERSION\s+(.*)') |
| 27 _V8_BUILD_NUMBER_PATTERN = re.compile(r'#define\s+BUILD_NUMBER\s+(.*)') | 26 _V8_BUILD_NUMBER_PATTERN = re.compile(r'#define\s+BUILD_NUMBER\s+(.*)') |
| 28 _V8_PATCH_LEVEL_PATTERN = re.compile(r'#define\s+PATCH_LEVEL\s+(.*)') | 27 _V8_PATCH_LEVEL_PATTERN = re.compile(r'#define\s+PATCH_LEVEL\s+(.*)') |
| 29 | 28 |
| 30 _V8_PATTERNS = [ | 29 _V8_PATTERNS = [ |
| 31 _V8_MAJOR_VERSION_PATTERN, | 30 _V8_MAJOR_VERSION_PATTERN, |
| 32 _V8_MINOR_VERSION_PATTERN, | 31 _V8_MINOR_VERSION_PATTERN, |
| 33 _V8_BUILD_NUMBER_PATTERN, | 32 _V8_BUILD_NUMBER_PATTERN, |
| 34 _V8_PATCH_LEVEL_PATTERN] | 33 _V8_PATCH_LEVEL_PATTERN] |
| 35 | 34 |
| 35 |
| 36 def GetV8Version(v8_directory): | 36 def GetV8Version(v8_directory): |
| 37 """ | 37 """ |
| 38 Returns version number as string based on the string | 38 Returns version number as string based on the string |
| 39 contents of version.cc file. | 39 contents of version.cc file. |
| 40 """ | 40 """ |
| 41 with open(os.path.join(v8_directory, 'src', 'version.cc')) as version_file: | 41 with open(os.path.join(v8_directory, 'src', 'version.cc')) as version_file: |
| 42 version_contents = version_file.read() | 42 version_contents = version_file.read() |
| 43 | 43 |
| 44 version_components = [] | 44 version_components = [] |
| 45 for pattern in _V8_PATTERNS: | 45 for pattern in _V8_PATTERNS: |
| 46 version_components.append(pattern.search(version_contents).group(1).strip()) | 46 version_components.append(pattern.search(version_contents).group(1).strip()) |
| 47 | 47 |
| 48 if version_components[len(version_components) - 1] == '0': | 48 if version_components[len(version_components) - 1] == '0': |
| 49 version_components.pop() | 49 version_components.pop() |
| 50 | 50 |
| 51 return '.'.join(version_components) | 51 return '.'.join(version_components) |
| 52 | 52 |
| 53 |
| 53 def GetSourceDirectory(): | 54 def GetSourceDirectory(): |
| 54 return os.path.realpath( | 55 return os.path.realpath( |
| 55 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) | 56 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) |
| 56 | 57 |
| 58 |
| 57 def GetV8Directory(): | 59 def GetV8Directory(): |
| 58 return os.path.join(GetSourceDirectory(), 'v8') | 60 return os.path.join(GetSourceDirectory(), 'v8') |
| 59 | 61 |
| 62 |
| 60 # Workaround lack of the exclude parameter in add method in python-2.4. | 63 # Workaround lack of the exclude parameter in add method in python-2.4. |
| 61 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. | 64 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. |
| 62 class MyTarFile(tarfile.TarFile): | 65 class MyTarFile(tarfile.TarFile): |
| 63 def add(self, name, arcname=None, recursive=True, exclude=None): | 66 def add(self, name, arcname=None, recursive=True, exclude=None): |
| 64 head, tail = os.path.split(name) | 67 head, tail = os.path.split(name) |
| 65 if tail in ('.svn', '.git'): | 68 if tail in ('.svn', '.git'): |
| 66 return | 69 return |
| 67 | 70 |
| 68 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) | 71 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) |
| 69 | 72 |
| 73 |
| 70 def main(argv): | 74 def main(argv): |
| 71 parser = optparse.OptionParser() | 75 parser = optparse.OptionParser() |
| 72 options, args = parser.parse_args(argv) | 76 options, args = parser.parse_args(argv) |
| 73 | 77 |
| 74 if len(args) != 1: | 78 if len(args) != 1: |
| 75 print 'You must provide only one argument: output file directory' | 79 print 'You must provide only one argument: output file directory' |
| 76 return 1 | 80 return 1 |
| 77 | 81 |
| 78 v8_directory = GetV8Directory() | 82 v8_directory = GetV8Directory() |
| 79 if not os.path.exists(v8_directory): | 83 if not os.path.exists(v8_directory): |
| (...skipping 12 matching lines...) Expand all Loading... |
| 92 subprocess.check_call(["make", "dependencies"], cwd=v8_directory) | 96 subprocess.check_call(["make", "dependencies"], cwd=v8_directory) |
| 93 | 97 |
| 94 archive = MyTarFile.open(output_fullname, 'w:bz2') | 98 archive = MyTarFile.open(output_fullname, 'w:bz2') |
| 95 try: | 99 try: |
| 96 archive.add(v8_directory, arcname=output_basename) | 100 archive.add(v8_directory, arcname=output_basename) |
| 97 finally: | 101 finally: |
| 98 archive.close() | 102 archive.close() |
| 99 | 103 |
| 100 return 0 | 104 return 0 |
| 101 | 105 |
| 106 |
| 102 if __name__ == '__main__': | 107 if __name__ == '__main__': |
| 103 sys.exit(main(sys.argv[1:])) | 108 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |