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.
7 This tool creates a tarball with all the sources, but without .svn directories.
9 It can also remove files which are not strictly required for build, so that
10 the resulting tarball can be reasonably small (last time it was ~110 MB).
14 export_tarball.py /foo/bar
16 The above will create file /foo/bar.tar.bz2.
27 'chrome/common/extensions/docs',
29 'chrome/tools/test/reference_build',
32 'native_client/src/trusted/service_runtime/testdata',
33 'src/chrome/test/data',
37 'third_party/angle/samples/gles2_book',
38 'third_party/hunspell_dictionaries',
39 'third_party/hunspell/tests',
40 'third_party/lighttpd',
41 'third_party/sqlite/test',
43 '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',
54 'third_party/WebKit/Source/JavaScriptCore/tests',
55 'third_party/WebKit/LayoutTests',
57 'webkit/data/layout_tests',
58 'webkit/tools/test/reference_build',
62 def GetSourceDirectory():
63 return os
.path
.realpath(
64 os
.path
.join(os
.path
.dirname(__file__
), '..', '..', '..', 'src'))
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):
74 head
, tail
= os
.path
.split(name
)
75 if tail
in ('.svn', '.git'):
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
):
84 tarfile
.TarFile
.add(self
, name
, arcname
=arcname
, recursive
=recursive
)
88 parser
= optparse
.OptionParser()
89 parser
.add_option("--remove-nonessential-files",
90 dest
="remove_nonessential_files",
91 action
="store_true", default
=False)
93 options
, args
= parser
.parse_args(argv
)
96 print 'You must provide only one argument: output file name'
97 print '(without .tar.bz2 extension).'
100 if not os
.path
.exists(GetSourceDirectory()):
101 print 'Cannot find the src directory.'
104 output_fullname
= args
[0] + '.tar.bz2'
105 output_basename
= os
.path
.basename(args
[0])
107 archive
= MyTarFile
.open(output_fullname
, 'w:bz2')
108 archive
.set_remove_nonessential_files(options
.remove_nonessential_files
)
110 archive
.add(GetSourceDirectory(), arcname
=output_basename
)
117 if __name__
== "__main__":
118 sys
.exit(main(sys
.argv
[1:]))