Skip to content

Commit 4ceee26

Browse files
committed
[update-checkout] Rather than hard coding the strings that a branch matches to cause it to be a *-branches branch, store the *-branches in the configuration file and the accepted names for the *-branches. This enables other configuration files to customize this behavior.
1 parent faa13a8 commit 4ceee26

File tree

2 files changed

+80
-52
lines changed

2 files changed

+80
-52
lines changed

utils/update-checkout

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,41 @@ def obtain_additional_swift_sources(
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 = os.path.join(SWIFT_SOURCE_ROOT, dir_name, ".git")
86+
src_path = os.path.join(SWIFT_SOURCE_ROOT, dir_name,
87+
".git")
8988
shell.call(['git', '--git-dir', src_path, '--work-tree',
9089
os.path.join(SWIFT_SOURCE_ROOT, dir_name),
9190
'checkout', repo_branch], echo=False)
9291

9392

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+
94113
def main():
95114
parser = argparse.ArgumentParser(
96115
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -132,6 +151,7 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
132151

133152
with open(args.config) as f:
134153
config = json.load(f)
154+
validate_config(config)
135155

136156
if clone or clone_with_ssh:
137157
obtain_additional_swift_sources(
@@ -143,13 +163,11 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
143163
print("--- Skipping '" + dir_name + "' ---")
144164
continue
145165
if branch:
146-
if branch == "master" or branch == "stable":
147-
repo_branch = config["master-branches"][dir_name]
148-
elif branch == "stable-next" or branch == "master-next":
149-
repo_branch = config["next-branches"][dir_name]
150-
elif branch == "swift-3.0-branch" or \
151-
branch == "swift-3.0-preview-1-branch":
152-
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
153171

154172
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, dir_name),
155173
repo_branch)

utils/update-checkout-config.json

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,57 @@
1515
"swift-corelibs-libdispatch": "apple/swift-corelibs-libdispatch",
1616
"swift-integration-tests": "apple/swift-integration-tests"
1717
},
18+
"branch_names": ["master-branches", "next-branches", "swift-3.0-preview-1-branches"],
1819
"master-branches": {
19-
"llvm": "stable",
20-
"clang": "stable",
21-
"swift": "master",
22-
"lldb": "master",
23-
"cmark": "master",
24-
"llbuild": "master",
25-
"swiftpm": "master",
26-
"compiler-rt": "stable",
27-
"swift-corelibs-xctest": "master",
28-
"swift-corelibs-foundation": "master",
29-
"swift-corelibs-libdispatch": "master",
30-
"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+
}
3135
},
3236
"next-branches" : {
33-
"llvm": "stable-next",
34-
"clang": "stable-next",
35-
"compiler-rt": "stable-next",
36-
"swift": "master-next",
37-
"lldb": "master-next",
38-
"cmark": "master",
39-
"llbuild": "master",
40-
"swiftpm": "master",
41-
"compiler-rt": "stable-next",
42-
"swift-corelibs-xctest": "master",
43-
"swift-corelibs-foundation": "master",
44-
"swift-corelibs-libdispatch": "master",
45-
"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+
}
4653
},
4754
"swift-3.0-preview-1-branches" : {
48-
"llvm": "swift-3.0-branch",
49-
"clang": "swift-3.0-branch",
50-
"swift": "swift-3.0-preview-1-branch",
51-
"lldb": "swift-3.0-preview-1-branch",
52-
"cmark": "swift-3.0-preview-1-branch",
53-
"llbuild": "swift-3.0-preview-1-branch",
54-
"swiftpm": "swift-3.0-preview-1-branch",
55-
"compiler-rt": "swift-3.0-branch",
56-
"swift-corelibs-xctest": "swift-3.0-preview-1-branch",
57-
"swift-corelibs-foundation": "swift-3.0-preview-1-branch",
58-
"swift-corelibs-libdispatch": "swift-3.0-preview-1-branch",
59-
"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+
}
6070
}
6171
}

0 commit comments

Comments
 (0)