command line xcode - justin millerjustinmiller.io/talks/media/xcode cli - cocoaheads.pdf ·...

42
Command Line Xcode Or: GUI Development Without The G Justin Miller / @incanus77 / MapBox

Upload: others

Post on 20-Jun-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

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

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
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

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

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

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

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

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

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

-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

-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

-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

-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

-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

-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

-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

-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

-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

-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

-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

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

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

-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

-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

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

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

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

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

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

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

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

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

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

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

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 35: 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

Extra Goodies

• nomad - http://nomad-cli.com

• gem install nomad-cli

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
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
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
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
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
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

Conclusion

• Xcode is very scriptable

• Apple has put a lot of time into this

• Hint: someone uses it internally

• It can actually be fun!

Page 42: 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

Thanks!

• @incanus77

[email protected]

• I’ll post these slides online