blob: ac366db8e841cbee44c76df5527bde39994e040a [file] [log] [blame]
[email protected]cb155a82011-11-29 17:25:341#!/usr/bin/env python
[email protected]31a46df2012-05-31 09:25:472# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]757c4922009-07-23 15:34:413# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""
7This tool creates a tarball with all the sources, but without .svn directories.
8
9It can also remove files which are not strictly required for build, so that
10the resulting tarball can be reasonably small (last time it was ~110 MB).
11
[email protected]3bcea862010-01-12 06:36:3812Example usage:
[email protected]757c4922009-07-23 15:34:4113
14export_tarball.py /foo/bar
15
16The above will create file /foo/bar.tar.bz2.
17"""
18
[email protected]757c4922009-07-23 15:34:4119import optparse
20import os
[email protected]d83bcc932011-05-25 08:49:2421import subprocess
[email protected]757c4922009-07-23 15:34:4122import sys
23import tarfile
[email protected]757c4922009-07-23 15:34:4124
[email protected]cb155a82011-11-29 17:25:3425
[email protected]3bcea862010-01-12 06:36:3826NONESSENTIAL_DIRS = (
[email protected]27cc2d42010-06-10 16:02:1527 'chrome/common/extensions/docs',
[email protected]3bcea862010-01-12 06:36:3828 'chrome/test/data',
29 'chrome/tools/test/reference_build',
[email protected]27cc2d42010-06-10 16:02:1530 'courgette/testdata',
[email protected]1f68ee622010-05-04 17:52:1331 'data',
[email protected]1f68ee622010-05-04 17:52:1332 'native_client/src/trusted/service_runtime/testdata',
[email protected]91b9a1f2010-04-14 08:55:2033 'src/chrome/test/data',
[email protected]3bcea862010-01-12 06:36:3834 'o3d/documentation',
35 'o3d/samples',
[email protected]27cc2d42010-06-10 16:02:1536 'o3d/tests',
[email protected]9aed18f2010-06-17 13:46:2037 'third_party/angle/samples/gles2_book',
[email protected]3bde4722010-06-10 04:08:5438 'third_party/hunspell_dictionaries',
[email protected]9aed18f2010-06-17 13:46:2039 'third_party/hunspell/tests',
[email protected]3bcea862010-01-12 06:36:3840 'third_party/lighttpd',
[email protected]9aed18f2010-06-17 13:46:2041 'third_party/sqlite/test',
[email protected]1f68ee622010-05-04 17:52:1342 'third_party/vc_80',
[email protected]9aed18f2010-06-17 13:46:2043 'third_party/xdg-utils/tests',
44 'third_party/yasm/source/patched-yasm/modules/arch/x86/tests',
45 'third_party/yasm/source/patched-yasm/modules/dbgfmts/dwarf2/tests',
46 'third_party/yasm/source/patched-yasm/modules/objfmts/bin/tests',
47 'third_party/yasm/source/patched-yasm/modules/objfmts/coff/tests',
48 'third_party/yasm/source/patched-yasm/modules/objfmts/elf/tests',
49 'third_party/yasm/source/patched-yasm/modules/objfmts/macho/tests',
50 'third_party/yasm/source/patched-yasm/modules/objfmts/rdf/tests',
51 'third_party/yasm/source/patched-yasm/modules/objfmts/win32/tests',
52 'third_party/yasm/source/patched-yasm/modules/objfmts/win64/tests',
53 'third_party/yasm/source/patched-yasm/modules/objfmts/xdf/tests',
[email protected]96e1fbe2011-04-09 23:23:3254 'third_party/WebKit/Source/JavaScriptCore/tests',
[email protected]3bcea862010-01-12 06:36:3855 'third_party/WebKit/LayoutTests',
[email protected]27cc2d42010-06-10 16:02:1556 'v8/test',
[email protected]3bcea862010-01-12 06:36:3857 'webkit/data/layout_tests',
58 'webkit/tools/test/reference_build',
59)
60
[email protected]cb155a82011-11-29 17:25:3461
[email protected]3bcea862010-01-12 06:36:3862def GetSourceDirectory():
63 return os.path.realpath(
64 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src'))
[email protected]757c4922009-07-23 15:34:4165
[email protected]cb155a82011-11-29 17:25:3466
[email protected]457b3372010-02-11 11:10:0067# 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.
69class MyTarFile(tarfile.TarFile):
[email protected]f3aea71ac2010-02-17 18:13:1570 def set_remove_nonessential_files(self, remove):
71 self.__remove_nonessential_files = remove
72
[email protected]457b3372010-02-11 11:10:0073 def add(self, name, arcname=None, recursive=True, exclude=None):
[email protected]f3aea71ac2010-02-17 18:13:1574 head, tail = os.path.split(name)
75 if tail in ('.svn', '.git'):
[email protected]457b3372010-02-11 11:10:0076 return
[email protected]f3aea71ac2010-02-17 18:13:1577
78 if self.__remove_nonessential_files:
79 for nonessential_dir in NONESSENTIAL_DIRS:
80 dir_path = os.path.join(GetSourceDirectory(), nonessential_dir)
81 if name.startswith(dir_path):
82 return
83
[email protected]457b3372010-02-11 11:10:0084 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive)
85
[email protected]cb155a82011-11-29 17:25:3486
[email protected]757c4922009-07-23 15:34:4187def main(argv):
88 parser = optparse.OptionParser()
89 parser.add_option("--remove-nonessential-files",
90 dest="remove_nonessential_files",
91 action="store_true", default=False)
92
93 options, args = parser.parse_args(argv)
94
95 if len(args) != 1:
96 print 'You must provide only one argument: output file name'
97 print '(without .tar.bz2 extension).'
98 return 1
99
[email protected]3bcea862010-01-12 06:36:38100 if not os.path.exists(GetSourceDirectory()):
101 print 'Cannot find the src directory.'
102 return 1
103
[email protected]31a46df2012-05-31 09:25:47104 # This command is from src/DEPS; please keep them in sync.
105 if subprocess.call(['python', 'build/util/lastchange.py', '-o',
106 'build/util/LASTCHANGE'], cwd=GetSourceDirectory()) != 0:
107 print 'Could not run build/util/lastchange.py to update LASTCHANGE.'
108 return 1
109
[email protected]757c4922009-07-23 15:34:41110 output_fullname = args[0] + '.tar.bz2'
111 output_basename = os.path.basename(args[0])
[email protected]757c4922009-07-23 15:34:41112
[email protected]457b3372010-02-11 11:10:00113 archive = MyTarFile.open(output_fullname, 'w:bz2')
[email protected]f3aea71ac2010-02-17 18:13:15114 archive.set_remove_nonessential_files(options.remove_nonessential_files)
[email protected]fc162502010-02-06 09:46:57115 try:
[email protected]f3aea71ac2010-02-17 18:13:15116 archive.add(GetSourceDirectory(), arcname=output_basename)
[email protected]fc162502010-02-06 09:46:57117 finally:
118 archive.close()
[email protected]757c4922009-07-23 15:34:41119
120 return 0
121
[email protected]cb155a82011-11-29 17:25:34122
[email protected]757c4922009-07-23 15:34:41123if __name__ == "__main__":
124 sys.exit(main(sys.argv[1:]))