From 0cdcd5462bc437d6febffc79181badc7ca8dcdc4 Mon Sep 17 00:00:00 2001 From: skobes Date: Wed, 28 Oct 2015 10:13:35 -0700 Subject: Better version of make_zip.sh for archiving build output. This replaces chrome/tools/build/win/make_zip.sh, which only worked with cygwin. It now works on Linux, and on Windows without cygwin, and is more user-friendly. Usage: [Linux] chrome/tools/build/linux/make_zip out/Release [Windows] chrome\tools\build\win\make_zip out\Release Review URL: https://codereview.chromium.org/1411253009 Cr-Commit-Position: refs/heads/master@{#356572} --- chrome/tools/build/linux/make_zip | 14 ++++++++++ chrome/tools/build/make_zip.py | 51 +++++++++++++++++++++++++++++++++++++ chrome/tools/build/win/make_zip.bat | 17 +++++++++++++ chrome/tools/build/win/make_zip.sh | 41 ----------------------------- 4 files changed, 82 insertions(+), 41 deletions(-) create mode 100755 chrome/tools/build/linux/make_zip create mode 100755 chrome/tools/build/make_zip.py create mode 100755 chrome/tools/build/win/make_zip.bat delete mode 100755 chrome/tools/build/win/make_zip.sh (limited to 'chrome/tools') diff --git a/chrome/tools/build/linux/make_zip b/chrome/tools/build/linux/make_zip new file mode 100755 index 0000000..700ec22 --- /dev/null +++ b/chrome/tools/build/linux/make_zip @@ -0,0 +1,14 @@ +#!/bin/sh + +outdir=$1 +cfg=chrome/tools/build/linux/FILES.cfg +archive=$outdir/chrome-linux.zip + +if [ -z $outdir ]; then + echo 'usage: make_zip.sh builddir' + echo + echo ' builddir build output directory (e.g., out/Release)' + exit 1 +fi + +chrome/tools/build/make_zip.py $outdir $cfg $archive diff --git a/chrome/tools/build/make_zip.py b/chrome/tools/build/make_zip.py new file mode 100755 index 0000000..81e411e --- /dev/null +++ b/chrome/tools/build/make_zip.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import glob +import os +import sys +import zipfile + + +def main(args): + if len(args) != 3: + print 'usage: make_zip.py build_dir FILES.cfg output.zip' + return 1 + (build_dir, cfg_file, output_file) = args + + exec_globals = {'__builtins__': None} + execfile(cfg_file, exec_globals) + + cwd = os.getcwd() + os.chdir(build_dir) + + files = [] + for file_spec in exec_globals['FILES']: + pattern = file_spec['filename'] + for glob_match in glob.glob(pattern): + if os.path.isfile(glob_match): + files.append(glob_match) + elif os.path.isdir(glob_match): + for root, dirs, filenames in os.walk(glob_match): + for f in filenames: + files.append(os.path.join(root, f)); + + os.chdir(cwd) + if not len(files): + print 'error: no files found in %s' % build_dir + return 1 + + with zipfile.ZipFile(output_file, mode = 'w', + compression = zipfile.ZIP_DEFLATED) as output: + for f in files: + sys.stdout.write("%s\r" % f[:40].ljust(40, ' ')) + sys.stdout.flush() + output.write(os.path.join(build_dir, f), f) + + print 'wrote %s' % output_file + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/chrome/tools/build/win/make_zip.bat b/chrome/tools/build/win/make_zip.bat new file mode 100755 index 0000000..ba03288 --- /dev/null +++ b/chrome/tools/build/win/make_zip.bat @@ -0,0 +1,17 @@ +@echo off + +if "%1" == "" ( + echo usage: make_zip builddir + echo. + echo builddir build output directory ^(e.g., out\Release^) + goto :eof +) + +setlocal + +set makezip=chrome\tools\build\make_zip.py +set outdir=%1 +set cfg=chrome\tools\build\win\FILES.cfg +set archive=%outdir%\chrome-win32.zip + +python %makezip% %outdir% %cfg% %archive% diff --git a/chrome/tools/build/win/make_zip.sh b/chrome/tools/build/win/make_zip.sh deleted file mode 100755 index 3cdba32..0000000 --- a/chrome/tools/build/win/make_zip.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2009 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# A simple shell script for creating a chrome zip from an output directory. -# Pass the path to the output directory you wish to package. - -if [ $# = 0 ]; then - echo "usage: make_zip.sh path/to/release/dir [output-name]" - exit 1 -fi - -tools_dir=$(dirname "$0") -release_dir="$1" - -files=$(sed -n "s/^ *'filename': '\(.*\)',$/\1/ p" "$tools_dir/FILES.cfg") - -output=${2:-chrome-win32} -rm -fr $output $output.zip -mkdir $output - -# Get the absolute path of the output directory. We need it when copying -# files. -output_abs=`cygpath -a $output` - -# Use cp --parents to copy full relative directory. Since we need the -# relative directory for the zip, change into the release dir. -pushd "$release_dir" -# The file names in FILES may contain whitespace, e.g. 'First Run'. -# Change IFS setting so we only split words with '\n' -IFS_Default=$IFS -IFS=$'\n' -for f in ${files[@]}; do - cp -r --parents "$f" "$output_abs" -done -IFS=$IFS_Default -popd - -zip -r $output.zip $output -- cgit v1.1