11#!/usr/bin/env python3
22
3- import contextlib
43import os
54from pathlib import Path
65import platform
109import time
1110
1211from tc_build .builder import Builder
12+ from tc_build .source import GitSourceManager
1313import tc_build .utils
1414
1515LLVM_VER_FOR_RUNTIMES = 20
@@ -572,10 +572,13 @@ class LLVMSlimInstrumentedBuilder(LLVMInstrumentedBuilder, LLVMSlimBuilder):
572572 pass
573573
574574
575- class LLVMSourceManager :
575+ class LLVMSourceManager ( GitSourceManager ) :
576576
577577 def __init__ (self , repo ):
578- self .repo = repo
578+ super ().__init__ (repo )
579+
580+ self ._pretty_name = 'LLVM'
581+ self ._repo_url = 'https://github.com/llvm/llvm-project.git'
579582
580583 def default_projects (self ):
581584 return ['clang' , 'compiler-rt' , 'lld' , 'polly' ]
@@ -591,57 +594,3 @@ def default_targets(self):
591594 targets .append ('LoongArch' )
592595
593596 return targets
594-
595- def download (self , ref , shallow = False ):
596- if self .repo .exists ():
597- return
598-
599- tc_build .utils .print_header ('Downloading LLVM' )
600-
601- git_clone = ['git' , 'clone' ]
602- if shallow :
603- git_clone .append ('--depth=1' )
604- if ref != 'main' :
605- git_clone .append ('--no-single-branch' )
606- git_clone += ['https://github.com/llvm/llvm-project' , self .repo ]
607-
608- subprocess .run (git_clone , check = True )
609-
610- self .git (['checkout' , ref ])
611-
612- def git (self , cmd , capture_output = False ):
613- return subprocess .run (['git' , * cmd ],
614- capture_output = capture_output ,
615- check = True ,
616- cwd = self .repo ,
617- text = True )
618-
619- def git_capture (self , cmd ):
620- return self .git (cmd , capture_output = True ).stdout .strip ()
621-
622- def is_shallow (self ):
623- git_dir = self .git_capture (['rev-parse' , '--git-dir' ])
624- return Path (git_dir , 'shallow' ).exists ()
625-
626- def ref_exists (self , ref ):
627- try :
628- self .git (['show-branch' , ref ])
629- except subprocess .CalledProcessError :
630- return False
631- return True
632-
633- def update (self , ref ):
634- tc_build .utils .print_header ('Updating LLVM' )
635-
636- self .git (['fetch' , 'origin' ])
637-
638- if self .is_shallow () and not self .ref_exists (ref ):
639- raise RuntimeError (f"Repo is shallow and supplied ref ('{ ref } ') does not exist!" )
640-
641- self .git (['checkout' , ref ])
642-
643- local_ref = None
644- with contextlib .suppress (subprocess .CalledProcessError ):
645- local_ref = self .git_capture (['symbolic-ref' , '-q' , 'HEAD' ])
646- if local_ref and local_ref .startswith ('refs/heads/' ):
647- self .git (['pull' , '--rebase' , 'origin' , local_ref .replace ('refs/heads/' , '' )])
0 commit comments