Nathaniel Manista | ae4fbcd | 2015-09-23 16:29:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 2 | # Copyright 2015, Google Inc. |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | import argparse |
| 32 | import os |
| 33 | import os.path |
| 34 | import shutil |
| 35 | import subprocess |
| 36 | import tempfile |
| 37 | |
| 38 | parser = argparse.ArgumentParser() |
| 39 | parser.add_argument('--config', metavar='c', type=str, nargs=1, |
| 40 | help='GRPC/GPR libraries build configuration', |
| 41 | default='opt') |
| 42 | parser.add_argument('--submit', action='store_true') |
| 43 | parser.add_argument('--gh-user', type=str, help='GitHub user to push as.') |
| 44 | parser.add_argument('--gh-repo-owner', type=str, |
| 45 | help=('Owner of the GitHub repository to be pushed; ' |
| 46 | 'defaults to --gh-user.')) |
| 47 | parser.add_argument('--doc-branch', type=str) |
| 48 | args = parser.parse_args() |
| 49 | |
| 50 | SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 51 | PROJECT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..')) |
| 52 | |
| 53 | CONFIG = args.config |
Masood Malekghassemi | 3ee1f9b | 2016-02-22 18:37:18 -0800 | [diff] [blame] | 54 | SETUP_PATH = os.path.join(PROJECT_ROOT, 'setup.py') |
| 55 | REQUIREMENTS_PATH = os.path.join(PROJECT_ROOT, 'requirements.txt') |
| 56 | DOC_PATH = os.path.join(PROJECT_ROOT, 'doc/build') |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 57 | INCLUDE_PATH = os.path.join(PROJECT_ROOT, 'include') |
| 58 | LIBRARY_PATH = os.path.join(PROJECT_ROOT, 'libs/{}'.format(CONFIG)) |
| 59 | VIRTUALENV_DIR = os.path.join(SCRIPT_DIR, 'distrib_virtualenv') |
| 60 | VIRTUALENV_PYTHON_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'python') |
Masood Malekghassemi | 3ee1f9b | 2016-02-22 18:37:18 -0800 | [diff] [blame] | 61 | VIRTUALENV_PIP_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'pip') |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 62 | |
| 63 | environment = os.environ.copy() |
| 64 | environment.update({ |
| 65 | 'CONFIG': CONFIG, |
| 66 | 'CFLAGS': '-I{}'.format(INCLUDE_PATH), |
| 67 | 'LDFLAGS': '-L{}'.format(LIBRARY_PATH), |
Masood Malekghassemi | 3ee1f9b | 2016-02-22 18:37:18 -0800 | [diff] [blame] | 68 | 'LD_LIBRARY_PATH': LIBRARY_PATH, |
| 69 | 'GRPC_PYTHON_BUILD_WITH_CYTHON': '1', |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 70 | }) |
| 71 | |
| 72 | subprocess_arguments_list = [ |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 73 | {'args': ['virtualenv', VIRTUALENV_DIR], 'env': environment}, |
Masood Malekghassemi | 6f7d422 | 2016-07-20 17:16:07 -0700 | [diff] [blame] | 74 | {'args': [VIRTUALENV_PIP_PATH, 'install', '--upgrade', 'pip'], |
| 75 | 'env': environment}, |
Masood Malekghassemi | 3ee1f9b | 2016-02-22 18:37:18 -0800 | [diff] [blame] | 76 | {'args': [VIRTUALENV_PIP_PATH, 'install', '-r', REQUIREMENTS_PATH], |
| 77 | 'env': environment}, |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 78 | {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'build'], 'env': environment}, |
| 79 | {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'doc'], 'env': environment}, |
| 80 | ] |
| 81 | |
| 82 | for subprocess_arguments in subprocess_arguments_list: |
Masood Malekghassemi | 3ee1f9b | 2016-02-22 18:37:18 -0800 | [diff] [blame] | 83 | print('Running command: {}'.format(subprocess_arguments['args'])) |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 84 | subprocess.check_call(**subprocess_arguments) |
| 85 | |
| 86 | if args.submit: |
| 87 | assert args.gh_user |
| 88 | assert args.doc_branch |
| 89 | github_user = args.gh_user |
| 90 | github_repository_owner = ( |
Masood Malekghassemi | 38fc0bb | 2015-09-10 08:49:57 -0700 | [diff] [blame] | 91 | args.gh_repo_owner if args.gh_repo_owner else args.gh_user) |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 92 | # Create a temporary directory out of tree, checkout gh-pages from the |
| 93 | # specified repository, edit it, and push it. It's up to the user to then go |
| 94 | # onto GitHub and make a PR against grpc/grpc:gh-pages. |
| 95 | repo_parent_dir = tempfile.mkdtemp() |
| 96 | repo_dir = os.path.join(repo_parent_dir, 'grpc') |
| 97 | python_doc_dir = os.path.join(repo_dir, 'python') |
| 98 | doc_branch = args.doc_branch |
| 99 | |
| 100 | subprocess.check_call([ |
| 101 | 'git', 'clone', 'https://{}@github.com/{}/grpc'.format( |
| 102 | github_user, github_repository_owner) |
| 103 | ], cwd=repo_parent_dir) |
| 104 | subprocess.check_call([ |
| 105 | 'git', 'remote', 'add', 'upstream', 'https://github.com/grpc/grpc' |
| 106 | ], cwd=repo_dir) |
| 107 | subprocess.check_call(['git', 'fetch', 'upstream'], cwd=repo_dir) |
| 108 | subprocess.check_call([ |
| 109 | 'git', 'checkout', 'upstream/gh-pages', '-b', doc_branch |
| 110 | ], cwd=repo_dir) |
| 111 | shutil.rmtree(python_doc_dir, ignore_errors=True) |
| 112 | shutil.copytree(DOC_PATH, python_doc_dir) |
| 113 | subprocess.check_call(['git', 'add', '--all'], cwd=repo_dir) |
| 114 | subprocess.check_call([ |
| 115 | 'git', 'commit', '-m', 'Auto-update Python documentation' |
| 116 | ], cwd=repo_dir) |
| 117 | subprocess.check_call([ |
| 118 | 'git', 'push', '--set-upstream', 'origin', doc_branch |
| 119 | ], cwd=repo_dir) |
| 120 | shutil.rmtree(repo_parent_dir) |