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
4 # found in the LICENSE file.
6 """Creates a tarball with V8 sources, but without .svn directories.
8 This allows easy packaging of V8, synchronized with browser releases.
12 export_v8_tarball.py /foo/bar
14 The above will create file /foo/bar/v8-VERSION.tar.bz2 if it doesn't exist.
24 _V8_MAJOR_VERSION_PATTERN
= re
.compile(r
'#define\s+MAJOR_VERSION\s+(.*)')
25 _V8_MINOR_VERSION_PATTERN
= re
.compile(r
'#define\s+MINOR_VERSION\s+(.*)')
26 _V8_BUILD_NUMBER_PATTERN
= re
.compile(r
'#define\s+BUILD_NUMBER\s+(.*)')
27 _V8_PATCH_LEVEL_PATTERN
= re
.compile(r
'#define\s+PATCH_LEVEL\s+(.*)')
30 _V8_MAJOR_VERSION_PATTERN
,
31 _V8_MINOR_VERSION_PATTERN
,
32 _V8_BUILD_NUMBER_PATTERN
,
33 _V8_PATCH_LEVEL_PATTERN
]
36 def GetV8Version(v8_directory
):
38 Returns version number as string based on the string
39 contents of version.cc file.
41 with
open(os
.path
.join(v8_directory
, 'src', 'version.cc')) as version_file
:
42 version_contents
= version_file
.read()
44 version_components
= []
45 for pattern
in _V8_PATTERNS
:
46 version_components
.append(pattern
.search(version_contents
).group(1).strip())
48 if version_components
[len(version_components
) - 1] == '0':
49 version_components
.pop()
51 return '.'.join(version_components
)
54 def GetSourceDirectory():
55 return os
.path
.realpath(
56 os
.path
.join(os
.path
.dirname(__file__
), '..', '..', '..', 'src'))
60 return os
.path
.join(GetSourceDirectory(), 'v8')
63 # Workaround lack of the exclude parameter in add method in python-2.4.
64 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot.
65 class MyTarFile(tarfile
.TarFile
):
66 def add(self
, name
, arcname
=None, recursive
=True, exclude
=None):
67 head
, tail
= os
.path
.split(name
)
68 if tail
in ('.svn', '.git'):
71 tarfile
.TarFile
.add(self
, name
, arcname
=arcname
, recursive
=recursive
)
75 parser
= optparse
.OptionParser()
76 options
, args
= parser
.parse_args(argv
)
79 print 'You must provide only one argument: output file directory'
82 v8_directory
= GetV8Directory()
83 if not os
.path
.exists(v8_directory
):
84 print 'Cannot find the v8 directory.'
87 v8_version
= GetV8Version(v8_directory
)
88 print 'Packaging V8 version %s...' % v8_version
89 output_basename
= 'v8-%s' % v8_version
90 output_fullname
= os
.path
.join(args
[0], output_basename
+ '.tar.bz2')
92 if os
.path
.exists(output_fullname
):
93 print 'Already packaged, exiting.'
96 subprocess
.check_call(["make", "dependencies"], cwd
=v8_directory
)
98 archive
= MyTarFile
.open(output_fullname
, 'w:bz2')
100 archive
.add(v8_directory
, arcname
=output_basename
)
107 if __name__
== '__main__':
108 sys
.exit(main(sys
.argv
[1:]))