[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 1 | #!/usr/bin/env python |
[email protected] | 31a46df | 2012-05-31 09:25:47 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """ |
| 7 | This tool creates a tarball with all the sources, but without .svn directories. |
| 8 | |
| 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). |
| 11 | |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 12 | Example usage: |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 13 | |
| 14 | export_tarball.py /foo/bar |
| 15 | |
| 16 | The above will create file /foo/bar.tar.bz2. |
| 17 | """ |
| 18 | |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 19 | import optparse |
| 20 | import os |
[email protected] | d83bcc93 | 2011-05-25 08:49:24 | [diff] [blame] | 21 | import subprocess |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 22 | import sys |
| 23 | import tarfile |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 24 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 25 | |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 26 | NONESSENTIAL_DIRS = ( |
[email protected] | 27cc2d4 | 2010-06-10 16:02:15 | [diff] [blame] | 27 | 'chrome/common/extensions/docs', |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 28 | 'chrome/test/data', |
| 29 | 'chrome/tools/test/reference_build', |
[email protected] | 27cc2d4 | 2010-06-10 16:02:15 | [diff] [blame] | 30 | 'courgette/testdata', |
[email protected] | 1f68ee62 | 2010-05-04 17:52:13 | [diff] [blame] | 31 | 'data', |
[email protected] | 1f68ee62 | 2010-05-04 17:52:13 | [diff] [blame] | 32 | 'native_client/src/trusted/service_runtime/testdata', |
[email protected] | 91b9a1f | 2010-04-14 08:55:20 | [diff] [blame] | 33 | 'src/chrome/test/data', |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 34 | 'o3d/documentation', |
| 35 | 'o3d/samples', |
[email protected] | 27cc2d4 | 2010-06-10 16:02:15 | [diff] [blame] | 36 | 'o3d/tests', |
[email protected] | 9aed18f | 2010-06-17 13:46:20 | [diff] [blame] | 37 | 'third_party/angle/samples/gles2_book', |
[email protected] | 3bde472 | 2010-06-10 04:08:54 | [diff] [blame] | 38 | 'third_party/hunspell_dictionaries', |
[email protected] | 9aed18f | 2010-06-17 13:46:20 | [diff] [blame] | 39 | 'third_party/hunspell/tests', |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 40 | 'third_party/lighttpd', |
[email protected] | 9aed18f | 2010-06-17 13:46:20 | [diff] [blame] | 41 | 'third_party/sqlite/test', |
[email protected] | 1f68ee62 | 2010-05-04 17:52:13 | [diff] [blame] | 42 | 'third_party/vc_80', |
[email protected] | 9aed18f | 2010-06-17 13:46:20 | [diff] [blame] | 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', |
[email protected] | 96e1fbe | 2011-04-09 23:23:32 | [diff] [blame] | 54 | 'third_party/WebKit/Source/JavaScriptCore/tests', |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 55 | 'third_party/WebKit/LayoutTests', |
[email protected] | 27cc2d4 | 2010-06-10 16:02:15 | [diff] [blame] | 56 | 'v8/test', |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 57 | 'webkit/data/layout_tests', |
| 58 | 'webkit/tools/test/reference_build', |
| 59 | ) |
| 60 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 61 | |
[email protected] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 62 | def GetSourceDirectory(): |
| 63 | return os.path.realpath( |
| 64 | os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 65 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 66 | |
[email protected] | 457b337 | 2010-02-11 11:10:00 | [diff] [blame] | 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): |
[email protected] | f3aea71ac | 2010-02-17 18:13:15 | [diff] [blame] | 70 | def set_remove_nonessential_files(self, remove): |
| 71 | self.__remove_nonessential_files = remove |
| 72 | |
[email protected] | 457b337 | 2010-02-11 11:10:00 | [diff] [blame] | 73 | def add(self, name, arcname=None, recursive=True, exclude=None): |
[email protected] | f3aea71ac | 2010-02-17 18:13:15 | [diff] [blame] | 74 | head, tail = os.path.split(name) |
| 75 | if tail in ('.svn', '.git'): |
[email protected] | 457b337 | 2010-02-11 11:10:00 | [diff] [blame] | 76 | return |
[email protected] | f3aea71ac | 2010-02-17 18:13:15 | [diff] [blame] | 77 | |
| 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] | 457b337 | 2010-02-11 11:10:00 | [diff] [blame] | 84 | tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) |
| 85 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 86 | |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 87 | def 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] | 3bcea86 | 2010-01-12 06:36:38 | [diff] [blame] | 100 | if not os.path.exists(GetSourceDirectory()): |
| 101 | print 'Cannot find the src directory.' |
| 102 | return 1 |
| 103 | |
[email protected] | 31a46df | 2012-05-31 09:25:47 | [diff] [blame] | 104 | # 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] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 110 | output_fullname = args[0] + '.tar.bz2' |
| 111 | output_basename = os.path.basename(args[0]) |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 112 | |
[email protected] | 457b337 | 2010-02-11 11:10:00 | [diff] [blame] | 113 | archive = MyTarFile.open(output_fullname, 'w:bz2') |
[email protected] | f3aea71ac | 2010-02-17 18:13:15 | [diff] [blame] | 114 | archive.set_remove_nonessential_files(options.remove_nonessential_files) |
[email protected] | fc16250 | 2010-02-06 09:46:57 | [diff] [blame] | 115 | try: |
[email protected] | f3aea71ac | 2010-02-17 18:13:15 | [diff] [blame] | 116 | archive.add(GetSourceDirectory(), arcname=output_basename) |
[email protected] | fc16250 | 2010-02-06 09:46:57 | [diff] [blame] | 117 | finally: |
| 118 | archive.close() |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 119 | |
| 120 | return 0 |
| 121 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 122 | |
[email protected] | 757c492 | 2009-07-23 15:34:41 | [diff] [blame] | 123 | if __name__ == "__main__": |
| 124 | sys.exit(main(sys.argv[1:])) |