[Lldb-commits] [lldb] r295922 - Changed builld-llvm.py to use .json files

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 22 18:21:35 PST 2017


Author: spyffe
Date: Wed Feb 22 20:21:34 2017
New Revision: 295922

URL: http://llvm.org/viewvc/llvm-project?rev=295922&view=rev
Log:
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.

This update to the patch introduces a FALLBACK file
whose contents take precedence if the current branch
could not be identified.  If the current branch could be
identified, FALLBACK is updated, allowing the user to
e.g. cut branches off of known branches and still have
the automatic checkout mechanism work.

It also documents all of this.

Differential revision: https://reviews.llvm.org/D30275

Added:
    lldb/trunk/scripts/Xcode/repo.py
    lldb/trunk/scripts/Xcode/repos/
    lldb/trunk/scripts/Xcode/repos/FALLBACK
    lldb/trunk/scripts/Xcode/repos/svn-trunk.json
Modified:
    lldb/trunk/INSTALL.txt
    lldb/trunk/scripts/Xcode/build-llvm.py

Modified: lldb/trunk/INSTALL.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/INSTALL.txt?rev=295922&r1=295921&r2=295922&view=diff
==============================================================================
--- lldb/trunk/INSTALL.txt (original)
+++ lldb/trunk/INSTALL.txt Wed Feb 22 20:21:34 2017
@@ -7,6 +7,11 @@ On Mac OS X, in addition to using Xcode
 on your system to either build lldb or debug using lldb.  Please see the code
 signing documentation in docs/code-signing.txt for more detailed directions.
 
+If you are building on Mac OS X and LLVM is not present in llvm/, then LLDB
+will check it out automatically.  The files in scripts/Xcode/repos determine
+which branches of LLVM/Clang are checked out, depending on the current
+LLDB branch, according to the algorithm in scripts/Xcode/repo.py.
+
 For instructions to build LLDB on Linux, or more details about supported
 compiler versions, other dependencies, and build flags, see:
 

Modified: lldb/trunk/scripts/Xcode/build-llvm.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Xcode/build-llvm.py?rev=295922&r1=295921&r2=295922&view=diff
==============================================================================
--- lldb/trunk/scripts/Xcode/build-llvm.py (original)
+++ lldb/trunk/scripts/Xcode/build-llvm.py Wed Feb 22 20:21:34 2017
@@ -6,6 +6,7 @@ import fnmatch
 import os
 import platform
 import re
+import repo
 import subprocess
 import sys
 
@@ -17,42 +18,36 @@ 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:
+        identifier = "<invalid>" # repo.find will just use the fallback file
+    set = repo.find(identifier)
+    return [process_repo(r) for r in set]
 
 
 def get_c_compiler():

Added: lldb/trunk/scripts/Xcode/repo.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Xcode/repo.py?rev=295922&view=auto
==============================================================================
--- lldb/trunk/scripts/Xcode/repo.py (added)
+++ lldb/trunk/scripts/Xcode/repo.py Wed Feb 22 20:21:34 2017
@@ -0,0 +1,42 @@
+import json
+import os
+import re
+import shutil
+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")
+	if os.path.isfile(override_path):
+		override_set = json.load(open(override_path))
+		return override_set["repos"]
+	fallback_path = os.path.join(repos_dir, "FALLBACK")
+	for path in [os.path.join(repos_dir, f) for f in filter(json_regex.match, os.listdir(repos_dir))]:
+		fd = open(path)
+		set = json.load(fd)
+		fd.close()
+		if any(re.match(set_regex, identifier) for set_regex in set["regexs"]):
+			shutil.copyfile(path, fallback_path)
+			return set["repos"]
+	if os.path.isfile(fallback_path):
+		fallback_set = json.load(open(fallback_path))
+		return fallback_set["repos"]
+	sys.exit("Couldn't find a branch configuration for " + identifier + " and there was no " + fallback_path)

Added: lldb/trunk/scripts/Xcode/repos/FALLBACK
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Xcode/repos/FALLBACK?rev=295922&view=auto
==============================================================================
--- lldb/trunk/scripts/Xcode/repos/FALLBACK (added)
+++ lldb/trunk/scripts/Xcode/repos/FALLBACK Wed Feb 22 20:21:34 2017
@@ -0,0 +1,19 @@
+{
+    "regexs" : [".*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"}
+    ]
+}

Added: lldb/trunk/scripts/Xcode/repos/svn-trunk.json
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Xcode/repos/svn-trunk.json?rev=295922&view=auto
==============================================================================
--- lldb/trunk/scripts/Xcode/repos/svn-trunk.json (added)
+++ lldb/trunk/scripts/Xcode/repos/svn-trunk.json Wed Feb 22 20:21:34 2017
@@ -0,0 +1,19 @@
+{
+    "regexs" : [".*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"}
+    ]
+}




More information about the lldb-commits mailing list