Skip to content

Commit aec15fa

Browse files
committed
[update-checkout] Rename the 'branch' concept to 'scheme'.
update-checkout as a script has two different concepts associated with the term 'branch': 1. A "real" git branch. 2. A dictionary of names mapped to lists of (repo, git branch) pairs. The second concept is used to specify on the command line a "palette" of branches in all of the repositories associated with things like "master", "master-next", and the preview branches. This is far more than a "branch". This commit gives a unique name, "scheme" to that concept. Keep in mind that even though the internals have changed, the outside interface (i.e. --branch) is still the same. That will change at a later time since I would like to change the interface slightly which may require bots to be updated.
1 parent e9c2aa8 commit aec15fa

File tree

2 files changed

+103
-96
lines changed

2 files changed

+103
-96
lines changed

utils/update-checkout

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,29 @@ def update_single_repository(repo_path, branch):
5656
echo=False)
5757

5858

59-
def update_all_repositories(args, config, branch):
60-
repo_branch = branch
61-
for dir_name in config["repositories"].keys():
62-
if dir_name in args.skip_repository:
63-
print("--- Skipping '" + dir_name + "' ---")
59+
def update_all_repositories(args, config, scheme_name):
60+
repo_branch = scheme_name
61+
for repo_name in config["repositories"].keys():
62+
if repo_name in args.skip_repository:
63+
print("--- Skipping '" + repo_name + "' ---")
6464
continue
65-
if branch:
66-
for config_branch_name in config['branch-names']:
67-
if branch not in config[config_branch_name]['aliases']:
65+
if scheme_name:
66+
# This loop is only correct, since we know that each alias set has
67+
# unique contents. This is checked by verify config. Thus the first
68+
# branch scheme data that has scheme_name as one of its aliases is
69+
# the only possible correct answer.
70+
for v in config['branch-schemes'].values():
71+
if scheme_name not in v['aliases']:
6872
continue
69-
repo_branch = config[config_branch_name]['repos'][dir_name]
73+
repo_branch = v['repos'][repo_name]
7074
break
7175

72-
update_single_repository(os.path.join(SWIFT_SOURCE_ROOT, dir_name),
76+
update_single_repository(os.path.join(SWIFT_SOURCE_ROOT, repo_name),
7377
repo_branch)
7478

7579

7680
def obtain_additional_swift_sources(
77-
config, with_ssh, branch, skip_history, skip_repositories):
81+
config, with_ssh, scheme_name, skip_history, skip_repositories):
7882
with shell.pushd(SWIFT_SOURCE_ROOT, dry_run=False,
7983
echo=False):
8084
for dir_name, repo_info in config['repositories'].items():
@@ -104,15 +108,14 @@ def obtain_additional_swift_sources(
104108
else:
105109
shell.call(['git', 'clone', '--recursive', remote,
106110
dir_name], echo=False)
107-
if branch:
108-
for config_branch_name in config['branch-names']:
109-
if branch not in config[config_branch_name]['aliases']:
111+
if scheme_name:
112+
for v in config['branch-schemes'].values():
113+
if scheme_name not in v['aliases']:
110114
continue
111-
repo_branch = \
112-
config[config_branch_name]['repos'][dir_name]
115+
repo_branch = v['repos'][dir_name]
113116
break
114117
else:
115-
repo_branch = branch
118+
repo_branch = scheme_name
116119
src_path = os.path.join(SWIFT_SOURCE_ROOT, dir_name,
117120
".git")
118121
shell.call(['git', '--git-dir', src_path, '--work-tree',
@@ -122,17 +125,18 @@ def obtain_additional_swift_sources(
122125

123126
def validate_config(config):
124127
# Make sure that our branch-names are unique.
125-
if len(config['branch-names']) != len(set(config['branch-names'])):
126-
raise RuntimeError('Configuration file has duplicate \'branch-names\'')
128+
scheme_names = config['branch-schemes'].keys()
129+
if len(scheme_names) != len(set(scheme_names)):
130+
raise RuntimeError('Configuration file has duplicate schemes?!')
127131

128132
# Then make sure the alias names used by our branches are unique.
129133
#
130134
# We do this by constructing a list consisting of len(names),
131135
# set(names). Then we reduce over that list summing the counts and taking
132136
# the union of the sets. We have uniqueness if the length of the union
133137
# equals the length of the sum of the counts.
134-
data = [(len(config[branch]['aliases']), set(config[branch]['aliases']))
135-
for branch in config['branch-names']]
138+
data = [(len(v['aliases']), set(v['aliases']))
139+
for v in config['branch-schemes'].values()]
136140
result = reduce(lambda acc, x: (acc[0] + x[0], acc[1] | x[1]), data,
137141
(0, set([])))
138142
if result[0] == len(result[1]):
@@ -167,7 +171,9 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
167171
action="append")
168172
parser.add_argument(
169173
"--branch",
170-
help="Obtain Sources for specific branch")
174+
help='Obtain Sources for specific branch',
175+
metavar='BRANCH',
176+
dest='scheme')
171177
parser.add_argument(
172178
"--config",
173179
default=os.path.join(SCRIPT_DIR, "update-checkout-config.json"),
@@ -177,22 +183,22 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
177183
clone = args.clone
178184
clone_with_ssh = args.clone_with_ssh
179185
skip_history = args.skip_history
180-
branch = args.branch
186+
scheme = args.scheme
181187

182188
with open(args.config) as f:
183189
config = json.load(f)
184190
validate_config(config)
185191

186192
# If branch is None, default to using the default branch alias specified by
187193
# our configuration file.
188-
if branch is None:
189-
branch = config['default-branch-alias']
194+
if scheme is None:
195+
scheme = config['default-branch-scheme']
190196

191197
if clone or clone_with_ssh:
192198
obtain_additional_swift_sources(
193-
config, clone_with_ssh, branch, skip_history, args.skip_repository)
199+
config, clone_with_ssh, scheme, skip_history, args.skip_repository)
194200

195-
update_all_repositories(args, config, branch)
201+
update_all_repositories(args, config, scheme)
196202

197203
return 0
198204

utils/update-checkout-config.json

Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,75 +15,76 @@
1515
"swift-corelibs-libdispatch": { "remote-repo-name": "apple/swift-corelibs-libdispatch" },
1616
"swift-integration-tests": { "remote-repo-name": "apple/swift-integration-tests" }
1717
},
18-
"branch-names": ["master-branches", "next-branches", "swift-3.0-preview-1-branches", "swift-3.0-preview-2-branches"],
19-
"default-branch-alias": "master",
20-
"master-branches": {
21-
"aliases": ["master", "stable"],
22-
"repos": {
23-
"llvm": "stable",
24-
"clang": "stable",
25-
"swift": "master",
26-
"lldb": "master",
27-
"cmark": "master",
28-
"llbuild": "master",
29-
"swiftpm": "master",
30-
"compiler-rt": "stable",
31-
"swift-corelibs-xctest": "master",
32-
"swift-corelibs-foundation": "master",
33-
"swift-corelibs-libdispatch": "master",
34-
"swift-integration-tests": "master"
35-
}
36-
},
37-
"next-branches" : {
38-
"aliases": ["master-next", "stable-next"],
39-
"repos": {
40-
"llvm": "stable-next",
41-
"clang": "stable-next",
42-
"compiler-rt": "stable-next",
43-
"swift": "master-next",
44-
"lldb": "master-next",
45-
"cmark": "master",
46-
"llbuild": "master",
47-
"swiftpm": "master",
48-
"compiler-rt": "stable-next",
49-
"swift-corelibs-xctest": "master",
50-
"swift-corelibs-foundation": "master",
51-
"swift-corelibs-libdispatch": "master",
52-
"swift-integration-tests": "master"
53-
}
54-
},
55-
"swift-3.0-preview-1-branches" : {
56-
"aliases": ["swift-3.0-preview-1-branch"],
57-
"repos": {
58-
"llvm": "swift-3.0-branch",
59-
"clang": "swift-3.0-branch",
60-
"swift": "swift-3.0-preview-1-branch",
61-
"lldb": "swift-3.0-preview-1-branch",
62-
"cmark": "swift-3.0-preview-1-branch",
63-
"llbuild": "swift-3.0-preview-1-branch",
64-
"swiftpm": "swift-3.0-preview-1-branch",
65-
"compiler-rt": "swift-3.0-branch",
66-
"swift-corelibs-xctest": "swift-3.0-preview-1-branch",
67-
"swift-corelibs-foundation": "swift-3.0-preview-1-branch",
68-
"swift-corelibs-libdispatch": "swift-3.0-preview-1-branch",
69-
"swift-integration-tests": "swift-3.0-preview-1-branch"
70-
}
71-
},
72-
"swift-3.0-preview-2-branches" : {
73-
"aliases": ["swift-3.0-branch", "swift-3.0-preview-2-branch"],
74-
"repos": {
75-
"llvm": "swift-3.0-branch",
76-
"clang": "swift-3.0-branch",
77-
"swift": "swift-3.0-preview-2-branch",
78-
"lldb": "swift-3.0-preview-2-branch",
79-
"cmark": "swift-3.0-preview-2-branch",
80-
"llbuild": "swift-3.0-preview-2-branch",
81-
"swiftpm": "swift-3.0-preview-2-branch",
82-
"compiler-rt": "swift-3.0-branch",
83-
"swift-corelibs-xctest": "swift-3.0-preview-2-branch",
84-
"swift-corelibs-foundation": "swift-3.0-preview-2-branch",
85-
"swift-corelibs-libdispatch": "swift-3.0-preview-2-branch",
86-
"swift-integration-tests": "swift-3.0-preview-2-branch"
18+
"default-branch-scheme": "master",
19+
"branch-schemes": {
20+
"master": {
21+
"aliases": ["master", "stable"],
22+
"repos": {
23+
"llvm": "stable",
24+
"clang": "stable",
25+
"swift": "master",
26+
"lldb": "master",
27+
"cmark": "master",
28+
"llbuild": "master",
29+
"swiftpm": "master",
30+
"compiler-rt": "stable",
31+
"swift-corelibs-xctest": "master",
32+
"swift-corelibs-foundation": "master",
33+
"swift-corelibs-libdispatch": "master",
34+
"swift-integration-tests": "master"
35+
}
36+
},
37+
"next" : {
38+
"aliases": ["master-next", "stable-next"],
39+
"repos": {
40+
"llvm": "stable-next",
41+
"clang": "stable-next",
42+
"compiler-rt": "stable-next",
43+
"swift": "master-next",
44+
"lldb": "master-next",
45+
"cmark": "master",
46+
"llbuild": "master",
47+
"swiftpm": "master",
48+
"compiler-rt": "stable-next",
49+
"swift-corelibs-xctest": "master",
50+
"swift-corelibs-foundation": "master",
51+
"swift-corelibs-libdispatch": "master",
52+
"swift-integration-tests": "master"
53+
}
54+
},
55+
"swift-3.0-preview-1" : {
56+
"aliases": ["swift-3.0-preview-1-branch"],
57+
"repos": {
58+
"llvm": "swift-3.0-branch",
59+
"clang": "swift-3.0-branch",
60+
"swift": "swift-3.0-preview-1-branch",
61+
"lldb": "swift-3.0-preview-1-branch",
62+
"cmark": "swift-3.0-preview-1-branch",
63+
"llbuild": "swift-3.0-preview-1-branch",
64+
"swiftpm": "swift-3.0-preview-1-branch",
65+
"compiler-rt": "swift-3.0-branch",
66+
"swift-corelibs-xctest": "swift-3.0-preview-1-branch",
67+
"swift-corelibs-foundation": "swift-3.0-preview-1-branch",
68+
"swift-corelibs-libdispatch": "swift-3.0-preview-1-branch",
69+
"swift-integration-tests": "swift-3.0-preview-1-branch"
70+
}
71+
},
72+
"swift-3.0-preview-2" : {
73+
"aliases": ["swift-3.0-branch", "swift-3.0-preview-2-branch"],
74+
"repos": {
75+
"llvm": "swift-3.0-branch",
76+
"clang": "swift-3.0-branch",
77+
"swift": "swift-3.0-preview-2-branch",
78+
"lldb": "swift-3.0-preview-2-branch",
79+
"cmark": "swift-3.0-preview-2-branch",
80+
"llbuild": "swift-3.0-preview-2-branch",
81+
"swiftpm": "swift-3.0-preview-2-branch",
82+
"compiler-rt": "swift-3.0-branch",
83+
"swift-corelibs-xctest": "swift-3.0-preview-2-branch",
84+
"swift-corelibs-foundation": "swift-3.0-preview-2-branch",
85+
"swift-corelibs-libdispatch": "swift-3.0-preview-2-branch",
86+
"swift-integration-tests": "swift-3.0-preview-2-branch"
87+
}
8788
}
8889
}
8990
}

0 commit comments

Comments
 (0)