summaryrefslogtreecommitdiffstats
path: root/tools/export_tarball
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 06:36:38 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 06:36:38 +0000
commit3bcea86de6bbab9ae23146b2aed08028ae800ecb (patch)
tree8acd69a9245ad9018a70b14556a98b339433c06d /tools/export_tarball
parente0e7c49e2f453c6f79974ac90e410204c4832db0 (diff)
downloadchromium_src-3bcea86de6bbab9ae23146b2aed08028ae800ecb.zip
chromium_src-3bcea86de6bbab9ae23146b2aed08028ae800ecb.tar.gz
chromium_src-3bcea86de6bbab9ae23146b2aed08028ae800ecb.tar.bz2
Make export_tarball.py more reliable and simplify it.
TEST=none BUG=none Review URL: http://codereview.chromium.org/545010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35996 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/export_tarball')
-rw-r--r--tools/export_tarball/export_tarball.py82
1 files changed, 38 insertions, 44 deletions
diff --git a/tools/export_tarball/export_tarball.py b/tools/export_tarball/export_tarball.py
index 79cc4fa..607f478 100644
--- a/tools/export_tarball/export_tarball.py
+++ b/tools/export_tarball/export_tarball.py
@@ -9,7 +9,7 @@ This tool creates a tarball with all the sources, but without .svn directories.
It can also remove files which are not strictly required for build, so that
the resulting tarball can be reasonably small (last time it was ~110 MB).
-Example usage (make sure gclient is in your PATH):
+Example usage:
export_tarball.py /foo/bar
@@ -21,20 +21,25 @@ from __future__ import with_statement
import contextlib
import optparse
import os
-import shutil
-import subprocess
import sys
import tarfile
-import tempfile
-def RunCommand(argv):
- """Runs the command with given argv and returns exit code."""
- try:
- proc = subprocess.Popen(argv, stdout=None)
- except OSError:
- return 1
- output = proc.communicate()[0]
- return proc.returncode
+NONESSENTIAL_DIRS = (
+ 'chrome/test/data',
+ 'chrome/tools/test/reference_build',
+ 'gears/binaries',
+ 'net/data/cache_tests',
+ 'o3d/documentation',
+ 'o3d/samples',
+ 'third_party/lighttpd',
+ 'third_party/WebKit/LayoutTests',
+ 'webkit/data/layout_tests',
+ 'webkit/tools/test/reference_build',
+)
+
+def GetSourceDirectory():
+ return os.path.realpath(
+ os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src'))
def main(argv):
parser = optparse.OptionParser()
@@ -49,40 +54,29 @@ def main(argv):
print '(without .tar.bz2 extension).'
return 1
+ if not os.path.exists(GetSourceDirectory()):
+ print 'Cannot find the src directory.'
+ return 1
+
output_fullname = args[0] + '.tar.bz2'
output_basename = os.path.basename(args[0])
- target_dir = tempfile.mkdtemp()
-
- try:
- if RunCommand(['gclient', 'export', target_dir]) != 0:
- print 'gclient failed'
- return 1
-
- if options.remove_nonessential_files:
- nonessential_dirs = (
- 'src/chrome/test/data',
- 'src/chrome/tools/test/reference_build',
- 'src/gears/binaries',
- 'src/net/data/cache_tests',
- 'src/o3d/documentation',
- 'src/o3d/samples',
- 'src/third_party/lighttpd',
- 'src/third_party/WebKit/LayoutTests',
- 'src/webkit/data/layout_tests',
- 'src/webkit/tools/test/reference_build',
- )
- for dir in nonessential_dirs:
- path = os.path.join(target_dir, dir)
- try:
- print 'removing %s...' % dir
- shutil.rmtree(path)
- except OSError, e:
- print 'error while trying to remove %s, skipping' % dir
-
- with contextlib.closing(tarfile.open(output_fullname, 'w:bz2')) as archive:
- archive.add(os.path.join(target_dir, 'src'), arcname=output_basename)
- finally:
- shutil.rmtree(target_dir)
+
+ def ShouldExcludePath(path):
+ head, tail = os.path.split(path)
+ if tail in ('.svn', '.git'):
+ return True
+
+ if not options.remove_nonessential_files:
+ return False
+ for nonessential_dir in NONESSENTIAL_DIRS:
+ if path.startswith(os.path.join(GetSourceDirectory(), nonessential_dir)):
+ return True
+
+ return False
+
+ with contextlib.closing(tarfile.open(output_fullname, 'w:bz2')) as archive:
+ archive.add(GetSourceDirectory(), arcname=output_basename,
+ exclude=ShouldExcludePath)
return 0