77import argparse
88import os
99import pathlib
10+ import requests
1011import shlex
1112import shutil
1213import subprocess
@@ -27,11 +28,23 @@ def clone_llvm(dst_dir, llvm_repo, llvm_branch):
2728 return llvm_dir
2829
2930
30- def query_llvm_version (llvm_dir ):
31- GIT_LOG_CMD = f"git log --format=format:'%h' -1"
32- return subprocess .check_output (
33- shlex .split (GIT_LOG_CMD ), cwd = llvm_dir , universal_newlines = True , text = True
34- )
31+ def query_llvm_version (llvm_info ):
32+ github_token = os .environ ['GH_TOKEN' ]
33+ owner_project = llvm_info ['repo' ].replace ("https://github.com/" , "" ).replace (".git" , "" )
34+ url = f"https://api.github.com/repos/{ owner_project } /commits/{ llvm_info ['branch' ]} "
35+ headers = {
36+ 'Authorization' : f"Bearer { github_token } "
37+ }
38+
39+ try :
40+ response = requests .request ("GET" , url , headers = headers , data = {})
41+ response .raise_for_status ()
42+ except requests .exceptions .HTTPError as error :
43+ print (error ) # for debugging purpose
44+ return None
45+
46+ response = response .json ()
47+ return response ['sha' ]
3548
3649
3750def build_llvm (llvm_dir , platform , backends , projects , use_clang = False ):
@@ -253,13 +266,13 @@ def main():
253266
254267 try :
255268 llvm_info = llvm_repo_and_branch .get (platform , llvm_repo_and_branch ["default" ])
256- llvm_dir = clone_llvm (deps_dir , llvm_info ["repo" ], llvm_info ["branch" ])
257269
258270 if options .llvm_ver :
259- commit_hash = query_llvm_version (llvm_dir )
271+ commit_hash = query_llvm_version (llvm_info )
260272 print (commit_hash )
261273 return commit_hash is not None
262-
274+
275+ llvm_dir = clone_llvm (deps_dir , llvm_info ["repo" ], llvm_info ["branch" ])
263276 if (
264277 build_llvm (
265278 llvm_dir , platform , options .arch , options .project , options .use_clang
0 commit comments