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
]
35 _NONESSENTIAL_DIRS
= (
40 def GetV8Version(v8_directory
):
42 Returns version number as string based on the string
43 contents of version.cc file.
45 with
open(os
.path
.join(v8_directory
, 'src', 'version.cc')) as version_file
:
46 version_contents
= version_file
.read()
48 version_components
= []
49 for pattern
in _V8_PATTERNS
:
50 version_components
.append(pattern
.search(version_contents
).group(1).strip())
52 if version_components
[len(version_components
) - 1] == '0':
53 version_components
.pop()
55 return '.'.join(version_components
)
58 def GetSourceDirectory():
59 return os
.path
.realpath(
60 os
.path
.join(os
.path
.dirname(__file__
), '..', '..', '..', 'src'))
64 return os
.path
.join(GetSourceDirectory(), 'v8')
67 # Workaround lack of the exclude parameter in add method in python-2.4.
68 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot.
69 class MyTarFile(tarfile
.TarFile
):
70 def set_remove_nonessential_files(self
, remove
):
71 self
.__remove
_nonessential
_files
= remove
73 def add(self
, name
, arcname
=None, recursive
=True, exclude
=None, filter=None):
74 head
, tail
= os
.path
.split(name
)
75 if tail
in ('.svn', '.git'):
78 if self
.__remove
_nonessential
_files
:
79 # Remove contents of non-essential directories, but preserve gyp files,
80 # so that build/gyp_chromium can work.
81 for nonessential_dir
in _NONESSENTIAL_DIRS
:
82 dir_path
= os
.path
.join(GetV8Directory(), nonessential_dir
)
83 if (name
.startswith(dir_path
) and
84 os
.path
.isfile(name
) and
88 tarfile
.TarFile
.add(self
, name
, arcname
=arcname
, recursive
=recursive
)
92 parser
= optparse
.OptionParser()
93 options
, args
= parser
.parse_args(argv
)
96 print 'You must provide only one argument: output file directory'
99 v8_directory
= GetV8Directory()
100 if not os
.path
.exists(v8_directory
):
101 print 'Cannot find the v8 directory.'
104 v8_version
= GetV8Version(v8_directory
)
105 print 'Packaging V8 version %s...' % v8_version
107 subprocess
.check_call(["make", "dependencies"], cwd
=v8_directory
)
109 output_basename
= 'v8-%s' % v8_version
111 # Package full tarball.
112 output_fullname
= os
.path
.join(args
[0], output_basename
+ '.tar.bz2')
113 if not os
.path
.exists(output_fullname
):
114 archive
= MyTarFile
.open(output_fullname
, 'w:bz2')
115 archive
.set_remove_nonessential_files(False)
117 archive
.add(v8_directory
, arcname
=output_basename
)
121 # Package lite tarball.
122 output_fullname
= os
.path
.join(args
[0], output_basename
+ '-lite.tar.bz2')
123 if not os
.path
.exists(output_fullname
):
124 archive
= MyTarFile
.open(output_fullname
, 'w:bz2')
125 archive
.set_remove_nonessential_files(True)
127 archive
.add(v8_directory
, arcname
=output_basename
)
134 if __name__
== '__main__':
135 sys
.exit(main(sys
.argv
[1:]))