From 9b66f357e3faccbc31e4f97b6e904f3195121d3e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 19 Jun 2013 14:32:41 +0800 Subject: [PATCH 01/18] Rewrite bootstrap script in python. --- script/bootstrap | 72 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/script/bootstrap b/script/bootstrap index 5af504d5c8b..88dd111848b 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -1,30 +1,60 @@ -#!/bin/sh -#/ Usage: bootstrap https://base.url.com/from/libchromiumcontent/script/upload -#/ Bootstrap this project. +#!/usr/bin/env python -set -e +import argparse +import errno +import os +import subprocess +import sys -usage() { - grep '^#/' <"$0"| cut -c4- -} -BASE_URL="${1}" +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor') +BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent' -if [ -z "${BASE_URL}" ]; then - BASE_URL="https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent" -fi -cd "$(dirname "$0")/.." -SOURCE_ROOT=$(pwd -P) -VENDOR_DIR="${SOURCE_ROOT}/vendor" -BRIGHTRAY_DIR="${VENDOR_DIR}/brightray" +def main(): + os.chdir(SOURCE_ROOT) -git submodule sync --quiet -git submodule update --init --recursive + args = parse_args() + update_submodules() + update_npm() + bootstrap_brightray(args.url) + update_atom_shell() -npm install npm --silent -./node_modules/.bin/npm install --silent -"${BRIGHTRAY_DIR}/script/bootstrap" "${BASE_URL}" +def parse_args(): + parser = argparse.ArgumentParser(description='Bootstrap this project') + parser.add_argument('--url', + help='The base URL from which to download ' + 'libchromiumcontent (i.e., the URL you passed to ' + 'libchromiumcontent\'s script/upload script', + default=BASE_URL, + required=False) + return parser.parse_args() -"${SOURCE_ROOT}/script/update" + +def update_submodules(): + subprocess.check_call(['git', 'submodule', 'sync', '--quiet']) + subprocess.check_call(['git', 'submodule', 'update', '--init', + '--recursive']) + + +def update_npm(): + subprocess.check_call(['npm', 'install', 'npm', '--silent']) + + npm = os.path.join(SOURCE_ROOT, 'node_modules', '.bin', 'npm') + subprocess.check_call([npm, 'install', '--silent']) + + +def bootstrap_brightray(url): + bootstrap = os.path.join(VENDOR_DIR, 'brightray', 'script', 'bootstrap') + subprocess.check_call([sys.executable, bootstrap, url]) + + +def update_atom_shell(): + update = os.path.join(SOURCE_ROOT, 'script', 'update') + subprocess.check_call([update]) + + +if __name__ == '__main__': + sys.exit(main()) From 467b2b154ff76839e9b5db4394c31c8e65c887f5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 19 Jun 2013 15:41:41 +0800 Subject: [PATCH 02/18] Add script to find existing Mac SDK (taken from chromium). --- script/find_sdk.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 script/find_sdk.py diff --git a/script/find_sdk.py b/script/find_sdk.py new file mode 100755 index 00000000000..067be638d21 --- /dev/null +++ b/script/find_sdk.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# Copyright (c) 2012 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 os +import re +import subprocess +import sys + +"""Prints the lowest locally available SDK version greater than or equal to a +given minimum sdk version to standard output. + +Usage: + python find_sdk.py 10.6 # Ignores SDKs < 10.6 +""" + +from optparse import OptionParser + + +def parse_version(version_str): + """'10.6' => [10, 6]""" + return map(int, re.findall(r'(\d+)', version_str)) + + +def main(): + parser = OptionParser() + parser.add_option("--verify", + action="store_true", dest="verify", default=False, + help="return the sdk argument and warn if it doesn't exist") + parser.add_option("--sdk_path", + action="store", type="string", dest="sdk_path", default="", + help="user-specified SDK path; bypasses verification") + (options, args) = parser.parse_args() + min_sdk_version = args[0] + + job = subprocess.Popen(['xcode-select', '-print-path'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + out, err = job.communicate() + if job.returncode != 0: + print >>sys.stderr, out + print >>sys.stderr, err + raise Exception(('Error %d running xcode-select, you might have to run ' + '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' + 'if you are using Xcode 4.') % job.returncode) + # The Developer folder moved in Xcode 4.3. + xcode43_sdk_path = os.path.join( + out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') + if os.path.isdir(xcode43_sdk_path): + sdk_dir = xcode43_sdk_path + else: + sdk_dir = os.path.join(out.rstrip(), 'SDKs') + sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] + sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] + sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] + if parse_version(s) >= parse_version(min_sdk_version)] + if not sdks: + raise Exception('No %s+ SDK found' % min_sdk_version) + best_sdk = sorted(sdks, key=parse_version)[0] + + if options.verify and best_sdk != min_sdk_version and not options.sdk_path: + print >>sys.stderr, '' + print >>sys.stderr, ' vvvvvvv' + print >>sys.stderr, '' + print >>sys.stderr, \ + 'This build requires the %s SDK, but it was not found on your system.' \ + % min_sdk_version + print >>sys.stderr, \ + 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' + print >>sys.stderr, '' + print >>sys.stderr, ' ^^^^^^^' + print >>sys.stderr, '' + return min_sdk_version + + return best_sdk + + +if __name__ == '__main__': + if sys.platform != 'darwin': + raise Exception("This script only runs on Mac") + print main() From 6d187cbb7d28b4768151732148e9012682e9e4fe Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 19 Jun 2013 21:31:57 +0800 Subject: [PATCH 03/18] Build atom-shell with ninja. --- .gitignore | 1 + atom.gyp | 26 +++++++++++-------- browser/mac/Info.plist | 2 ++ common.gypi | 42 +++++++++++++++++++++++++++++++ renderer/mac/Info.plist | 2 ++ script/update | 3 ++- {script => tools/mac}/find_sdk.py | 0 tools/mac/source_root.py | 10 ++++++++ 8 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 common.gypi rename {script => tools/mac}/find_sdk.py (100%) create mode 100755 tools/mac/source_root.py diff --git a/.gitignore b/.gitignore index 7eb2ff83c72..c09e8c02929 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ dist/ frameworks/ node/ node_modules/ +out/ vendor/ *.xcodeproj *.swp diff --git a/atom.gyp b/atom.gyp index 82e2affb491..a926cae6f5b 100644 --- a/atom.gyp +++ b/atom.gyp @@ -144,11 +144,10 @@ '${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}' ], }, - 'includes': [ - 'vendor/brightray/brightray.gypi' - ], 'target_defaults': { - 'mac_framework_dirs': [ 'frameworks' ], + 'mac_framework_dirs': [ + '<(source_root)/frameworks', + ], }, 'targets': [ { @@ -180,7 +179,9 @@ ], 'xcode_settings': { 'INFOPLIST_FILE': 'browser/mac/Info.plist', - 'LD_RUNPATH_SEARCH_PATHS': '@executable_path/../Frameworks', + 'LD_RUNPATH_SEARCH_PATHS': [ + '@executable_path/../Frameworks', + ], }, 'copies': [ { @@ -305,11 +306,12 @@ '<(libchromiumcontent_resources_dir)/content_shell.pak', ], 'xcode_settings': { - 'LIBRARY_SEARCH_PATHS': '<(libchromiumcontent_library_dir)', + 'LIBRARY_SEARCH_PATHS': [ + '<(libchromiumcontent_library_dir)', + ], 'LD_DYLIB_INSTALL_NAME': '@rpath/<(product_name).framework/<(product_name)', - 'LD_RUNPATH_SEARCH_PATHS': '@loader_path/Libraries', - 'OTHER_LDFLAGS': [ - '-ObjC', + 'LD_RUNPATH_SEARCH_PATHS': [ + '@loader_path/Libraries', ], }, 'copies': [ @@ -346,7 +348,9 @@ 'mac_bundle': 1, 'xcode_settings': { 'INFOPLIST_FILE': 'renderer/mac/Info.plist', - 'LD_RUNPATH_SEARCH_PATHS': '@executable_path/../../..', + 'LD_RUNPATH_SEARCH_PATHS': [ + '@executable_path/../../..', + ], }, 'postbuilds': [ { @@ -358,6 +362,6 @@ ], }, # target helper ], - }], + }], # OS==Mac ], } diff --git a/browser/mac/Info.plist b/browser/mac/Info.plist index 971fd379af0..7ad4ab7f4b5 100644 --- a/browser/mac/Info.plist +++ b/browser/mac/Info.plist @@ -6,6 +6,8 @@ com.github.atom CFBundleName ${PRODUCT_NAME} + CFBundlePackageType + APPL CFBundleIconFile atom.icns CFBundleVersion diff --git a/common.gypi b/common.gypi new file mode 100644 index 00000000000..9dd0ead9c6f --- /dev/null +++ b/common.gypi @@ -0,0 +1,42 @@ +{ + 'variables': { + 'clang': 0, + 'source_root': 'com.github.atom.helper CFBundleName ${PRODUCT_NAME} + CFBundlePackageType + APPL LSUIElement diff --git a/script/update b/script/update index 444b2896118..b10bfe2377d 100755 --- a/script/update +++ b/script/update @@ -7,7 +7,8 @@ cd "$(dirname "$0")/.." ./script/update-frameworks ./script/update-node v0.10.9 -gyp --depth . atom.gyp \ +gyp -f ninja --depth . atom.gyp \ + -Icommon.gypi \ -Ivendor/brightray/brightray.gypi \ -Dtarget_arch=ia32 \ -Dlibrary=static_library diff --git a/script/find_sdk.py b/tools/mac/find_sdk.py similarity index 100% rename from script/find_sdk.py rename to tools/mac/find_sdk.py diff --git a/tools/mac/source_root.py b/tools/mac/source_root.py new file mode 100755 index 00000000000..73ac5eb0c49 --- /dev/null +++ b/tools/mac/source_root.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import os + +"""Prints the absolute path of the root of atom-shell's source tree. +""" + + +relative_source_root = os.path.join(__file__, '..', '..', '..') +print os.path.abspath(relative_source_root) From e3803bc4995488789df2e6e947931f5374f532f2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 19 Jun 2013 22:54:40 +0800 Subject: [PATCH 04/18] Update brightray: fix linking with libchromiumcontent. --- vendor/brightray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/brightray b/vendor/brightray index 1143359bed7..6d893b1f500 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 1143359bed70f5c2d4f6fc998a1d8cedb7ecff87 +Subproject commit 6d893b1f5001c94d1ace0bc3d976f6e83a922e81 From 07260731ca9c9771acfd16ab36924610fd72c16a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Jun 2013 22:49:11 +0800 Subject: [PATCH 05/18] Rewrite update-node script in python. --- script/{bootstrap => bootstrap.py} | 0 script/update-node | 145 ++++++++++++++++++++++++----- 2 files changed, 122 insertions(+), 23 deletions(-) rename script/{bootstrap => bootstrap.py} (100%) diff --git a/script/bootstrap b/script/bootstrap.py similarity index 100% rename from script/bootstrap rename to script/bootstrap.py diff --git a/script/update-node b/script/update-node index 54edd321ce8..c406cfaff2e 100755 --- a/script/update-node +++ b/script/update-node @@ -1,31 +1,130 @@ -#!/bin/bash +#!/usr/bin/env python -set -e +import argparse +import atexit +import errno +import shutil +import subprocess +import sys +import tarfile +import tempfile +import os +import urllib2 -cd "$(dirname $0)/.." -NODE_VERSION=v0.10.5 -[ -z $1 ] || NODE_VERSION=$1 +SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) +NODE_VERSION = 'v0.10.9' +NODE_DIST_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/node/dist' +IS_POSIX = (sys.platform != 'win32') and (sys.platform != 'cygwin') -# Test whether we need update. -if [ -f "node/node" ] && [[ `node/node --version` == $NODE_VERSION ]] ; then - exit 0 -fi -case $OSTYPE in - darwin*) NODE_PLATFORM=darwin ;; - linux*) NODE_PLATFORM=linux ;; - *) echo "Unsupported platform $OSTYPE" && exit 1 ;; -esac +def main(): + os.chdir(SOURCE_ROOT) -NODE_DIST_NAME="node-$NODE_VERSION-$NODE_PLATFORM-x86" + args = parse_args() + if not node_needs_update(args.version): + return 0 -# Download node and untar -NODE_TARBALL_URL="https://gh-contractor-zcbenz.s3.amazonaws.com/node/dist/$NODE_DIST_NAME.tar.gz" -TARGET_DIR='node' -[ -d "$TARGET_DIR" ] || mkdir "$TARGET_DIR" -cd "$TARGET_DIR" -curl -fsSkL $NODE_TARBALL_URL | tar -zx || exit 1 + url, filename = get_node_url(args.url, args.version) + directory = download('Download node', url, filename) -cp "$NODE_DIST_NAME/bin/node" . -rm -rf "$NODE_DIST_NAME" + if IS_POSIX: + root_name = 'node-{0}-{1}-x86'.format(args.version, sys.platform) + member = os.path.join(root_name, 'bin', 'node') + extract_tarball(os.path.join(directory, filename), member, directory) + node_path = os.path.join(directory, member) + + copy_node(node_path) + + +def parse_args(): + parser = argparse.ArgumentParser(description='Update node binary') + parser.add_argument('--version', + help='Version of node', + default=NODE_VERSION, + required=False) + parser.add_argument('--url', + help='URL to download node', + default=NODE_DIST_URL, + required=False) + return parser.parse_args() + + +def node_needs_update(target_version): + try: + node = os.path.join('node', 'node') + if not IS_POSIX: + node += '.exe' + version = subprocess.check_output([node, '--version']) + return version.strip() != target_version + except OSError as e: + if e.errno != errno.ENOENT: + raise + return True + + +def get_node_url(base_url, target_version): + if IS_POSIX: + distname = 'node-{0}-{1}-x86.tar.gz'.format(target_version, sys.platform) + else: + distname = 'node-{0}.exe'.format(target_version) + return '{0}/{1}'.format(base_url, distname), distname + + +def copy_node(node_path): + safe_mkdir('node') + node = os.path.join('node', 'node') + safe_unlink(node) + os.rename(node_path, node) + + +def download(text, url, filename): + directory = tempfile.mkdtemp(prefix='atom-shell-') + atexit.register(shutil.rmtree, directory) + + web_file = urllib2.urlopen(url) + file_size = int(web_file.info().getheaders("Content-Length")[0]) + downloaded_size = 0 + block_size = 128 + + with open(os.path.join(directory, filename), 'w+') as local_file: + while True: + buf = web_file.read(block_size) + if not buf: + break + + downloaded_size += len(buf) + local_file.write(buf) + + percent = downloaded_size * 100. / file_size + status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent) + print status, + + print + + return directory + + +def extract_tarball(tarball_path, member, path): + with tarfile.open(tarball_path) as tarball: + tarball.extract(member, path) + + +def safe_unlink(path): + try: + os.unlink(path) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + +def safe_mkdir(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +if __name__ == '__main__': + sys.exit(main()) From 9983e7c0ba8330c69cd24e9fd0c4b1c8ad416493 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Jun 2013 22:51:58 +0800 Subject: [PATCH 06/18] Move helper functions into a common module. --- .gitignore | 1 + script/lib/__init__.py | 0 script/lib/util.py | 53 ++++++++++++++++++++++++++++++++++++++++ script/update-node | 55 ++---------------------------------------- 4 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 script/lib/__init__.py create mode 100644 script/lib/util.py diff --git a/.gitignore b/.gitignore index c09e8c02929..062b94e24e5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ out/ vendor/ *.xcodeproj *.swp +*.pyc diff --git a/script/lib/__init__.py b/script/lib/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/script/lib/util.py b/script/lib/util.py new file mode 100644 index 00000000000..b71e5838be8 --- /dev/null +++ b/script/lib/util.py @@ -0,0 +1,53 @@ +import atexit +import shutil +import tarfile +import tempfile +import urllib2 + + +def download(text, url, filename): + directory = tempfile.mkdtemp(prefix='atom-shell-') + atexit.register(shutil.rmtree, directory) + + web_file = urllib2.urlopen(url) + file_size = int(web_file.info().getheaders("Content-Length")[0]) + downloaded_size = 0 + block_size = 128 + + with open(os.path.join(directory, filename), 'w+') as local_file: + while True: + buf = web_file.read(block_size) + if not buf: + break + + downloaded_size += len(buf) + local_file.write(buf) + + percent = downloaded_size * 100. / file_size + status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent) + print status, + + print + + return directory + + +def extract_tarball(tarball_path, member, path): + with tarfile.open(tarball_path) as tarball: + tarball.extract(member, path) + + +def safe_unlink(path): + try: + os.unlink(path) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + +def safe_mkdir(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise diff --git a/script/update-node b/script/update-node index c406cfaff2e..bfa2aa07492 100755 --- a/script/update-node +++ b/script/update-node @@ -1,15 +1,12 @@ #!/usr/bin/env python import argparse -import atexit import errno -import shutil import subprocess import sys -import tarfile -import tempfile import os -import urllib2 + +from lib.util import * SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) @@ -78,53 +75,5 @@ def copy_node(node_path): os.rename(node_path, node) -def download(text, url, filename): - directory = tempfile.mkdtemp(prefix='atom-shell-') - atexit.register(shutil.rmtree, directory) - - web_file = urllib2.urlopen(url) - file_size = int(web_file.info().getheaders("Content-Length")[0]) - downloaded_size = 0 - block_size = 128 - - with open(os.path.join(directory, filename), 'w+') as local_file: - while True: - buf = web_file.read(block_size) - if not buf: - break - - downloaded_size += len(buf) - local_file.write(buf) - - percent = downloaded_size * 100. / file_size - status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent) - print status, - - print - - return directory - - -def extract_tarball(tarball_path, member, path): - with tarfile.open(tarball_path) as tarball: - tarball.extract(member, path) - - -def safe_unlink(path): - try: - os.unlink(path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - - -def safe_mkdir(path): - try: - os.makedirs(path) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - if __name__ == '__main__': sys.exit(main()) From 993c7ad6505ec53c044643d6c2d538bbc99ae0b7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Jun 2013 22:55:54 +0800 Subject: [PATCH 07/18] Use .py suffix for python scripts, we're following chromium. --- script/update | 2 +- script/{update-node => update-node.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename script/{update-node => update-node.py} (100%) diff --git a/script/update b/script/update index b10bfe2377d..c441f4463ae 100755 --- a/script/update +++ b/script/update @@ -5,7 +5,7 @@ set -e cd "$(dirname "$0")/.." ./script/update-frameworks -./script/update-node v0.10.9 +./script/update-node.py --version v0.10.9 gyp -f ninja --depth . atom.gyp \ -Icommon.gypi \ diff --git a/script/update-node b/script/update-node.py similarity index 100% rename from script/update-node rename to script/update-node.py From 9bcb67701288339cf5b50c4cdbc12fdf893b2417 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Jun 2013 23:10:00 +0800 Subject: [PATCH 08/18] Simplify download function. --- script/lib/util.py | 23 ++++++++++++++--------- script/update-node.py | 6 ++++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/script/lib/util.py b/script/lib/util.py index b71e5838be8..51ca69dc378 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -1,20 +1,27 @@ +#!/usr/bin/env python + import atexit +import errno import shutil import tarfile import tempfile import urllib2 +import os -def download(text, url, filename): - directory = tempfile.mkdtemp(prefix='atom-shell-') +def tempdir(prefix=''): + directory = tempfile.mkdtemp(prefix=prefix) atexit.register(shutil.rmtree, directory) + return directory - web_file = urllib2.urlopen(url) - file_size = int(web_file.info().getheaders("Content-Length")[0]) - downloaded_size = 0 - block_size = 128 - with open(os.path.join(directory, filename), 'w+') as local_file: +def download(text, url, path): + with open(path, 'w') as local_file: + web_file = urllib2.urlopen(url) + file_size = int(web_file.info().getheaders("Content-Length")[0]) + downloaded_size = 0 + block_size = 128 + while True: buf = web_file.read(block_size) if not buf: @@ -29,8 +36,6 @@ def download(text, url, filename): print - return directory - def extract_tarball(tarball_path, member, path): with tarfile.open(tarball_path) as tarball: diff --git a/script/update-node.py b/script/update-node.py index bfa2aa07492..caadb3c8ff8 100755 --- a/script/update-node.py +++ b/script/update-node.py @@ -23,12 +23,14 @@ def main(): return 0 url, filename = get_node_url(args.url, args.version) - directory = download('Download node', url, filename) + directory = tempdir(prefix='atom-shell-') + path = os.path.join(directory, filename) + download('Download node', url, path) if IS_POSIX: root_name = 'node-{0}-{1}-x86'.format(args.version, sys.platform) member = os.path.join(root_name, 'bin', 'node') - extract_tarball(os.path.join(directory, filename), member, directory) + extract_tarball(path, member, directory) node_path = os.path.join(directory, member) copy_node(node_path) From 2f50102b50aad95ae7b07f90c009dde94fc2ee51 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Jun 2013 23:23:22 +0800 Subject: [PATCH 09/18] Rewrite update-frameworks script in python. --- script/lib/util.py | 10 +++++++-- script/update | 2 +- script/update-frameworks | 23 --------------------- script/update-frameworks.py | 41 +++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 26 deletions(-) delete mode 100755 script/update-frameworks create mode 100755 script/update-frameworks.py diff --git a/script/lib/util.py b/script/lib/util.py index 51ca69dc378..f4f42be926c 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -7,6 +7,7 @@ import tarfile import tempfile import urllib2 import os +import zipfile def tempdir(prefix=''): @@ -37,9 +38,14 @@ def download(text, url, path): print -def extract_tarball(tarball_path, member, path): +def extract_tarball(tarball_path, member, destination): with tarfile.open(tarball_path) as tarball: - tarball.extract(member, path) + tarball.extract(member, destination) + + +def extract_zip(zip_path, destination): + with zipfile.ZipFile(zip_path) as z: + z.extractall(destination) def safe_unlink(path): diff --git a/script/update b/script/update index c441f4463ae..89ddc0673f6 100755 --- a/script/update +++ b/script/update @@ -4,7 +4,7 @@ set -e cd "$(dirname "$0")/.." -./script/update-frameworks +./script/update-frameworks.py ./script/update-node.py --version v0.10.9 gyp -f ninja --depth . atom.gyp \ diff --git a/script/update-frameworks b/script/update-frameworks deleted file mode 100755 index 38656af8e99..00000000000 --- a/script/update-frameworks +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -cd "$(dirname $0)/.." - -. script/lib/polite-curl - -[ -d frameworks ] || mkdir frameworks -cd frameworks - -FRAMEWORKS_URL='https://gh-contractor-zcbenz.s3.amazonaws.com/frameworks' - -trap 'rm -f *.zip' EXIT - -function download_and_unzip() { - if ! [ -d $1.framework ]; then - echo "Downloading $1..." - polite_curl "$FRAMEWORKS_URL/$1.framework.zip" > $1.framework.zip - unzip $1.framework.zip - fi -} - -download_and_unzip Quincy -download_and_unzip Sparkle diff --git a/script/update-frameworks.py b/script/update-frameworks.py new file mode 100755 index 00000000000..55f2fc95571 --- /dev/null +++ b/script/update-frameworks.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import sys +import os + +from lib.util import * + + +SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) +FRAMEWORKS_URL='https://gh-contractor-zcbenz.s3.amazonaws.com/frameworks' + + +def main(): + os.chdir(SOURCE_ROOT) + safe_mkdir('frameworks') + download_and_unzip('Quincy') + download_and_unzip('Sparkle') + + +def download_and_unzip(framework): + zip_path = download_framework(framework) + if zip_path: + extract_zip(zip_path, 'frameworks') + + +def download_framework(framework): + framework_path = os.path.join('frameworks', framework) + '.framework' + if os.path.exists(framework_path): + return + + filename = framework + '.framework.zip' + url = FRAMEWORKS_URL + '/' + filename + download_dir = tempdir(prefix='atom-shell-') + path = os.path.join(download_dir, filename) + + download('Download ' + framework, url, path) + return path + + +if __name__ == '__main__': + sys.exit(main()) From 1eb521d32a842dc2a7421043419bf95d9e9aae81 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 21 Jun 2013 10:32:57 +0800 Subject: [PATCH 10/18] Use unzip command on Mac to keep symbol links in zip file work. --- script/lib/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/script/lib/util.py b/script/lib/util.py index f4f42be926c..ab331870654 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -3,6 +3,8 @@ import atexit import errno import shutil +import subprocess +import sys import tarfile import tempfile import urllib2 @@ -44,8 +46,12 @@ def extract_tarball(tarball_path, member, destination): def extract_zip(zip_path, destination): - with zipfile.ZipFile(zip_path) as z: - z.extractall(destination) + if sys.platform == 'darwin': + # Use unzip command on Mac to keep symbol links in zip file work. + subprocess.check_call(['unzip', zip_path, '-d', destination]) + else: + with zipfile.ZipFile(zip_path) as z: + z.extractall(destination) def safe_unlink(path): From 3cc304cbe5e5d24387a7e462144271504cb04cc1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 15:24:30 +0800 Subject: [PATCH 11/18] Rewrite update script in python. --- script/bootstrap.py | 4 ++-- script/update | 14 -------------- script/update.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 16 deletions(-) delete mode 100755 script/update create mode 100755 script/update.py diff --git a/script/bootstrap.py b/script/bootstrap.py index 88dd111848b..73a5492bd36 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -52,8 +52,8 @@ def bootstrap_brightray(url): def update_atom_shell(): - update = os.path.join(SOURCE_ROOT, 'script', 'update') - subprocess.check_call([update]) + update = os.path.join(SOURCE_ROOT, 'script', 'update.py') + subprocess.check_call([sys.executable, update]) if __name__ == '__main__': diff --git a/script/update b/script/update deleted file mode 100755 index 23f306e5ded..00000000000 --- a/script/update +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -e - -cd "$(dirname "$0")/.." - -./script/update-frameworks.py -./script/update-node.py --version v0.10.12 - -gyp -f ninja --depth . atom.gyp \ - -Icommon.gypi \ - -Ivendor/brightray/brightray.gypi \ - -Dtarget_arch=ia32 \ - -Dlibrary=static_library diff --git a/script/update.py b/script/update.py new file mode 100755 index 00000000000..790c58adcf6 --- /dev/null +++ b/script/update.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import subprocess +import sys + +from lib.util import * + + +SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) +NODE_VERSION = 'v0.10.12' + + +def main(): + os.chdir(SOURCE_ROOT) + + update_frameworks_and_node(NODE_VERSION) + update_gyp() + + +def update_frameworks_and_node(version): + uf = os.path.join(SOURCE_ROOT, 'script', 'update-frameworks.py') + un = os.path.join(SOURCE_ROOT, 'script', 'update-node.py') + subprocess.check_call([sys.executable, uf]) + subprocess.check_call([sys.executable, un, '--version', version]) + + +def update_gyp(): + subprocess.check_call(['gyp', '-f', 'ninja', '--depth', '.', 'atom.gyp', + '-Icommon.gypi', '-Ivendor/brightray/brightray.gypi', + '-Dtarget_arch=ia32', '-Dlibrary=static_library']) + + +if __name__ == '__main__': + sys.exit(main()) From 5c4c86c6ef5d288c1162356e6f0d94c9b85a1127 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 15:36:38 +0800 Subject: [PATCH 12/18] Rewrite build script in python. --- script/build | 12 ------------ script/build.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) delete mode 100755 script/build create mode 100755 script/build.py diff --git a/script/build b/script/build deleted file mode 100755 index 06a34af1a18..00000000000 --- a/script/build +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -set -e - -MODE=Release -if [ ! -z $1 ]; then - MODE=$1 -fi - -cd "$(dirname "$0")/.." - -xcodebuild -configuration ${MODE} -target atom diff --git a/script/build.py b/script/build.py new file mode 100755 index 00000000000..2f9974a8305 --- /dev/null +++ b/script/build.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import argparse +import os +import subprocess +import sys + + +CONFIGURATIONS = ['Release', 'Debug'] + + +def main(): + args = parse_args() + for config in args.configuration: + build_path = os.path.join('out', config) + subprocess.check_call(['ninja', '-C', build_path]) + + +def parse_args(): + parser = argparse.ArgumentParser(description='Build atom-shell') + parser.add_argument('-c', '--configuration', + help='Build with Release or Debug configuration', + nargs='+', + default=CONFIGURATIONS, + required=False) + return parser.parse_args() + + +if __name__ == '__main__': + sys.exit(main()) From 85d7e7b0343a5610f6c5c84cb27aad8d0a7b6180 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 16:05:22 +0800 Subject: [PATCH 13/18] Don't throw exception when ninja quit unnormally. --- script/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/build.py b/script/build.py index 2f9974a8305..2403401fd3a 100755 --- a/script/build.py +++ b/script/build.py @@ -13,7 +13,7 @@ def main(): args = parse_args() for config in args.configuration: build_path = os.path.join('out', config) - subprocess.check_call(['ninja', '-C', build_path]) + subprocess.call(['ninja', '-C', build_path]) def parse_args(): From 5c48f03dfead0826cfa0ef6bf1e2d72c52715603 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 16:24:19 +0800 Subject: [PATCH 14/18] Rewrite compile-coffee script in python. --- atom.gyp | 6 +++--- script/compile-coffee | 21 --------------------- script/compile-coffee.py | 23 +++++++++++++++++++++++ script/lib/util.py | 7 +++++++ 4 files changed, 33 insertions(+), 24 deletions(-) delete mode 100755 script/compile-coffee create mode 100755 script/compile-coffee.py diff --git a/atom.gyp b/atom.gyp index 6205810b268..9430bb740f2 100644 --- a/atom.gyp +++ b/atom.gyp @@ -264,14 +264,14 @@ 'rule_name': 'coffee', 'extension': 'coffee', 'inputs': [ - 'script/compile-coffee', + 'script/compile-coffee.py', ], 'outputs': [ '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js', ], 'action': [ - 'sh', - 'script/compile-coffee', + 'python', + 'script/compile-coffee.py', '<(RULE_INPUT_PATH)', '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js', ], diff --git a/script/compile-coffee b/script/compile-coffee deleted file mode 100755 index 2c15358c9d7..00000000000 --- a/script/compile-coffee +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -set -e - -# Because of the way xcodebuild invokes external scripts we need to load -# The Setup's environment ourselves. If this isn't done, things like the -# node shim won't be able to find the stuff they need. - -node --version > /dev/null 2>&1 || { - if [ -e /opt/github/env.sh ]; then - source /opt/github/env.sh - else - # Try Constructicon's PATH. - export PATH="/usr/local/Cellar/node/0.8.21/bin:${PATH}" - fi -} - -INPUT_FILE="${1}" -OUTPUT_DIR=`dirname "$2"` - -node_modules/.bin/coffee -c -o "$OUTPUT_DIR" "$INPUT_FILE" diff --git a/script/compile-coffee.py b/script/compile-coffee.py new file mode 100755 index 00000000000..35642c90e54 --- /dev/null +++ b/script/compile-coffee.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import os +import subprocess +import sys + +from lib.util import * + + +SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) + + +def main(): + input_file = sys.argv[1] + output_dir = os.path.dirname(sys.argv[2]) + + node = get_node_path() + coffee = os.path.join(SOURCE_ROOT, 'node_modules', '.bin', 'coffee') + subprocess.check_call([node, coffee, '-c', '-o', output_dir, input_file]) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/script/lib/util.py b/script/lib/util.py index ab331870654..7060f1ac1d1 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -68,3 +68,10 @@ def safe_mkdir(path): except OSError as e: if e.errno != errno.EEXIST: raise + + +def get_node_path(): + node = os.path.join(os.path.dirname(__file__), '..', '..', 'node', 'node') + if sys.platform == 'win32' or sys.platform == 'cygwin': + node += '.exe' + return node From cce712549be1025b9ef202e2f12007561b04aad5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 17:03:48 +0800 Subject: [PATCH 15/18] Rewrite cpplint script in python. --- script/cpplint | 26 -------------------------- script/cpplint.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 26 deletions(-) delete mode 100755 script/cpplint create mode 100755 script/cpplint.py diff --git a/script/cpplint b/script/cpplint deleted file mode 100755 index ba9ba9e3183..00000000000 --- a/script/cpplint +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -cd "`dirname $0`/.." - -# List all Objective-C headers here, should not cpplint them. -OBJC_HEADERS=' -browser/atom_event_processing_window.h -browser/atom_application_mac.h -browser/atom_application_delegate_mac.h -browser/native_window_mac.h -browser/nsalert_synchronous_sheet.h -common/api/api_messages.cc -common/api/api_messages.h' - -FILES=`find app browser common renderer -type f -name '*.h' -or -name '*.cc'` -FILTERED_FILES= - -while read file; do - if ! echo "$OBJC_HEADERS" | grep "$file" > /dev/null ; then - FILTERED_FILES="$FILTERED_FILES $file" - fi -done <<< "$FILES" - -python ./vendor/cpplint.py \ - --filter=-build/header_guard,-build/include_what_you_use \ - $FILTERED_FILES diff --git a/script/cpplint.py b/script/cpplint.py new file mode 100755 index 00000000000..9ebf5e64f9d --- /dev/null +++ b/script/cpplint.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import fnmatch +import os +import subprocess +import sys + +OBJC_HEADERS = [ + 'browser/atom_event_processing_window.h', + 'browser/atom_application_mac.h', + 'browser/atom_application_delegate_mac.h', + 'browser/native_window_mac.h', + 'browser/nsalert_synchronous_sheet.h', + 'common/api/api_messages.cc', + 'common/api/api_messages.h', +] + +SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) + + +def main(): + os.chdir(SOURCE_ROOT) + files = list_files(['app', 'browser', 'common', 'renderer'], + ['*.cc', '*.h']) + call_cpplint(list(set(files) - set(OBJC_HEADERS))) + + +def list_files(directories, filters): + matches = [] + for directory in directories: + for root, dirs, filenames, in os.walk(directory): + for f in filters: + for filename in fnmatch.filter(filenames, f): + matches.append(os.path.join(root, filename)) + return matches + + +def call_cpplint(files): + cpplint = os.path.join(SOURCE_ROOT, 'vendor', 'cpplint.py') + rules = '--filter=-build/header_guard,-build/include_what_you_use' + subprocess.call([sys.executable, cpplint, rules] + files) + + +if __name__ == '__main__': + sys.exit(main()) From 5845740844a727411778147ee5b31ef8d0583ee5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 17:51:48 +0800 Subject: [PATCH 16/18] Update create-dist script for changes of building system. --- script/create-dist | 56 ------------------------------------------- script/create-dist.py | 43 +++++++++++++++++++++++++++++++++ script/lib/util.py | 8 +++++++ 3 files changed, 51 insertions(+), 56 deletions(-) delete mode 100755 script/create-dist create mode 100755 script/create-dist.py diff --git a/script/create-dist b/script/create-dist deleted file mode 100755 index 975833aff36..00000000000 --- a/script/create-dist +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python - -import errno -import os -import shutil -import subprocess - - -SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -DIST_DIR = os.path.join(SOURCE_ROOT, 'dist') -BUNDLE_NAME = 'Atom.app' -BUNDLE_DIR = os.path.join(SOURCE_ROOT, 'build', 'Release', BUNDLE_NAME) - - -def main(): - rm_rf(DIST_DIR) - os.makedirs(DIST_DIR) - - copy_binaries() - create_zip() - - -def copy_binaries(): - shutil.copytree(BUNDLE_DIR, os.path.join(DIST_DIR, BUNDLE_NAME), symlinks=True) - - -def create_zip(): - print "Zipping distribution..." - zip_file = os.path.join(SOURCE_ROOT, 'atom-shell.zip') - safe_unlink(zip_file) - - cwd = os.getcwd() - os.chdir(DIST_DIR) - subprocess.check_call(['zip', '-r', '-y', zip_file, 'Atom.app']) - os.chdir(cwd) - - -def rm_rf(path): - try: - shutil.rmtree(path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - - -def safe_unlink(path): - try: - os.unlink(path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - - -if __name__ == '__main__': - import sys - sys.exit(main()) diff --git a/script/create-dist.py b/script/create-dist.py new file mode 100755 index 00000000000..af9f47ea449 --- /dev/null +++ b/script/create-dist.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import errno +import os +import shutil +import subprocess +import sys + +from lib.util import * + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +DIST_DIR = os.path.join(SOURCE_ROOT, 'dist') +BUNDLE_NAME = 'Atom.app' +BUNDLE_DIR = os.path.join(SOURCE_ROOT, 'out', 'Release', BUNDLE_NAME) + + +def main(): + rm_rf(DIST_DIR) + os.makedirs(DIST_DIR) + + copy_binaries() + create_zip() + + +def copy_binaries(): + shutil.copytree(BUNDLE_DIR, os.path.join(DIST_DIR, BUNDLE_NAME), + symlinks=True) + + +def create_zip(): + print "Zipping distribution..." + zip_file = os.path.join(SOURCE_ROOT, 'atom-shell.zip') + safe_unlink(zip_file) + + cwd = os.getcwd() + os.chdir(DIST_DIR) + subprocess.check_call(['zip', '-r', '-y', zip_file, 'Atom.app']) + os.chdir(cwd) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/script/lib/util.py b/script/lib/util.py index 7060f1ac1d1..acbaca30288 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -54,6 +54,14 @@ def extract_zip(zip_path, destination): z.extractall(destination) +def rm_rf(path): + try: + shutil.rmtree(path) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + def safe_unlink(path): try: os.unlink(path) From b17a6c98873c088aef383779366e23a28ffac934 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 17:54:56 +0800 Subject: [PATCH 17/18] Remove the download script. --- script/download | 103 ------------------------------------------------ 1 file changed, 103 deletions(-) delete mode 100755 script/download diff --git a/script/download b/script/download deleted file mode 100755 index 8a53163d7ff..00000000000 --- a/script/download +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python - -import argparse -import contextlib -import errno -import os -import shutil -import subprocess -import sys -import tempfile -import urllib2 -import zipfile - - -SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) - - -class ProgramError(Exception): - pass - - -def main(): - try: - args = parse_args() - commit = head_commit() - download_if_needed(args.path, args.url, commit, force=args.force) - except ProgramError as e: - return e.message - - -def parse_args(): - parser = argparse.ArgumentParser(description='Download and extract ' - 'atom-shell') - parser.add_argument('-f', '--force', action='store_true', - help='Overwrite destination if it already exists.') - parser.add_argument('url', help='The base URL from which to download ' - '(i.e., the URL you passed to script/upload)') - parser.add_argument('path', help='The path to extract to') - return parser.parse_args() - - -def head_commit(): - args = [ - 'git', - '--git-dir', - os.path.join(SOURCE_ROOT, '.git'), - 'rev-parse', - 'HEAD', - ] - return subprocess.check_output(args).strip() - - -def download_if_needed(destination, base_url, commit, force): - version_file = os.path.join(destination, '.version') - existing_version = '' - try: - with open(version_file, 'r') as f: - existing_version = f.readline().strip() - except IOError as e: - if e.errno != errno.ENOENT: - raise - if existing_version == commit: - return - - if force: - rm_rf(destination) - elif os.path.exists(destination): - raise ProgramError('Error: {0} already exists. Pass --force if you ' - 'want to overwrite it.'.format(destination)) - sys.stderr.write('Downloading atom-shell {0}...\n'.format(commit)) - sys.stderr.flush() - download_and_extract(destination, '{0}/{1}/atom-shell.zip'.format(base_url, commit)) - with open(version_file, 'w') as f: - f.write('{0}\n'.format(commit)) - - -def download_and_extract(destination, url): - print url - with tempfile.TemporaryFile() as t: - with contextlib.closing(urllib2.urlopen(url)) as u: - while True: - chunk = u.read(1024*1024) - if not len(chunk): - break - sys.stderr.write('.') - sys.stderr.flush() - t.write(chunk) - sys.stderr.write('\nExtracting...\n') - sys.stderr.flush() - with zipfile.ZipFile(t) as z: - z.extractall(destination) - - -def rm_rf(path): - try: - shutil.rmtree(path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - - -if __name__ == '__main__': - sys.exit(main()) From 40ed17d8fd406dad64e019a71c3efb8b8951b3f4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Jun 2013 17:56:51 +0800 Subject: [PATCH 18/18] Modify upload script to obey chromium's style. --- script/upload | 77 ------------------------------------------------ script/upload.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 77 deletions(-) delete mode 100755 script/upload create mode 100755 script/upload.py diff --git a/script/upload b/script/upload deleted file mode 100755 index f9bb20b097a..00000000000 --- a/script/upload +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python - -import errno -import glob -import os -import subprocess -import tempfile - - -SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) - - -def main(): - try: - ensure_s3put() - upload() - except AssertionError as e: - return e.message - - -def ensure_s3put(): - output = '' - try: - output = subprocess.check_output(['s3put', '--help']) - except OSError as e: - if e.errno != errno.ENOENT: - raise - assert 'multipart' in output, 'Error: Please install boto and filechunkio' - - -def upload(): - os.chdir(SOURCE_ROOT) - bucket, access_key, secret_key = s3_config() - commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() - - s3put(bucket, access_key, secret_key, 'atom-shell/{0}'.format(commit), glob.glob('atom-shell*.zip')) - - update_version(bucket, access_key, secret_key, commit) - - -def s3_config(): - config = (os.environ.get('ATOM_SHELL_S3_BUCKET', ''), - os.environ.get('ATOM_SHELL_S3_ACCESS_KEY', ''), - os.environ.get('ATOM_SHELL_S3_SECRET_KEY', '')) - message = ('Error: Please set the $ATOM_SHELL_S3_BUCKET, ' - '$ATOM_SHELL_S3_ACCESS_KEY, and ' - '$ATOM_SHELL_S3_SECRET_KEY environment variables') - assert all(len(c) for c in config), message - return config - - -def update_version(bucket, access_key, secret_key, commit): - version_path = os.path.join(SOURCE_ROOT, 'version') - with open(version_path, 'w') as version_file: - version_file.write(commit) - - # Upload after file is closed, it's required under Windows. - s3put(bucket, access_key, secret_key, 'atom-shell', [ version_path ]) - - -def s3put(bucket, access_key, secret_key, key_prefix, files): - args = [ - 's3put', - '--bucket', bucket, - '--access_key', access_key, - '--secret_key', secret_key, - '--prefix', SOURCE_ROOT, - '--key_prefix', key_prefix, - '--grant', 'public-read' - ] + files - - subprocess.check_call(args) - - -if __name__ == '__main__': - import sys - sys.exit(main()) diff --git a/script/upload.py b/script/upload.py new file mode 100755 index 00000000000..a73f8de454d --- /dev/null +++ b/script/upload.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +import errno +import glob +import os +import subprocess +import tempfile + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + + +def main(): + try: + ensure_s3put() + upload() + except AssertionError as e: + return e.message + + +def ensure_s3put(): + output = '' + try: + output = subprocess.check_output(['s3put', '--help']) + except OSError as e: + if e.errno != errno.ENOENT: + raise + assert 'multipart' in output, 'Error: Please install boto and filechunkio' + + +def upload(): + os.chdir(SOURCE_ROOT) + bucket, access_key, secret_key = s3_config() + commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() + + s3put(bucket, access_key, secret_key, 'atom-shell/{0}'.format(commit), glob.glob('atom-shell*.zip')) + + update_version(bucket, access_key, secret_key, commit) + + +def s3_config(): + config = (os.environ.get('ATOM_SHELL_S3_BUCKET', ''), + os.environ.get('ATOM_SHELL_S3_ACCESS_KEY', ''), + os.environ.get('ATOM_SHELL_S3_SECRET_KEY', '')) + message = ('Error: Please set the $ATOM_SHELL_S3_BUCKET, ' + '$ATOM_SHELL_S3_ACCESS_KEY, and ' + '$ATOM_SHELL_S3_SECRET_KEY environment variables') + assert all(len(c) for c in config), message + return config + + +def update_version(bucket, access_key, secret_key, commit): + version_path = os.path.join(SOURCE_ROOT, 'version') + with open(version_path, 'w') as version_file: + version_file.write(commit) + + # Upload after file is closed, it's required under Windows. + s3put(bucket, access_key, secret_key, 'atom-shell', [ version_path ]) + + +def s3put(bucket, access_key, secret_key, key_prefix, files): + args = [ + 's3put', + '--bucket', bucket, + '--access_key', access_key, + '--secret_key', secret_key, + '--prefix', SOURCE_ROOT, + '--key_prefix', key_prefix, + '--grant', 'public-read' + ] + files + + subprocess.check_call(args) + + +if __name__ == '__main__': + import sys + sys.exit(main())