Skip to content

Commit

Permalink
Make export_tarball.py more reliable and simplify it.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
phajdan.jr@chromium.org committed Jan 12, 2010
1 parent e0e7c49 commit 3bcea86
Showing 1 changed file with 38 additions and 44 deletions.
82 changes: 38 additions & 44 deletions tools/export_tarball/export_tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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
Expand All @@ -21,20 +21,25 @@
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()
Expand All @@ -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

Expand Down

0 comments on commit 3bcea86

Please sign in to comment.