Skip to content

Commit b0862e2

Browse files
committed
Merge pull request #2925 from gottesmm/move_the_rest_of_the_customization_code_into_the_config_file
Move the rest of the update-checkout repo customization code into update-checkout-config.json.
2 parents e7bf227 + 4ceee26 commit b0862e2

File tree

2 files changed

+85
-56
lines changed

2 files changed

+85
-56
lines changed

utils/update-checkout

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,52 @@ def obtain_additional_swift_sources(
6464
echo=False):
6565
if not os.path.isdir(os.path.join(dir_name, ".git")):
6666
print("--- Cloning '" + dir_name + "' ---")
67-
if with_ssh is True:
68-
remote = "[email protected]:" + repo + '.git'
67+
if with_ssh is True or "https_clone_pattern" not in config:
68+
remote = config["ssh_clone_pattern"] % repo
6969
else:
70-
remote = "https://github.com/" + repo + '.git'
70+
remote = config["https_clone_pattern"] % repo
7171
if skip_history:
7272
shell.call(['git', 'clone', '--recursive', '--depth', '1',
7373
remote, dir_name], echo=False)
7474
else:
7575
shell.call(['git', 'clone', '--recursive', remote,
7676
dir_name], echo=False)
7777
if branch:
78-
if branch == "master" or branch == "stable":
79-
repo_branch = config['master-branches'][dir_name]
80-
elif branch == "stable-next" or branch == "master-next":
81-
repo_branch = config['next-branches'][dir_name]
82-
elif branch == "swift-3.0-branch" or \
83-
branch == "swift-3.0-preview-1-branch":
78+
for config_branch_name in config['branch_names']:
79+
if branch not in config[config_branch_name]['aliases']:
80+
continue
8481
repo_branch = \
85-
config["swift-3.0-preview-1-branches"][dir_name]
82+
config[config_branch_name]['repos'][dir_name]
83+
break
8684
else:
8785
repo_branch = branch
88-
src_path = SWIFT_SOURCE_ROOT + "/" + dir_name + "/" + \
89-
".git"
86+
src_path = os.path.join(SWIFT_SOURCE_ROOT, dir_name,
87+
".git")
9088
shell.call(['git', '--git-dir', src_path, '--work-tree',
9189
os.path.join(SWIFT_SOURCE_ROOT, dir_name),
9290
'checkout', repo_branch], echo=False)
9391

9492

93+
def validate_config(config):
94+
# Make sure that our branch_names are unique.
95+
if len(config['branch_names']) != len(set(config['branch_names'])):
96+
raise RuntimeError('Configuration file has duplicate \'branch_names\'')
97+
98+
# Then make sure the alias names used by our branches are unique.
99+
#
100+
# We do this by constructing a list consisting of len(names),
101+
# set(names). Then we reduce over that list summing the counts and taking
102+
# the union of the sets. We have uniqueness if the length of the union
103+
# equals the length of the sum of the counts.
104+
data = [(len(config[branch]['aliases']), set(config[branch]['aliases']))
105+
for branch in config['branch_names']]
106+
result = reduce(lambda acc, x: (acc[0] + x[0], acc[1] | x[1]), data,
107+
(0, set([])))
108+
if result[0] == len(result[1]):
109+
return
110+
raise RuntimeError('Overlapping alias names for two types of branches')
111+
112+
95113
def main():
96114
parser = argparse.ArgumentParser(
97115
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -133,6 +151,7 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
133151

134152
with open(args.config) as f:
135153
config = json.load(f)
154+
validate_config(config)
136155

137156
if clone or clone_with_ssh:
138157
obtain_additional_swift_sources(
@@ -144,13 +163,11 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
144163
print("--- Skipping '" + dir_name + "' ---")
145164
continue
146165
if branch:
147-
if branch == "master" or branch == "stable":
148-
repo_branch = config["master-branches"][dir_name]
149-
elif branch == "stable-next" or branch == "master-next":
150-
repo_branch = config["next-branches"][dir_name]
151-
elif branch == "swift-3.0-branch" or \
152-
branch == "swift-3.0-preview-1-branch":
153-
repo_branch = config["swift-3.0-preview-1-branches"][dir_name]
166+
for config_branch_name in config['branch_names']:
167+
if branch not in config[config_branch_name]['aliases']:
168+
continue
169+
repo_branch = config[config_branch_name]['repos'][dir_name]
170+
break
154171

155172
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, dir_name),
156173
repo_branch)

utils/update-checkout-config.json

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"ssh_clone_pattern": "[email protected]:%s.git",
3+
"https_clone_pattern": "https://github.com/%s.git",
24
"repositories" : {
35
"llvm": "apple/swift-llvm",
46
"clang": "apple/swift-clang",
@@ -13,47 +15,57 @@
1315
"swift-corelibs-libdispatch": "apple/swift-corelibs-libdispatch",
1416
"swift-integration-tests": "apple/swift-integration-tests"
1517
},
18+
"branch_names": ["master-branches", "next-branches", "swift-3.0-preview-1-branches"],
1619
"master-branches": {
17-
"llvm": "stable",
18-
"clang": "stable",
19-
"swift": "master",
20-
"lldb": "master",
21-
"cmark": "master",
22-
"llbuild": "master",
23-
"swiftpm": "master",
24-
"compiler-rt": "stable",
25-
"swift-corelibs-xctest": "master",
26-
"swift-corelibs-foundation": "master",
27-
"swift-corelibs-libdispatch": "master",
28-
"swift-integration-tests": "master"
20+
"aliases": ["master", "stable"],
21+
"repos": {
22+
"llvm": "stable",
23+
"clang": "stable",
24+
"swift": "master",
25+
"lldb": "master",
26+
"cmark": "master",
27+
"llbuild": "master",
28+
"swiftpm": "master",
29+
"compiler-rt": "stable",
30+
"swift-corelibs-xctest": "master",
31+
"swift-corelibs-foundation": "master",
32+
"swift-corelibs-libdispatch": "master",
33+
"swift-integration-tests": "master"
34+
}
2935
},
3036
"next-branches" : {
31-
"llvm": "stable-next",
32-
"clang": "stable-next",
33-
"compiler-rt": "stable-next",
34-
"swift": "master-next",
35-
"lldb": "master-next",
36-
"cmark": "master",
37-
"llbuild": "master",
38-
"swiftpm": "master",
39-
"compiler-rt": "stable-next",
40-
"swift-corelibs-xctest": "master",
41-
"swift-corelibs-foundation": "master",
42-
"swift-corelibs-libdispatch": "master",
43-
"swift-integration-tests": "master"
37+
"aliases": ["master-next", "stable-next"],
38+
"repos": {
39+
"llvm": "stable-next",
40+
"clang": "stable-next",
41+
"compiler-rt": "stable-next",
42+
"swift": "master-next",
43+
"lldb": "master-next",
44+
"cmark": "master",
45+
"llbuild": "master",
46+
"swiftpm": "master",
47+
"compiler-rt": "stable-next",
48+
"swift-corelibs-xctest": "master",
49+
"swift-corelibs-foundation": "master",
50+
"swift-corelibs-libdispatch": "master",
51+
"swift-integration-tests": "master"
52+
}
4453
},
4554
"swift-3.0-preview-1-branches" : {
46-
"llvm": "swift-3.0-branch",
47-
"clang": "swift-3.0-branch",
48-
"swift": "swift-3.0-preview-1-branch",
49-
"lldb": "swift-3.0-preview-1-branch",
50-
"cmark": "swift-3.0-preview-1-branch",
51-
"llbuild": "swift-3.0-preview-1-branch",
52-
"swiftpm": "swift-3.0-preview-1-branch",
53-
"compiler-rt": "swift-3.0-branch",
54-
"swift-corelibs-xctest": "swift-3.0-preview-1-branch",
55-
"swift-corelibs-foundation": "swift-3.0-preview-1-branch",
56-
"swift-corelibs-libdispatch": "swift-3.0-preview-1-branch",
57-
"swift-integration-tests": "swift-3.0-preview-1-branch"
55+
"aliases": ["swift-3.0-branch", "swift-3.0-preview-1-branch"],
56+
"repos": {
57+
"llvm": "swift-3.0-branch",
58+
"clang": "swift-3.0-branch",
59+
"swift": "swift-3.0-preview-1-branch",
60+
"lldb": "swift-3.0-preview-1-branch",
61+
"cmark": "swift-3.0-preview-1-branch",
62+
"llbuild": "swift-3.0-preview-1-branch",
63+
"swiftpm": "swift-3.0-preview-1-branch",
64+
"compiler-rt": "swift-3.0-branch",
65+
"swift-corelibs-xctest": "swift-3.0-preview-1-branch",
66+
"swift-corelibs-foundation": "swift-3.0-preview-1-branch",
67+
"swift-corelibs-libdispatch": "swift-3.0-preview-1-branch",
68+
"swift-integration-tests": "swift-3.0-preview-1-branch"
69+
}
5870
}
5971
}

0 commit comments

Comments
 (0)