加入到新的團(tuán)隊(duì)后宣增,首先發(fā)現(xiàn)的問題就是項(xiàng)目編譯速度太慢了玫膀!簡直慢到令人發(fā)指,什么概念呢爹脾,當(dāng)你修改了項(xiàng)目的配置文件或者重新 pod install 或者其他改動(dòng)帖旨,導(dǎo)致工程觸發(fā)全量編譯時(shí),編譯時(shí)間居然在30分~40分鐘不等灵妨!
雖然以前了解過一些編譯優(yōu)化的工作解阅,但沒有親自參與過,這一次也算是親自實(shí)踐了泌霍。比較明確的是货抄,在進(jìn)行優(yōu)化之前,首先要做的一定是深入研究一下 Xcode 的編譯過程烹吵,找到導(dǎo)致工程編譯慢的罪魁禍?zhǔn)装谋茫瑢ΠY下藥方能解決問題生蚁。
一個(gè)簡單的 Demo
為了方便輔助介紹 Xcode 的編譯過程,用 Xcode 創(chuàng)建一個(gè)簡單的 single view app藏姐,考慮到采用 Cocoapods 進(jìn)行第三方庫管理已經(jīng)成了幾乎所有 iOS 項(xiàng)目的標(biāo)配呀酸,我這里使用本地源碼創(chuàng)建的一個(gè)本地 pod 來實(shí)驗(yàn)凉蜂。Log 目錄下存在一個(gè) TestLog.podpec 的文件,執(zhí)行 pod install 后,就得到的集成后的工程窿吩,工程結(jié)構(gòu)如下圖所示:
注茎杂,Podfile 和 podspec 均使用官方命令產(chǎn)出:
pod init
pod spec create TestLog
頁面啟動(dòng)后調(diào)用 XcodeLog 的類方法:+[XcodeLog log],打印一行日志:
ok纫雁,Demo 準(zhǔn)備好了煌往,也運(yùn)行起來了,我們一起看下編譯它過程轧邪。
Demo 編譯過程
Xcode 非常的強(qiáng)大刽脖,強(qiáng)大到整個(gè)編譯細(xì)節(jié)你都可以看到!
于是忌愚,我們 cmd + B 后曲管,看到詳細(xì)的編譯日志:
流程大致分為:
- 編譯 TestLog 這個(gè) Target
- 編譯 Pods-XcodeDemo 這個(gè) Target
- 編譯 XcodeDemo 這個(gè)主工程
- 編譯完成
默認(rèn)情況下,上面細(xì)節(jié)的界面隱藏了大量編譯信息硕糊,我們可以通過點(diǎn)擊每一條單獨(dú)的任務(wù)進(jìn)行展開院水,更詳細(xì)的信息就在這里面了。
Target 編譯
- Write auxiliary files
生成一些輔助文件简十,主要是 .hmap檬某、LinkFileList 文件,用于輔助執(zhí)行編譯用的勺远,可以提高二次編譯速度橙喘。
Write auxiliary files
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-target-headers.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-generated-files.hmap
/bin/mkdir -p /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog.LinkFileList
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-own-target-headers.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-project-headers.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-non-framework-target-headers.hmap
- 編譯 .m 文件
.m 是主要的源文件,經(jīng)過預(yù)編譯操作后胶逢,這里的 .m 是展開后的厅瞎,可以獨(dú)立編譯生成最后的 .o 文件。
這里 CompileC 命令和 clang 命令
CompileC /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.o /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/ranger/tmp/XcodeDemo/Pods
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu11 -fobjc-arc -fobjc-weak -fmodules -fmodules-cache-path=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DPOD_CONFIGURATION_DEBUG=1 -DDEBUG=1 -DCOCOAPODS=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -mios-simulator-version-min=9.0 -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wunguarded-availability -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Index/DataStore -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-generated-files.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-own-target-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-target-headers.hmap -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-project-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/include -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private/TestLog -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public/TestLog -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources/x86_64 -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources -F/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -include /Users/ranger/tmp/XcodeDemo/Pods/Target\ Support\ Files/TestLog/TestLog-prefix.pch -MMD -MT dependencies -MF /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.d --serialize-diagnostics /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.dia -c /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.m -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.o
- 編譯 xxx-dummy.m 文件
xxx-dummy.m 文件是 CocoaPods 使用的用于區(qū)分不同 pod 的編譯文件初坠,每個(gè)第三方庫有不同的 target和簸,所以每次編譯第三方庫時(shí),都會(huì)新增幾個(gè)文件:包含編譯選項(xiàng)的.xcconfig文件碟刺,同時(shí)擁有編譯設(shè)置和 CocoaPods 配置的私有 .xcconfig 文件锁保,編譯所必須的prefix.pch文件以及編譯必須的文件 dummy.m
CompileC /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.o Target\ Support\ Files/TestLog/TestLog-dummy.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/ranger/tmp/XcodeDemo/Pods
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu11 -fobjc-arc -fobjc-weak -fmodules -fmodules-cache-path=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DPOD_CONFIGURATION_DEBUG=1 -DDEBUG=1 -DCOCOAPODS=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -mios-simulator-version-min=9.0 -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wunguarded-availability -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Index/DataStore -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-generated-files.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-own-target-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-target-headers.hmap -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-project-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/include -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private/TestLog -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public/TestLog -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources/x86_64 -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources -F/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -include /Users/ranger/tmp/XcodeDemo/Pods/Target\ Support\ Files/TestLog/TestLog-prefix.pch -MMD -MT dependencies -MF /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.d --serialize-diagnostics /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.dia -c /Users/ranger/tmp/XcodeDemo/Pods/Target\ Support\ Files/TestLog/TestLog-dummy.m -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.o
- 創(chuàng)建靜態(tài)庫
創(chuàng)建當(dāng)前架構(gòu)的靜態(tài)庫,例如栗子中用的是模擬器半沽,對應(yīng)的是 x86_64 架構(gòu)爽柒。
Libtool /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/libTestLog.a normal x86_64
cd /Users/ranger/tmp/XcodeDemo/Pods
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -L/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -filelist /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog.LinkFileList -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/libTestLog.a
- 拷貝頭文件
將所有的頭文件拷貝到 Pods 目錄對應(yīng)的 pod 里,沒有頭文件配合使用的二進(jìn)制庫是不能使用的者填。
CpHeader /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.h /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/XcodeLog.h
cd /Users/ranger/tmp/XcodeDemo/Pods
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.h /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog
- 拷貝資源文件(如果有)
主工程編譯
- Write auxiliary files
- Process product packaging
- 執(zhí)行 cocoapods 資源拷貝腳本
- 編譯 .m 文件
- 鏈接靜態(tài)庫
- 編譯資源文件
- Process info.plist file
- 執(zhí)行 cocoapods 資源拷貝腳本
- 創(chuàng)建 .app
- 打包及簽名
仔細(xì)觀察
我們知道浩村,XcodeDemo 是工程的主 Target,那 TestLog 和 Pods-XcodeDemo 是哪兒來的呢占哟?
嗯心墅,了解 CocoaPods 原理的同學(xué)都知道酿矢,CocoaPods 創(chuàng)建了 Pods 工程,引入新的工程來隱藏第三方庫的依賴怎燥,從而管理第三方 pods瘫筐。簡單說就是主工程依賴 Pods 工程,Pods 工程依賴子
pods铐姚,從而間接被主工程依賴策肝。而新的 Target 就是 CocoaPods 創(chuàng)建的。
仔細(xì)觀察編譯過程隐绵,我們會(huì)發(fā)現(xiàn)驳糯,除了主工程直接生成最終的 .app 外,其他工程(Target)都會(huì)編譯成一個(gè)靜態(tài)庫被主工程去 Link氢橙,如果某個(gè)工程特別大酝枢,包含眾多的 .m 文件或者其他資源文件,那么 Xcode 就會(huì)花費(fèi)較多的時(shí)間去編譯悍手。
而在 Link 階段帘睦,Xcode 會(huì)將前面創(chuàng)建的所有二進(jìn)制文件做一次鏈接得到最后的二進(jìn)制包
Ld /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/XcodeDemo.app/XcodeDemo normal x86_64
cd /Users/ranger/tmp/XcodeDemo
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -L/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator -L/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -F/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator -filelist /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/Objects-normal/x86_64/XcodeDemo.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/Objects-normal/x86_64/XcodeDemo_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -ObjC -lTestLog -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/XcodeDemo.app-Simulated.xcent -lPods-XcodeDemo -Xlinker -dependency_info -Xlinker /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/Objects-normal/x86_64/XcodeDemo_dependency_info.dat -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/XcodeDemo.app/XcodeDemo
整體流程大概就是這樣,即使再復(fù)雜的工程坦康,也是類似的流程和操作竣付。