Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf ·...
Transcript of Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf ·...
![Page 1: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/1.jpg)
Command Line XcodeOr: GUI Development Without The G
Justin Miller / @incanus77 / MapBox
![Page 2: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/2.jpg)
![Page 3: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/3.jpg)
About Me
• Mobile Lead at MapBox
• 15y CLI / 10y Cocoa / ~3y CLI Xcode
• Mostly work in iOS, though a bit of OS X
• We have a build box for TileMill(.com)
![Page 4: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/4.jpg)
Target Audience• Cocoa developers
• You are working on apps in .xcodeproj files
• Maybe you want to automate builds or tests
• Maybe you build frameworks
• CLI tools are enough for straight UNIX stuff
![Page 5: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/5.jpg)
Overview• Setup & configuration
• Actual building
• Project files, targets, configurations, architectures, SDKs, etc.
• Assistive tools & extras
• lipo, hub, Homebrew, nomad, shell tricks, etc.
![Page 6: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/6.jpg)
Installation• Xcode.app (App Store or .dmg)
• Can have multiple installs (e.g. 4.6.3 & 5.0.1)
• xcode-select
• DEVELOPER_DIR
• Xcode preferences
![Page 7: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/7.jpg)
xcrun
• Very useful for UNIX building
• e.g. `xcrun -f clang`
• Uses a caching system
• -n : Don’t use/update cache
• -k : Kill cache
![Page 8: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/8.jpg)
xcodebuild
• The Big Kahuna (that’s the technical term)
• You’ll spend most of your time in it
• Have a look at the man page
• `man xcodebuild`
![Page 9: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/9.jpg)
-listAnalogy: having a glance at
the main UI
![Page 10: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/10.jpg)
-project
• For when you have multiple project files in the current folder
• Analogy: opening an .xcodeproj
![Page 11: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/11.jpg)
-workspace
• For when you want to open an .xcworkspace
• Personally, I prefer to explicitly specify everything
• I use workspaces for CocoaPods
![Page 12: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/12.jpg)
-targetAnalogy: target selector
(obviously not rocket science)
![Page 13: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/13.jpg)
-configurationAnalogy: target configurations (Release/Debug/Ad Hoc, etc.)
![Page 14: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/14.jpg)
-showsdks
• List installed SDKs
• macosx10.6
• iphoneos5.0
• etc.
![Page 15: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/15.jpg)
-sdk• iOS 6 or 7, etc.
• -sdk macosx10.6
• -sdk iphoneos5.0
![Page 16: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/16.jpg)
-destination• Machine architecture
• arch=i386
• arch=x86_64 (default)
• Device or simulator
• name=Ithildin
• name="iPhone Retina (3.5-inch)"
• Operating system
• OS=7.0
• OS=latest
• Generic device
• name="generic/iOS Device"
• -destination-timeout
![Page 17: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/17.jpg)
-scheme
• Scheme selector
• Obtain from -list
![Page 18: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/18.jpg)
-derivedDataPath
• If you don’t know what DerivedData is, you should probably keep it that way
• Seriously, though: maybe you have a reason to be sure you are working cache-free
![Page 19: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/19.jpg)
-resultBundlePath
• Modify where your built product ends up
• Useful for e.g. plopping it into a shared folder
![Page 20: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/20.jpg)
Archives• -exportArchive
• -exportFormat
• IPA, PKG, APP (guesses intelligently)
• -archivePath
• -exportPath
• -exportProvisioningProfile
• -exportSigningIdentity
![Page 21: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/21.jpg)
Build Actions• clean
• build (default)
• analyze
• archive
• test
• installsrc & install
![Page 22: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/22.jpg)
-xcconfig
• Useful if you use .xcconfig files
• Probably a better route if you use version control and/or have a team
![Page 23: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/23.jpg)
-dry-run & -n
• DON’T TOUCH ANYTHING
• Great way to just try things out
• Thought I can’t see what could get hurt
![Page 24: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/24.jpg)
setting=value
• Change build settings
• e.g. Header Search Paths
![Page 25: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/25.jpg)
Extra Goodies
• lipo
• Useful for adding/subtracting slices in fat binaries
![Page 26: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/26.jpg)
lipo Example
![Page 27: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/27.jpg)
lipo Example
![Page 28: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/28.jpg)
Extra Goodies• CocoaPods
• Excellent dependency system
• But also has a great command-line tool
• xcodeproj
• Project info, config settings, even resources!
![Page 29: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/29.jpg)
Extra Goodies
• Notifications
• Bezel
• Notifications
![Page 30: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/30.jpg)
Notifications• I made some handy shell functions
• bwd - terminal bell
• gwd - Growl when done
• nwd - notify when done
• `nwd xcodebuild […]`
![Page 31: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/31.jpg)
Notifications
![Page 32: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/32.jpg)
Notifications
![Page 33: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/33.jpg)
Extra Goodies• hub
• create - create repo on GitHub & set origin
• browse - open GitHub page in browser
• compare a…b - open GitHub compare page
• pull-request & fork - YMMV
![Page 34: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/34.jpg)
Extra Goodies• Xcode ships with nice Git Bash completion
• Add to ~/.bash_profile:
• . `xcode-select -p`/usr/share/git-core/git-completion.bash
• . `xcode-select -p`/usr/share/git-core/git-prompt.sh
![Page 36: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/36.jpg)
![Page 37: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/37.jpg)
![Page 38: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/38.jpg)
![Page 39: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/39.jpg)
![Page 40: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/40.jpg)
![Page 41: Command Line Xcode - Justin Millerjustinmiller.io/talks/media/Xcode CLI - CocoaHeads.pdf · 2020-03-31 · Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77](https://reader035.fdocuments.net/reader035/viewer/2022062317/5f09bf7a7e708231d428545f/html5/thumbnails/41.jpg)
Conclusion
• Xcode is very scriptable
• Apple has put a lot of time into this
• Hint: someone uses it internally
• It can actually be fun!