Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 This tool creates a tarball with all the sources, but without .svn directories. | 7 This tool creates a tarball with all the sources, but without .svn directories. |
| 8 | 8 |
| 9 It can also remove files which are not strictly required for build, so that | 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). | 10 the resulting tarball can be reasonably small (last time it was ~110 MB). |
| 11 | 11 |
| 12 Example usage: | 12 Example usage: |
| 13 | 13 |
| 14 export_tarball.py /foo/bar | 14 export_tarball.py /foo/bar |
| 15 | 15 |
| 16 The above will create file /foo/bar.tar.bz2. | 16 The above will create file /foo/bar.tar.bz2. |
| 17 """ | 17 """ |
| 18 | 18 |
| 19 import optparse | 19 import optparse |
| 20 import os | 20 import os |
| 21 import subprocess | 21 import subprocess |
| 22 import sys | 22 import sys |
| 23 import tarfile | 23 import tarfile |
| 24 | 24 |
| 25 | 25 |
| 26 NONESSENTIAL_DIRS = ( | 26 NONESSENTIAL_DIRS = ( |
| 27 'breakpad/src/processor/testdata', | 27 'breakpad/src/processor/testdata', |
| 28 'chrome/browser/resources/tracing/tests', | 28 'chrome/browser/resources/tracing/tests', |
| 29 'chrome/common/extensions/docs', | 29 'chrome/common/extensions/docs', |
| 30 'chrome/test/data', | |
| 31 'chrome/tools/test/reference_build', | 30 'chrome/tools/test/reference_build', |
| 32 'content/test/data', | |
| 33 'courgette/testdata', | 31 'courgette/testdata', |
| 34 'data', | 32 'data', |
| 35 'media/test/data', | |
| 36 'native_client/src/trusted/service_runtime/testdata', | 33 'native_client/src/trusted/service_runtime/testdata', |
| 37 'net/data', | |
| 38 'src/chrome/test/data', | 34 'src/chrome/test/data', |
| 39 'o3d/documentation', | 35 'o3d/documentation', |
| 40 'o3d/samples', | 36 'o3d/samples', |
| 41 'o3d/tests', | 37 'o3d/tests', |
| 42 'ppapi/examples', | 38 'ppapi/examples', |
| 43 'ppapi/native_client/tests', | 39 'ppapi/native_client/tests', |
| 44 'third_party/angle/samples/gles2_book', | 40 'third_party/angle/samples/gles2_book', |
| 45 'third_party/findbugs', | 41 'third_party/findbugs', |
| 46 'third_party/hunspell_dictionaries', | 42 'third_party/hunspell_dictionaries', |
| 47 'third_party/hunspell/tests', | 43 'third_party/hunspell/tests', |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 64 'third_party/WebKit/Source/JavaScriptCore/tests', | 60 'third_party/WebKit/Source/JavaScriptCore/tests', |
| 65 'third_party/WebKit/Source/WebCore/ChangeLog', | 61 'third_party/WebKit/Source/WebCore/ChangeLog', |
| 66 'third_party/WebKit/Source/WebKit2', | 62 'third_party/WebKit/Source/WebKit2', |
| 67 'third_party/WebKit/Tools/Scripts', | 63 'third_party/WebKit/Tools/Scripts', |
| 68 'tools/gyp/test', | 64 'tools/gyp/test', |
| 69 'v8/test', | 65 'v8/test', |
| 70 'webkit/data/layout_tests', | 66 'webkit/data/layout_tests', |
| 71 'webkit/tools/test/reference_build', | 67 'webkit/tools/test/reference_build', |
| 72 ) | 68 ) |
| 73 | 69 |
| 70 TESTDIRS = ( | |
| 71 'chrome/test/data', | |
| 72 'content/test/data', | |
| 73 'media/test/data', | |
| 74 'net/data', | |
| 75 ) | |
| 76 | |
| 74 | 77 |
| 75 def GetSourceDirectory(): | 78 def GetSourceDirectory(): |
| 76 return os.path.realpath( | 79 return os.path.realpath( |
| 77 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) | 80 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) |
| 78 | 81 |
| 79 | 82 |
| 80 # Workaround lack of the exclude parameter in add method in python-2.4. | 83 # Workaround lack of the exclude parameter in add method in python-2.4. |
| 81 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. | 84 # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. |
| 82 class MyTarFile(tarfile.TarFile): | 85 class MyTarFile(tarfile.TarFile): |
| 83 def set_remove_nonessential_files(self, remove): | 86 def set_remove_nonessential_files(self, remove): |
| 84 self.__remove_nonessential_files = remove | 87 self.__remove_nonessential_files = remove |
| 85 | 88 |
| 86 def add(self, name, arcname=None, recursive=True, exclude=None, filter=None): | 89 def add(self, name, arcname=None, recursive=True, exclude=None, filter=None): |
| 87 head, tail = os.path.split(name) | 90 head, tail = os.path.split(name) |
| 88 if tail in ('.svn', '.git'): | 91 if tail in ('.svn', '.git'): |
| 89 return | 92 return |
| 90 | 93 |
| 91 if self.__remove_nonessential_files: | 94 if self.__remove_nonessential_files: |
| 92 # WebKit change logs take quite a lot of space. This saves ~10 MB | 95 # WebKit change logs take quite a lot of space. This saves ~10 MB |
| 93 # in a bzip2-compressed tarball. | 96 # in a bzip2-compressed tarball. |
| 94 if 'ChangeLog' in name: | 97 if 'ChangeLog' in name: |
| 95 return | 98 return |
| 96 | 99 |
| 97 # Remove contents of non-essential directories, but preserve gyp files, | 100 # Remove contents of non-essential directories, but preserve gyp files, |
| 98 # so that build/gyp_chromium can work. | 101 # so that build/gyp_chromium can work. |
| 99 for nonessential_dir in NONESSENTIAL_DIRS: | 102 for nonessential_dir in (NONESSENTIAL_DIRS + TESTDIRS): |
| 100 dir_path = os.path.join(GetSourceDirectory(), nonessential_dir) | 103 dir_path = os.path.join(GetSourceDirectory(), nonessential_dir) |
| 101 if (name.startswith(dir_path) and | 104 if (name.startswith(dir_path) and |
| 102 os.path.isfile(name) and | 105 os.path.isfile(name) and |
| 103 'gyp' not in name): | 106 'gyp' not in name): |
| 104 return | 107 return |
| 105 | 108 |
| 106 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) | 109 tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) |
| 107 | 110 |
| 108 | 111 |
| 109 def main(argv): | 112 def main(argv): |
| 110 parser = optparse.OptionParser() | 113 parser = optparse.OptionParser() |
| 114 parser.add_option("--basename") | |
| 111 parser.add_option("--remove-nonessential-files", | 115 parser.add_option("--remove-nonessential-files", |
| 112 dest="remove_nonessential_files", | 116 dest="remove_nonessential_files", |
| 113 action="store_true", default=False) | 117 action="store_true", default=False) |
| 118 parser.add_option("--test-data", action="store_true") | |
| 114 parser.add_option("--xz", action="store_true") | 119 parser.add_option("--xz", action="store_true") |
| 115 | 120 |
| 116 options, args = parser.parse_args(argv) | 121 options, args = parser.parse_args(argv) |
| 117 | 122 |
| 118 if len(args) != 1: | 123 if len(args) != 1: |
| 119 print 'You must provide only one argument: output file name' | 124 print 'You must provide only one argument: output file name' |
| 120 print '(without .tar.bz2 extension).' | 125 print '(without .tar.bz2 extension).' |
| 121 return 1 | 126 return 1 |
| 122 | 127 |
| 123 if not os.path.exists(GetSourceDirectory()): | 128 if not os.path.exists(GetSourceDirectory()): |
| 124 print 'Cannot find the src directory.' | 129 print 'Cannot find the src directory ' + GetSourceDirectory() |
| 125 return 1 | 130 return 1 |
| 126 | 131 |
| 127 # This command is from src/DEPS; please keep them in sync. | 132 # This command is from src/DEPS; please keep them in sync. |
| 128 if subprocess.call(['python', 'build/util/lastchange.py', '-o', | 133 if subprocess.call(['python', 'build/util/lastchange.py', '-o', |
| 129 'build/util/LASTCHANGE'], cwd=GetSourceDirectory()) != 0: | 134 'build/util/LASTCHANGE'], cwd=GetSourceDirectory()) != 0: |
| 130 print 'Could not run build/util/lastchange.py to update LASTCHANGE.' | 135 print 'Could not run build/util/lastchange.py to update LASTCHANGE.' |
| 131 return 1 | 136 return 1 |
| 132 | 137 |
| 133 if options.xz: | 138 if options.xz: |
| 134 output_fullname = args[0] + '.tar' | 139 output_fullname = args[0] + '.tar' |
| 135 else: | 140 else: |
| 136 output_fullname = args[0] + '.tar.bz2' | 141 output_fullname = args[0] + '.tar.bz2' |
| 137 | 142 |
| 138 output_basename = os.path.basename(args[0]) | 143 if options.basename: |
|
M-A Ruel
2013/03/08 02:10:54
output_basename = options.basename or os.path.base
Paweł Hajdan Jr.
2013/03/08 18:00:38
Done.
| |
| 144 output_basename = options.basename | |
| 145 else: | |
| 146 output_basename = os.path.basename(args[0]) | |
| 139 | 147 |
| 140 if options.xz: | 148 if options.xz: |
| 141 archive = MyTarFile.open(output_fullname, 'w') | 149 archive = MyTarFile.open(output_fullname, 'w') |
| 142 else: | 150 else: |
| 143 archive = MyTarFile.open(output_fullname, 'w:bz2') | 151 archive = MyTarFile.open(output_fullname, 'w:bz2') |
| 144 archive.set_remove_nonessential_files(options.remove_nonessential_files) | 152 archive.set_remove_nonessential_files(options.remove_nonessential_files) |
| 145 try: | 153 try: |
| 146 archive.add(GetSourceDirectory(), arcname=output_basename) | 154 if (options.test_data): |
|
M-A Ruel
2013/03/08 02:10:54
if options.test_data:
Paweł Hajdan Jr.
2013/03/08 18:00:38
Done. Heh, too much C++.
| |
| 155 for directory in TESTDIRS: | |
| 156 archive.add(os.path.join(GetSourceDirectory(), directory), | |
| 157 arcname=os.path.join(output_basename, directory)) | |
| 158 else: | |
| 159 archive.add(GetSourceDirectory(), arcname=output_basename) | |
| 147 finally: | 160 finally: |
| 148 archive.close() | 161 archive.close() |
| 149 | 162 |
| 150 if options.xz: | 163 if options.xz: |
| 151 if subprocess.call(['xz', '-9', output_fullname]) != 0: | 164 if subprocess.call(['xz', '-9', output_fullname]) != 0: |
| 152 print 'xz -9 failed!' | 165 print 'xz -9 failed!' |
| 153 return 1 | 166 return 1 |
| 154 | 167 |
| 155 return 0 | 168 return 0 |
| 156 | 169 |
| 157 | 170 |
| 158 if __name__ == "__main__": | 171 if __name__ == "__main__": |
| 159 sys.exit(main(sys.argv[1:])) | 172 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |