From ff1fb7f846829a20a4d8242925686effb8cbbaf1 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Wed, 22 Feb 2017 22:57:59 +0000 Subject: [PATCH] Changed builld-llvm.py to use .json files LLDB has many branches in a variety of repositories. The build-script.py file is subtly different for each set. This is unnecessary and causes merge headaches. This patch makes build-llvm.py consult a directory full of .json files, each one of which matches a particular branch using a regular expression. Differential revision: https://reviews.llvm.org/D30275 llvm-svn: 295897 --- lldb/scripts/Xcode/build-llvm.py | 61 ++++++++++++------------- lldb/scripts/Xcode/repo.py | 33 +++++++++++++ lldb/scripts/Xcode/repos/svn-trunk.json | 19 ++++++++ 3 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 lldb/scripts/Xcode/repo.py create mode 100644 lldb/scripts/Xcode/repos/svn-trunk.json diff --git a/lldb/scripts/Xcode/build-llvm.py b/lldb/scripts/Xcode/build-llvm.py index 792f92558b4d..15b6a6b8c505 100755 --- a/lldb/scripts/Xcode/build-llvm.py +++ b/lldb/scripts/Xcode/build-llvm.py @@ -6,6 +6,7 @@ import fnmatch import os import platform import re +import repo import subprocess import sys @@ -17,42 +18,38 @@ from lldbbuild import * def LLVM_HASH_INCLUDES_DIFFS(): return False -# The use of "x = "..."; return x" here is important because tooling looks for -# it with regexps. Only change how this works if you know what you are doing. - - -def LLVM_REF(): - llvm_ref = "master" - return llvm_ref - - -def CLANG_REF(): - clang_ref = "master" - return clang_ref - # For use with Xcode-style builds +def process_vcs(vcs): + return { + "svn": VCS.svn, + "git": VCS.git + }[vcs] + +def process_root(name): + return { + "llvm": llvm_source_path(), + "clang": clang_source_path(), + "ninja": ninja_source_path() + }[name] + +def process_repo(r): + return { + 'name': r["name"], + 'vcs': process_vcs(r["vcs"]), + 'root': process_root(r["name"]), + 'url': r["url"], + 'ref': r["ref"] + } def XCODE_REPOSITORIES(): - return [ - {'name': "llvm", - 'vcs': VCS.git, - 'root': llvm_source_path(), - 'url': "http://llvm.org/git/llvm.git", - 'ref': LLVM_REF()}, - - {'name': "clang", - 'vcs': VCS.git, - 'root': clang_source_path(), - 'url': "http://llvm.org/git/clang.git", - 'ref': CLANG_REF()}, - - {'name': "ninja", - 'vcs': VCS.git, - 'root': ninja_source_path(), - 'url': "https://github.com/ninja-build/ninja.git", - 'ref': "master"} - ] + identifier = repo.identifier() + if identifier == None: + sys.exit("Couldn't identify the current branch") + set = repo.find(identifier) + if set == None: + sys.exit("Couldn't find a repository set for the current branch") + return [process_repo(r) for r in set] def get_c_compiler(): diff --git a/lldb/scripts/Xcode/repo.py b/lldb/scripts/Xcode/repo.py new file mode 100644 index 000000000000..2f737b5186c6 --- /dev/null +++ b/lldb/scripts/Xcode/repo.py @@ -0,0 +1,33 @@ +import json +import os +import re +import subprocess + +def identifier(): + try: + svn_output = subprocess.check_output(["svn", "info", "--show-item", "url"], stderr=subprocess.STDOUT).rstrip() + return svn_output + except: + pass + try: + git_remote_and_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]).rstrip() + git_remote = git_remote_and_branch.split("/")[0] + git_branch = "/".join(git_remote_and_branch.split("/")[1:]) + git_url = subprocess.check_output(["git", "remote", "get-url", git_remote]).rstrip() + return git_url + ":" + git_branch + except: + pass + return None + +def find(identifier): + dir = os.path.dirname(os.path.realpath(__file__)) + repos_dir = os.path.join(dir, "repos") + json_regex = re.compile(r"^.*.json$") + override_path = os.path.join(repos_dir, "OVERRIDE.json") + if os.path.isfile(override_path): + override_set = json.load(open(override_path)) + return override_set["repos"] + for set in [json.load(open(os.path.join(repos_dir, f))) for f in filter(json_regex.match, os.listdir(repos_dir))]: + if re.match(set["regexp"], identifier): + return set["repos"] + return None diff --git a/lldb/scripts/Xcode/repos/svn-trunk.json b/lldb/scripts/Xcode/repos/svn-trunk.json new file mode 100644 index 000000000000..e4a1af122e1b --- /dev/null +++ b/lldb/scripts/Xcode/repos/svn-trunk.json @@ -0,0 +1,19 @@ +{ + "regexp" : ".*llvm\\.org.*", + "repos" : [ + {"name": "llvm", + "vcs": "git", + "url": "http://llvm.org/git/llvm.git", + "ref": "master"}, + + {"name": "clang", + "vcs": "git", + "url": "http://llvm.org/git/clang.git", + "ref": "master"}, + + {"name": "ninja", + "vcs": "git", + "url": "https://github.com/ninja-build/ninja.git", + "ref": "master"} + ] +}