| #!/usr/bin/env python |
| # utils/update-checkout - Utility to update your local checkouts -*- python -*- |
| # |
| # This source file is part of the Swift.org open source project |
| # |
| # Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors |
| # Licensed under Apache License v2.0 with Runtime Library Exception |
| # |
| # See http://swift.org/LICENSE.txt for license information |
| # See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| |
| from __future__ import print_function |
| |
| import argparse |
| import os |
| import sys |
| |
| sys.path.append(os.path.dirname(__file__)) |
| |
| from SwiftBuildSupport import ( |
| SWIFT_SOURCE_ROOT, |
| WorkingDirectory, |
| check_call, |
| ) |
| |
| def update_working_copy(repo_path): |
| if not os.path.isdir(repo_path): |
| return |
| |
| print("--- Updating '" + repo_path + "' ---") |
| with WorkingDirectory(repo_path): |
| # Prior to Git 2.6, this is the way to do a "git pull |
| # --rebase" that respects rebase.autostash. See |
| # http://stackoverflow.com/a/30209750/125349 |
| check_call([ "git", "fetch" ]) |
| check_call([ "git", "rebase", "FETCH_HEAD" ]) |
| |
| def obtain_additional_swift_sources(opts = {'with_ssh': False}): |
| additional_repos = { |
| 'llvm': 'apple/swift-llvm', |
| 'clang': 'apple/swift-clang', |
| 'lldb': 'apple/swift-lldb', |
| 'cmark': 'apple/swift-cmark', |
| 'llbuild': 'apple/swift-llbuild', |
| 'swiftpm': 'apple/swift-package-manager', |
| 'swift-corelibs-xctest': 'apple/swift-corelibs-xctest', |
| 'swift-corelibs-foundation': 'apple/swift-corelibs-foundation', |
| 'swift-integration-tests': 'apple/swift-integration-tests', |
| } |
| for dir_name, repo in additional_repos.items(): |
| with WorkingDirectory(SWIFT_SOURCE_ROOT): |
| if not os.path.isdir(os.path.join(dir_name, ".git")): |
| print("--- Cloning '" + dir_name + "' ---") |
| if opts['with_ssh'] is True: |
| remote = "git@github.com:" + repo + '.git' |
| else: |
| remote = "https://github.com/" + repo + '.git' |
| check_call(['git', 'clone', remote, dir_name]) |
| |
| def main(): |
| parser = argparse.ArgumentParser( |
| formatter_class=argparse.RawDescriptionHelpFormatter, |
| description=""" |
| repositories. |
| |
| By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""") |
| parser.add_argument("-a", "--all", |
| help="also update checkouts of llbuild, LLVM, and Clang", |
| action="store_true") |
| parser.add_argument("--clone", |
| help="Obtain Sources for Swift and Related Projects", |
| action="store_true") |
| parser.add_argument("--clone-with-ssh", |
| help="Obtain Sources for Swift and Related Projects via SSH", |
| action="store_true") |
| args = parser.parse_args() |
| |
| if args.clone: |
| obtain_additional_swift_sources() |
| return 0 |
| |
| if args.clone_with_ssh: |
| obtain_additional_swift_sources({'with_ssh': True}) |
| return 0 |
| |
| if args.all: |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "llbuild")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "llvm")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "clang")) |
| |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift")) |
| update_working_copy( |
| os.path.join(SWIFT_SOURCE_ROOT, "swift", "benchmark", "PerfTestSuite")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "SourceKit")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "cmark")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "lldb")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swiftpm")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift-corelibs-foundation")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift-corelibs-xctest")) |
| update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift-integration-tests")) |
| |
| return 0 |
| |
| |
| if __name__ == "__main__": |
| sys.exit(main()) |
| |