@@ -21,83 +21,88 @@ from SwiftBuildSupport import (
21
21
SWIFT_SOURCE_ROOT ,
22
22
WorkingDirectory ,
23
23
check_call ,
24
+ check_output ,
24
25
)
25
26
26
- def update_working_copy (repo_path ):
27
+ def update_working_copy (repo_path , branch ):
27
28
if not os .path .isdir (repo_path ):
28
29
return
29
30
30
31
print ("--- Updating '" + repo_path + "' ---" )
31
32
with WorkingDirectory (repo_path ):
33
+ if branch :
34
+ status = check_output (['git' , 'status' , '--porcelain' ])
35
+ if status :
36
+ print ("Please, commit your changes." )
37
+ print (status )
38
+ exit (1 )
39
+ check_call (['git' , 'checkout' , branch ])
40
+
32
41
# Prior to Git 2.6, this is the way to do a "git pull
33
42
# --rebase" that respects rebase.autostash. See
34
43
# http://stackoverflow.com/a/30209750/125349
35
- check_call ([ "git" , "fetch" ])
36
- check_call ([ "git" , "rebase" , "FETCH_HEAD" ])
44
+ check_call (["git" , "fetch" ])
45
+ check_call (["git" , "rebase" , "FETCH_HEAD" ])
37
46
38
- def obtain_additional_swift_sources (opts = { ' with_ssh' : False } ):
47
+ def obtain_additional_swift_sources (with_ssh , branch ):
39
48
additional_repos = {
40
49
'llvm' : 'apple/swift-llvm' ,
41
50
'clang' : 'apple/swift-clang' ,
42
51
'lldb' : 'apple/swift-lldb' ,
43
52
'cmark' : 'apple/swift-cmark' ,
44
- 'llbuild' : 'apple/swift-llbuild' ,
45
- 'swiftpm' : 'apple/swift-package-manager' ,
46
- 'swift-corelibs-xctest' : 'apple/swift-corelibs-xctest' ,
47
- 'swift-corelibs-foundation' : 'apple/swift-corelibs-foundation' ,
48
53
'swift-integration-tests' : 'apple/swift-integration-tests' ,
49
54
}
50
55
for dir_name , repo in additional_repos .items ():
51
56
with WorkingDirectory (SWIFT_SOURCE_ROOT ):
52
57
if not os .path .isdir (os .path .join (dir_name , ".git" )):
53
58
print ("--- Cloning '" + dir_name + "' ---" )
54
- if opts [ ' with_ssh' ] is True :
59
+ if with_ssh is True :
55
60
remote = "[email protected] :" + repo + '.git'
56
61
else :
57
62
remote = "https://github.com/" + repo + '.git'
58
63
check_call (['git' , 'clone' , remote , dir_name ])
64
+ if branch :
65
+ src_path = SWIFT_SOURCE_ROOT + "/" + dir_name + "/" + ".git"
66
+ check_call (['git' , '--git-dir' , src_path , '--work-tree' , os .path .join (SWIFT_SOURCE_ROOT , dir_name ), 'checkout' , branch ])
59
67
60
68
def main ():
61
69
parser = argparse .ArgumentParser (
62
70
formatter_class = argparse .RawDescriptionHelpFormatter ,
63
71
description = """
64
72
repositories.
65
73
66
- By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM .""" )
74
+ By default, updates your checkouts of Swift, and LLDB .""" )
67
75
parser .add_argument ("-a" , "--all" ,
68
- help = "also update checkouts of llbuild, LLVM, and Clang" ,
76
+ help = "also update checkouts of LLVM, and Clang" ,
69
77
action = "store_true" )
70
78
parser .add_argument ("--clone" ,
71
79
help = "Obtain Sources for Swift and Related Projects" ,
72
80
action = "store_true" )
73
81
parser .add_argument ("--clone-with-ssh" ,
74
82
help = "Obtain Sources for Swift and Related Projects via SSH" ,
75
83
action = "store_true" )
84
+ parser .add_argument ("--branch" ,
85
+ help = "Obtain Sources for specific branch" )
76
86
args = parser .parse_args ()
77
87
78
- if args .clone :
79
- obtain_additional_swift_sources ()
80
- return 0
88
+ clone = args .clone
89
+ clone_with_ssh = args . clone_with_ssh
90
+ branch = args . branch
81
91
82
- if args . clone_with_ssh :
83
- obtain_additional_swift_sources ({ 'with_ssh' : True } )
92
+ if clone or clone_with_ssh :
93
+ obtain_additional_swift_sources (clone_with_ssh , branch )
84
94
return 0
85
95
86
96
if args .all :
87
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "llbuild" ))
88
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "llvm" ))
89
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "clang" ))
97
+ update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "llvm" ), branch )
98
+ update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "clang" ), branch )
90
99
91
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "swift" ))
100
+ update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "swift" ), branch )
92
101
update_working_copy (
93
- os .path .join (SWIFT_SOURCE_ROOT , "swift" , "benchmark" , "PerfTestSuite" ))
94
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "SourceKit" ))
95
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "cmark" ))
96
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "lldb" ))
97
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "swiftpm" ))
98
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "swift-corelibs-foundation" ))
99
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "swift-corelibs-xctest" ))
100
- update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "swift-integration-tests" ))
102
+ os .path .join (SWIFT_SOURCE_ROOT , "swift" , "benchmark" , "PerfTestSuite" ), branch )
103
+ update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "cmark" ), branch )
104
+ update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "lldb" ), branch )
105
+ update_working_copy (os .path .join (SWIFT_SOURCE_ROOT , "swift-integration-tests" ), branch )
101
106
102
107
return 0
103
108
0 commit comments