Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit c9442bd

Browse files
committed
[Bug 18335] Add SDK caching to setup_xcode_sdks.py tool
If you pass `--cache` as an argument to the Xcode SDK setup script, it will now copy all referenced SDKs into a cache directory before symlinking them into the target Xcode app bundle.
1 parent 435ac01 commit c9442bd

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

tools/setup_xcode_sdks.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,60 @@ def _install_sdks(self, xcode_app, platform, versions):
137137
for version in versions:
138138
self._install_sdk(xcode_app, platform, version)
139139

140+
class CachingSDKInstaller(SDKInstaller):
141+
def __init__(self, base_dir, cache_dir):
142+
super(CachingSDKInstaller, self).__init__(base_dir)
143+
self._cache_dir = cache_dir
144+
145+
def _cached_sdk_path(self, platform, version):
146+
tmpl = "{0}/{1}/{1}{2}.sdk"
147+
return os.path.abspath(tmpl.format(self._cache_dir, platform, version))
148+
149+
def _check_cached_sdk_path(self, platform, version):
150+
path = self._cached_sdk_path(platform, version)
151+
if os.path.exists(path) and os.path.isdir(path):
152+
return path
153+
else:
154+
return None
155+
156+
def _cache_sdk(self, platform, version):
157+
# Check cache
158+
cache = self._check_cached_sdk_path(platform, version)
159+
if cache is not None:
160+
return
161+
162+
# Search app bundles
163+
original = super(CachingSDKInstaller, self)._find_sdk(platform, version)
164+
if original is None:
165+
return
166+
167+
# Copy the original into cache
168+
# N.b. use `cp -a` in order to make sure all resource forks etc. are
169+
# preserved
170+
self._diagnostic("Caching {} {} SDK".format(platform, version))
171+
172+
cache = self._cached_sdk_path(platform, version)
173+
174+
platform_dir = os.path.dirname(cache)
175+
if not os.path.isdir(platform_dir):
176+
os.makedirs(platform_dir)
177+
178+
cmd = ["/bin/cp", "-a", original, cache]
179+
subprocess.check_call(cmd)
180+
181+
def _find_sdk(self, platform, version):
182+
# Any available SDKs should have already been cached
183+
return self._check_cached_sdk_path(platform, version)
184+
185+
def _install_sdk(self, xcode_app, platform, version):
186+
self._cache_sdk(platform, version)
187+
super(CachingSDKInstaller, self)._install_sdk(xcode_app, platform, version)
188+
140189
if __name__ == "__main__":
141-
installer = SDKInstaller(".")
190+
if "--cache" in sys.argv:
191+
installer = CachingSDKInstaller(".", "./XcodeSDKs")
192+
else:
193+
installer = SDKInstaller(".")
142194
installer.install("iPhoneOS", iphoneos_versions)
143195
installer.install("iPhoneSimulator", iphonesimulator_versions)
144196
installer.install("MacOSX", macosx_versions)

0 commit comments

Comments
 (0)