|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import os |
| 4 | +import re |
| 5 | +import glob |
| 6 | +import shutil |
| 7 | +import datetime |
| 8 | +import sys |
| 9 | +import getopt |
| 10 | +import pipes |
| 11 | +import subprocess |
| 12 | + |
| 13 | +SOURCE_DIR = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '/..') |
| 14 | +BUILD_SCRIPT = SOURCE_DIR + '/build-script.py' |
| 15 | +GYB_GEN_SOURCE_DIR = SOURCE_DIR + '/Sources/SwiftSyntax/gyb_generated/' |
| 16 | + |
| 17 | +def escapeCmdArg(arg): |
| 18 | + if '"' in arg or ' ' in arg: |
| 19 | + return '"%s"' % arg.replace('"', '\\"') |
| 20 | + else: |
| 21 | + return arg |
| 22 | + |
| 23 | +# Git Utils |
| 24 | +def git(git_command, cwd): |
| 25 | + '''Run a git command.''' |
| 26 | + command = ['git'] + git_command |
| 27 | + check_call(command, cwd=cwd, verbose=True) |
| 28 | + |
| 29 | +def git_tag(tag,src_path): |
| 30 | + '''Tag git repo''' |
| 31 | + git(['tag','-a',tag,'-m','Tag build ' + tag],src_path) |
| 32 | + |
| 33 | +def git_push_tag(tag,src_path): |
| 34 | + '''Push git tag''' |
| 35 | + git(['push', 'origin', tag], src_path) |
| 36 | + |
| 37 | +def git_clone(repo_url,src_path): |
| 38 | + '''Push git tag''' |
| 39 | + git(['clone', repo_url], src_path) |
| 40 | + |
| 41 | +def check_call(cmd, cwd=None, env=os.environ, verbose=False): |
| 42 | + if verbose: |
| 43 | + print(' '.join([escapeCmdArg(arg) for arg in cmd])) |
| 44 | + return subprocess.check_call(cmd, cwd=cwd, env=env, stderr=subprocess.STDOUT) |
| 45 | + |
| 46 | +def degyb(): |
| 47 | + check_call([BUILD_SCRIPT, '--degyb-only']) |
| 48 | + |
| 49 | +def main(argv): |
| 50 | + # Generate gyb files |
| 51 | + degyb() |
| 52 | + # Force commit gyb files |
| 53 | + git(git_command=['add', '-f', GYB_GEN_SOURCE_DIR + '/*.swift'], cwd=SOURCE_DIR) |
| 54 | + git(git_command=['commit', '-m', 'Auto-commit: add degybed files'], cwd=SOURCE_DIR) |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + main(sys.argv[1:]) |
0 commit comments