解决办法:
在官方文档中找到如下一段说明,即使用--cache-builds
即表示使用缓存进行构建。
Caching builds
By default Carthage will rebuild a dependency regardless of whether it's the same resolved version as before. Passing the
--cache-builds
will cause carthage to avoid rebuilding a dependency if it can. See information on version files for details on how carthage performs this caching.
执行:
修改 Jenkins 脚本,将命令carthage update --platform iOS
修改为carthage update --platform iOS --cache-builds
,然后很开心的在 Jenkins job 上点了构建。
carthage update --platform iOS --cache-builds
*** Fetching Charts
*** Checking out Charts at "v3.0.2"
*** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.JEKNY6.log
*** No cache found for Charts, building with all downstream dependencies
*** Building scheme "Charts" in Charts.xcodeproj
但没找到 cache,怀疑需要第二次 build 才可以。但事实是第二次依然提示No cache found
。肯定是哪里不对,回过头来再次查看官方文档,发现如下一段介绍:
If you're building for iOS, tvOS, or watchOS
...
6.Add the paths to the copied frameworks to the “Output Files”, e.g.:
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Result.framework
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveSwift.framework
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveCocoa.framework
With output files specified alongside the input files, Xcode only needs to run the script when the input files have changed or the output files are missing. This means dirty builds will be faster when you haven't rebuilt frameworks with Carthage.
然后对照我们的工程检查,发现并没有配置这个Output Files
,原因应该就在这里了。随即找开发添加,并提交代码,触发构建。
本以为这次可以命中 cache,但得到无效 cache 的提示:
carthage update --platform iOS --cache-builds
*** Fetching Charts
*** Checking out Charts at "v3.0.2"
*** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.KZDaMB.log
*** Invalid cache found for Charts, rebuilding with all downstream dependencies
*** Building scheme "Charts" in Charts.xcodeproj
这个就比较郁闷了,按照官方文档所有的配置都没有问题,参数也没有问题,而且在本地是可以命中 cache 的:
carthage update --platform iOS --cache-builds
*** Fetching Charts
*** Checking out Charts at "v3.0.2"
*** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.gxGJC9.log
*** Valid cache found for Charts, skipping build
而且开发提交代码后,在我的电脑上和开发的电脑上都可以命中 cache,偏偏只有 Jenkins 无法命中 cache。
这个时候已经没有其他可能,不会是配置或者参数的问题了,那么来查看一下 xcodebuild 的日志吧。
发现构建生成的Charts.framework
所有的路径中有8.1_8B62
,而这个正式 Jenkins 服务器上 xcode 的版本。所以猜测 carthage 的 cache 和 xcode 的版本有关。
Signing Identity: "-"
/usr/bin/codesign --force --sign - --timestamp=none /Users/nick/Library/Caches/org.carthage.CarthageKit/DerivedData/8.1_8B62/Charts/v3.0.2/Build/Products/Release-iphonesimulator/Charts.framework
** BUILD SUCCEEDED **
随即升级了 xcode 版本到 8.3.3,然后再次构建,成功命中缓存。
carthage update --platform iOS --cache-builds
*** Fetching Charts
*** Checking out Charts at "v3.0.2"
*** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.8aIUyY.log
*** Valid cache found for Charts, skipping build
Carthage is intended to be the simplest way to add frameworks to your Cocoa application.
The basic workflow looks something like this:
Carthage builds your dependencies and provides you with binary frameworks, but you retain full control over your project structure and setup. Carthage does not automatically modify your project files or your build settings.