def main(): freeze_support() parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=""" repositories. By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""") 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") parser.add_argument("--skip-history", help="Skip histories when obtaining sources", action="store_true") parser.add_argument("--skip-repository", metavar="DIRECTORY", default=[], help="Skip the specified repository", dest='skip_repository_list', action="append") parser.add_argument( "--scheme", help='Use branches from the specified branch-scheme. A "branch-scheme"' ' is a list of (repo, branch) pairs.', metavar='BRANCH-SCHEME', dest='scheme') parser.add_argument('--reset-to-remote', help='Reset each branch to the remote state.', action='store_true') parser.add_argument('--clean', help='Clean unrelated files from each repository.', action='store_true') parser.add_argument("--config", default=os.path.join(SCRIPT_DIR, "update-checkout-config.json"), help="Configuration file to use") parser.add_argument( "--github-comment", help="""Check out related pull requests referenced in the given free-form GitHub-style comment.""", metavar='GITHUB-COMMENT', dest='github_comment') parser.add_argument( '--dump-hashes', action='store_true', help='Dump the git hashes of all repositories being tracked') parser.add_argument( '--dump-hashes-config', help='Dump the git hashes of all repositories packaged into ' 'update-checkout-config.json', metavar='BRANCH-SCHEME-NAME') parser.add_argument( "--tag", help="""Check out each repository to the specified tag.""", metavar='TAG-NAME') parser.add_argument( "--match-timestamp", help='Check out adjacent repositories to match timestamp of ' ' current swift checkout.', action='store_true') parser.add_argument("-j", "--jobs", type=int, help="Number of threads to run at once", default=0, dest="n_processes") args = parser.parse_args() if args.reset_to_remote and not args.scheme: print("update-checkout usage error: --reset-to-remote must specify " "--scheme=foo") sys.exit(1) clone = args.clone clone_with_ssh = args.clone_with_ssh skip_history = args.skip_history scheme = args.scheme github_comment = args.github_comment with open(args.config) as f: config = json.load(f) validate_config(config) if args.dump_hashes: dump_repo_hashes(config) return (None, None) if args.dump_hashes_config: dump_hashes_config(args, config) return (None, None) cross_repos_pr = {} if github_comment: regex_pr = r'(apple/[-a-zA-Z0-9_]+/pull/\d+|apple/[-a-zA-Z0-9_]+#\d+)' repos_with_pr = re.findall(regex_pr, github_comment) print("Found related pull requests:", str(repos_with_pr)) repos_with_pr = [pr.replace('/pull/', '#') for pr in repos_with_pr] cross_repos_pr = dict(pr.split('#') for pr in repos_with_pr) clone_results = None if clone or clone_with_ssh: # If branch is None, default to using the default branch alias # specified by our configuration file. if scheme is None: scheme = config['default-branch-scheme'] skip_repo_list = args.skip_repository_list clone_results = obtain_all_additional_swift_sources( args, config, clone_with_ssh, scheme, skip_history, skip_repo_list) update_results = update_all_repositories(args, config, scheme, cross_repos_pr) fail_count = 0 fail_count += shell.check_parallel_results(clone_results, "CLONE") fail_count += shell.check_parallel_results(update_results, "UPDATE") if fail_count > 0: print("update-checkout failed, fix errors and try again") sys.exit(fail_count)
def main(): freeze_support() parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=""" repositories. By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""") 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") parser.add_argument( "--skip-history", help="Skip histories when obtaining sources", action="store_true") parser.add_argument( "--skip-repository", metavar="DIRECTORY", default=[], help="Skip the specified repository", dest='skip_repository_list', action="append") parser.add_argument( "--scheme", help='Use branches from the specified branch-scheme. A "branch-scheme"' ' is a list of (repo, branch) pairs.', metavar='BRANCH-SCHEME', dest='scheme') parser.add_argument( '--reset-to-remote', help='Reset each branch to the remote state.', action='store_true') parser.add_argument( '--clean', help='Clean unrelated files from each repository.', action='store_true') parser.add_argument( "--config", default=os.path.join(SCRIPT_DIR, "update-checkout-config.json"), help="Configuration file to use") parser.add_argument( "--github-comment", help="""Check out related pull requests referenced in the given free-form GitHub-style comment.""", metavar='GITHUB-COMMENT', dest='github_comment') parser.add_argument( '--dump-hashes', action='store_true', help='Dump the git hashes of all repositories being tracked') parser.add_argument( '--dump-hashes-config', help='Dump the git hashes of all repositories packaged into ' 'update-checkout-config.json', metavar='BRANCH-SCHEME-NAME') parser.add_argument( "--tag", help="""Check out each repository to the specified tag.""", metavar='TAG-NAME') parser.add_argument( "--match-timestamp", help='Check out adjacent repositories to match timestamp of ' ' current swift checkout.', action='store_true') parser.add_argument( "-j", "--jobs", type=int, help="Number of threads to run at once", default=0, dest="n_processes") args = parser.parse_args() if args.reset_to_remote and not args.scheme: print("update-checkout usage error: --reset-to-remote must specify " "--scheme=foo") sys.exit(1) clone = args.clone clone_with_ssh = args.clone_with_ssh skip_history = args.skip_history scheme = args.scheme github_comment = args.github_comment with open(args.config) as f: config = json.load(f) validate_config(config) if args.dump_hashes: dump_repo_hashes(config) return (None, None) if args.dump_hashes_config: dump_hashes_config(args, config) return (None, None) cross_repos_pr = {} if github_comment: regex_pr = r'(apple/[-a-zA-Z0-9_]+/pull/\d+|apple/[-a-zA-Z0-9_]+#\d+)' repos_with_pr = re.findall(regex_pr, github_comment) print("Found related pull requests:", str(repos_with_pr)) repos_with_pr = [pr.replace('/pull/', '#') for pr in repos_with_pr] cross_repos_pr = dict(pr.split('#') for pr in repos_with_pr) clone_results = None if clone or clone_with_ssh: # If branch is None, default to using the default branch alias # specified by our configuration file. if scheme is None: scheme = config['default-branch-scheme'] skip_repo_list = args.skip_repository_list clone_results = obtain_all_additional_swift_sources(args, config, clone_with_ssh, scheme, skip_history, skip_repo_list) update_results = update_all_repositories(args, config, scheme, cross_repos_pr) fail_count = 0 fail_count += shell.check_parallel_results(clone_results, "CLONE") fail_count += shell.check_parallel_results(update_results, "UPDATE") if fail_count > 0: print("update-checkout failed, fix errors and try again") else: print("update-checkout succeeded") sys.exit(fail_count)
def main(): freeze_support() parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=""" repositories. By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""") 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") parser.add_argument( "--skip-history", help="Skip histories when obtaining sources", action="store_true") parser.add_argument( "--skip-repository", metavar="DIRECTORY", default=[], help="Skip the specified repository", dest='skip_repository_list', action="append") parser.add_argument( "--scheme", help='Use branches from the specified branch-scheme. A "branch-scheme"' ' is a list of (repo, branch) pairs.', metavar='BRANCH-SCHEME', dest='scheme') parser.add_argument( '--reset-to-remote', help='Reset each branch to the remote state.', action='store_true') parser.add_argument( '--clean', help='Clean unrelated files from each repository.', action='store_true') parser.add_argument( "--config", default=os.path.join(SCRIPT_DIR, os.pardir, "update-checkout-config.json"), help="Configuration file to use") parser.add_argument( "--github-comment", help="""Check out related pull requests referenced in the given free-form GitHub-style comment.""", metavar='GITHUB-COMMENT', dest='github_comment') parser.add_argument( '--dump-hashes', action='store_true', help='Dump the git hashes of all repositories being tracked') parser.add_argument( '--dump-hashes-config', help='Dump the git hashes of all repositories packaged into ' 'update-checkout-config.json', metavar='BRANCH-SCHEME-NAME') parser.add_argument( "--tag", help="""Check out each repository to the specified tag.""", metavar='TAG-NAME') parser.add_argument( "--match-timestamp", help='Check out adjacent repositories to match timestamp of ' ' current swift checkout.', action='store_true') parser.add_argument( "-j", "--jobs", type=int, help="Number of threads to run at once", default=0, dest="n_processes") parser.add_argument( "--source-root", help="The root directory to checkout repositories", default=SWIFT_SOURCE_ROOT, dest='source_root') parser.add_argument( '--symlink-llvm-monorepo', help='Create symlink from LLVM-Project to source root directory', action='store_true') args = parser.parse_args() if not args.scheme: if args.reset_to_remote: print("update-checkout usage error: --reset-to-remote must " "specify --scheme=foo") sys.exit(1) if args.match_timestamp: # without a scheme, we won't be able match timestamps forward in # time, which is an annoying footgun for bisection etc. print("update-checkout usage error: --match-timestamp must " "specify --scheme=foo") sys.exit(1) clone = args.clone clone_with_ssh = args.clone_with_ssh skip_history = args.skip_history scheme = args.scheme github_comment = args.github_comment with open(args.config) as f: config = json.load(f) validate_config(config) if args.dump_hashes: dump_repo_hashes(args, config) return (None, None) if args.dump_hashes_config: dump_repo_hashes(args, config, args.dump_hashes_config) return (None, None) cross_repos_pr = {} if github_comment: regex_pr = r'(apple/[-a-zA-Z0-9_]+/pull/\d+|apple/[-a-zA-Z0-9_]+#\d+)' repos_with_pr = re.findall(regex_pr, github_comment) print("Found related pull requests:", str(repos_with_pr)) repos_with_pr = [pr.replace('/pull/', '#') for pr in repos_with_pr] cross_repos_pr = dict(pr.split('#') for pr in repos_with_pr) clone_results = None if clone or clone_with_ssh: # If branch is None, default to using the default branch alias # specified by our configuration file. if scheme is None: scheme = config['default-branch-scheme'] skip_repo_list = skip_list_for_platform(config) skip_repo_list.extend(args.skip_repository_list) clone_results = obtain_all_additional_swift_sources(args, config, clone_with_ssh, scheme, skip_history, skip_repo_list) # Quick check whether somebody is calling update in an empty directory directory_contents = os.listdir(args.source_root) if not ('cmark' in directory_contents or 'llvm' in directory_contents or 'clang' in directory_contents): print("You don't have all swift sources. " "Call this script with --clone to get them.") update_results = update_all_repositories(args, config, scheme, cross_repos_pr) fail_count = 0 fail_count += shell.check_parallel_results(clone_results, "CLONE") fail_count += shell.check_parallel_results(update_results, "UPDATE") if fail_count > 0: print("update-checkout failed, fix errors and try again") else: if args.symlink_llvm_monorepo: symlink_llvm_monorepo(args) print("update-checkout succeeded") print_repo_hashes(args, config) sys.exit(fail_count)