Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
4e921b1
Add entitlements file
bachand Apr 20, 2019
d788327
Set entitlements file for Xcode
bachand Apr 21, 2019
f50ee16
Add extension targets
bachand Apr 21, 2019
5425b68
Remove clarification which seems unnecessary or incorrect
bachand Apr 21, 2019
041564e
Add .intentdefinition file
bachand Apr 21, 2019
14764a7
Use BuckPhotoIntent in application target
bachand Apr 22, 2019
247ca35
WORKAROUND: Add generated source of BuckPhotoIntent
bachand Apr 22, 2019
8715e5c
Add (currently hacked) intentdefinition_resource macro
bachand Apr 22, 2019
3ad2a02
Add intents file to Xcode
bachand Apr 22, 2019
f90fe86
Add intent to Info.plist
bachand Apr 22, 2019
5fffe75
Add Intents.intentdefinition as a resource
bachand Apr 22, 2019
a060fc7
Renaming
bachand Apr 23, 2019
3f21c5f
More cleanup
bachand Apr 23, 2019
74c83fd
Process .intentdefinition file
bachand Apr 23, 2019
c22f380
Simplify running intentbuilderc
bachand Apr 24, 2019
676c06b
Add IntentCompiler Xcode project
bachand Apr 24, 2019
5e5b111
Incremental progress towards programmatically building Swift interfac…
bachand Apr 24, 2019
d1b0509
Generate intent Swift interface using xcodebuild
bachand Apr 26, 2019
d519409
Specify intents
bachand Apr 27, 2019
7b8faf7
Use generated intent interface and process .intentdefinition in exten…
bachand Apr 28, 2019
52dc9d6
Indentation
bachand Apr 28, 2019
ad6af79
Fix syntax for including Swift interface
bachand Apr 28, 2019
227131b
Add intent handling code
bachand Apr 28, 2019
c67e7e6
Add AddToSiri button
bachand Apr 28, 2019
85c3b1a
Hook up ability to add to siri
bachand Apr 28, 2019
41cbae1
Get intent building for CLI
bachand Apr 28, 2019
a20ea1f
Clean up BUCK file and fix NSExtensionPrincipalClass
bachand Apr 28, 2019
df13572
More info.plist fixes and consolidation
bachand Apr 28, 2019
3a92916
Cleanup and fix NS_EXTENSION_PRINCIPAL_CLASS
bachand Apr 28, 2019
fbc7a7d
Cleanup
bachand Apr 28, 2019
b565ae5
Link to frameworks and add storyboard resource
bachand Apr 28, 2019
8d39ccc
change UI
bachand Apr 28, 2019
87f7185
DO NOT MERGE add buck CLI fix
bachand Apr 28, 2019
ee1ec1e
Fix intent UI in Buck CLI
bachand Apr 28, 2019
48d7ba5
Actually commit Xcode project
bachand Apr 29, 2019
b3acc6f
Revert "DO NOT MERGE add buck CLI fix"
bachand Apr 29, 2019
b2d5237
Make app delegate code more logical
bachand Apr 29, 2019
f656cb6
Style and remove unnecessary comment
bachand Apr 29, 2019
ac938b3
Remove MARK
bachand Apr 29, 2019
582508b
Remove xcrun which is breaking CI
bachand Apr 29, 2019
c067ed0
Revert "Remove xcrun which is breaking CI"
bachand Apr 29, 2019
7cff1b0
Update to syntax that works in Airbnb project
bachand May 4, 2019
bb258ac
Formatting
bachand May 4, 2019
f16f11b
Make intent_interface more explicit
bachand May 5, 2019
7acb92f
Make intent_interface more helpful
bachand May 5, 2019
3794fd0
Update .intentdefinition to 10.2.1 and add intent key to IntentCompil…
bachand May 5, 2019
7a82c08
Update buck_rule_macros.bzl
bachand May 6, 2019
463e3b4
Don't code sign in new or old build system
bachand May 6, 2019
0a5b442
attemp to get CI working
bachand May 6, 2019
c467c8b
Do not process in Xcode 9 either
bachand May 6, 2019
a4d12b6
Do something for Xcode 9
bachand May 6, 2019
d4c45d4
Use shared configs
bachand May 6, 2019
fca3075
Actually add something to Swfit file
bachand May 6, 2019
ba21ce4
Change mv to cp for consistency
bachand May 6, 2019
b8f1ceb
Update visibility
bachand May 7, 2019
bdcc891
Revert "Update visibility"
bachand May 7, 2019
b7fad87
add compiler version of BuckPhoto Intent to get this working on Xcode 9
bachand May 9, 2019
204ed2e
Work around Xcode 9 on CI
bachand May 9, 2019
51f6dba
Clean up VC
bachand May 9, 2019
85dcd1a
Attempt to fix Xcode 9 build error as this file is necessary to build…
bachand May 9, 2019
6cea09f
try again
bachand May 9, 2019
3d9eb26
try again
bachand May 9, 2019
b71cd9e
More Xcode 9
bachand May 9, 2019
76538ff
And more
bachand May 9, 2019
2948f14
More Swift wrappers
bachand May 9, 2019
25c64b8
More
bachand May 9, 2019
94e7b39
try again
bachand May 9, 2019
52e65d6
Adjustment
bachand May 9, 2019
c98c372
we actually want greater than Swift 4 since this project is still swi…
bachand May 9, 2019
490ca98
add siri shortcut feature flag
bachand May 9, 2019
40d7705
Add compiler flag and turn off by default
bachand May 9, 2019
0cc6ae8
get rid of placeholder
bachand May 9, 2019
69c2596
Simplify
bachand May 9, 2019
9037297
fix xcode 10
bachand May 9, 2019
227623b
One more place
bachand May 9, 2019
358dc67
fallback
bachand May 9, 2019
380c709
ONe more
bachand May 9, 2019
6386ea8
Last one
bachand May 9, 2019
905456a
hopefully
bachand May 9, 2019
7061d33
remove erroneous comments
bachand May 9, 2019
884ea19
oops
bachand May 9, 2019
dc1823a
Change arg type again
bachand May 9, 2019
07a4ae6
Update AppDelegate.swift
bachand May 9, 2019
273c29a
Fix test App delegate
bachand May 9, 2019
0c6c4b2
Update for arm64
bachand May 9, 2019
c34ca1e
Localize intentdefinition
bachand May 12, 2019
1daee65
Process intentdefinition from new location
bachand May 12, 2019
b637c4e
Point IntentsCompiler project to correct location
bachand May 12, 2019
8338c76
Missing slash
bachand May 12, 2019
3e90047
Remove .intentdefinition from extra_xcode_files as we've done in our …
bachand May 12, 2019
ac70379
Create BUCK file for Resources/ and update how we handle storyboards
bachand May 12, 2019
91a4096
Move .intentdefinition processing into Resources/BUCK to make Buck happy
bachand May 12, 2019
17209dd
Localize .intentdefinition
bachand May 12, 2019
70033a6
Create rule for intent strings
bachand May 12, 2019
08fa2d4
reorg
bachand May 12, 2019
b9632e2
Add string resources
bachand May 12, 2019
0cd69bf
typo
bachand May 12, 2019
07b4ebd
Use variants instead of files since we're localizing
bachand May 12, 2019
a215603
Plural
bachand May 12, 2019
e40af55
Add localization TODO
bachand May 13, 2019
f031411
Localize invocation phrase
bachand May 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[swift]
version = 4.0
compiler_flags = -DBUCK -enable-testing -g -Onone -whole-module-optimization $(config custom.other_swift_compiler_flags)
compiler_flags = -DBUCK -enable-testing -g -Onone -whole-module-optimization $(config custom.other_swift_compiler_flags) -DDISABLE_SIRI_SHORTCUT
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's behind a feature flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works around having Xcode 9 in CI.

use_filelist = true

[apple]
Expand Down Expand Up @@ -41,4 +41,3 @@
code_coverage_cxxflags = -fprofile-instr-generate -fcoverage-mapping
code_coverage_ldflags = -fprofile-instr-generate
code_coverage_swift_compiler_flags = -profile-generate -profile-coverage-mapping

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ tools/buck
# Xcode
**/xcuserdata/
**/*.xcodeproj/
!App/SiriShortcut/_IntentsCompiler/IntentsCompiler.xcodeproj
**/*.xcworkspace/
**/build/

# Make
*.d
34 changes: 33 additions & 1 deletion App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,42 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let window = UIWindow(frame: UIScreen.main.bounds)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: ArgType) -> Bool {

window.makeKeyAndVisible()
window.rootViewController = ViewController()

return true
}

#if !DISABLE_SIRI_SHORTCUT
#if swift(>=4.2)
// Xcode 10
func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
{
return continueWithUserActivity(userActivity)
}
#endif
#endif

// MARK: Private

private func continueWithUserActivity(_ userActivity: NSUserActivity) -> Bool {
guard #available(iOS 12.0, *) else {
return false
}

#if !DISABLE_SIRI_SHORTCUT
if let buckPhotoIntent = userActivity.interaction?.intent as? BuckPhotoIntent {
print("Launched with BuckPhotoIntent: \(buckPhotoIntent)")
return true
} else {
return false
}
#else
return false
#endif
}
}
140 changes: 137 additions & 3 deletions App/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//Config:configs.bzl", "app_binary_configs", "library_configs", "watch_binary_configs", "message_binary_configs", "pretty", "info_plist_substitutions", "bundle_identifier", "DEVELOPMENT_LANGUAGE")
load("//Config:buck_rule_macros.bzl", "apple_lib", "apple_test_lib", "apple_test_all")
load("//Config:configs.bzl", "app_binary_configs", "library_configs", "watch_binary_configs", "message_binary_configs", "intent_binary_configs", "pretty", "info_plist_substitutions", "bundle_identifier", "DEVELOPMENT_LANGUAGE")
load("//Config:buck_rule_macros.bzl", "apple_lib", "apple_test_lib", "apple_test_all", "intent_interface")

apple_asset_catalog(
name = "ExampleAppAssets",
Expand Down Expand Up @@ -57,8 +57,10 @@ apple_library(
swift_version = "4.0",
srcs = [
"ViewController.swift",
"ViewController+INUIAddVoiceShortcutViewControllerDelegate.swift",
"AppDelegate.swift",
"LocalizationHelper.swift",
":BuckPhotoIntentInterface",
],
tests = app_tests,
deps = [
Expand All @@ -69,10 +71,16 @@ apple_library(

# Resources
"//App/Resources:ExampleAppStringResources",
"//App/Resources:IntentsDefinition",
"//App/Resources:IntentsStringResources",
"//App/Resources:StoryboardResources",
]
+ first_party_library_dependencies
+ build_phase_scripts,
frameworks = [
"$SDKROOT/System/Library/Frameworks/Intents.framework",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that Intents.framework is strictly necessary, but I have added it to reduce the potential causes of unexpected failure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. This is used by the generated intent source code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's good we keep Intents.framework 👍

"$SDKROOT/System/Library/Frameworks/IntentsUI.framework",
],
)

apple_binary(
Expand All @@ -82,6 +90,7 @@ apple_binary(
"//App/...",
],
configs = app_binary_configs("ExampleApp"),
entitlements_file = "ExampleApp.entitlements",
swift_version = "4.0",
srcs = [
"BuckSupportFiles/Dummy.swift",
Expand Down Expand Up @@ -148,7 +157,9 @@ apple_bundle(
deps = [
# For "#watch", https://buckbuild.com/rule/apple_bundle.html#deps
":ExampleWatchApp#watch",
":ExampleMessageExtension"
":ExampleMessageExtension",
":ExampleIntentExtension",
":ExampleIntentUIExtension",
]
+ prebuilt_frameworks,
)
Expand All @@ -158,6 +169,129 @@ apple_package(
bundle = ":ExampleApp",
)

### Siri Shortcut Begin ###

# Set up `BuckPhotoIntent` by handling the .intentdefinition file.
intent_interface(
"BuckPhotoIntentInterface",
"BuckPhoto",
"SiriShortcut/_IntentsCompiler/IntentsCompiler.xcodeproj")

# The non-UI code for processing `BuckPhotoIntent`.
intent_bundle_identifier = bundle_identifier("ExampleApp.IntentExtension")
intent_binary_name = "ExampleIntentBinary"
intent_bundle_name = "ExampleIntentExtension"
intent_info_plist_substitutions = {
"DEVELOPMENT_LANGUAGE": "en-us",
"EXECUTABLE_NAME": intent_bundle_name,
"PRODUCT_BUNDLE_DISPLAY_NAME": intent_bundle_name,
"PRODUCT_BUNDLE_IDENTIFIER": intent_bundle_identifier,
"PRODUCT_NAME": intent_bundle_name,
# The Swift module name for `IntentHandler` is the binary name.
"NS_EXTENSION_PRINCIPAL_CLASS": "%s.IntentHandler" % intent_binary_name,
}

apple_binary(
name = intent_binary_name,
srcs = glob([
"SiriShortcut/ExampleIntent/**/*.swift",
]) + [":BuckPhotoIntentInterface"],
configs = intent_binary_configs(intent_info_plist_substitutions),

# "-e _NSExtensionMain" tell linker this binary is app extension, so it won't fail due to
# missing _main "-Xlinker -rpath -Xlinker @executable_path/../../Frameworks" tells the
# executable binary to look for frameworks in ExampleApp.app/Frameworks instead of PlugIns, so
# that we don't need to have the libSwift*.dylib in ExampleApp.app/PlugIns/*.appex/Frameworks
linker_flags = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add /usr/lib/swift as a search path to make it work on iOS 12.2 forward. It was the case for me:

    linker_flags = [
        "-e",
        "_NSExtensionMain",
        "-Xlinker",
        "-rpath",
        "-Xlinker",
        "/usr/lib/swift"
        "-Xlinker",
        "-rpath",
        "-Xlinker",
        "@executable_path/../../Frameworks",
    ],

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Thanks for sharing @rockbruno. Are you on Swift 5?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m trying to understand if this is because the Swift libraries packaged with the app are now being ignored. If I understand correctly this occurs with Swift 5+ and iOS 12.2+.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on 4.2, but I'm using Xcode 10.2 which IIRC uses the Swift 5 compiler regardless of the version.
I remember they changed Buck to add this import by default so I'm surprised I had to do this, so maybe it's just the extension bundles that weren't covered by the change...

"-e",
"_NSExtensionMain",
"-Xlinker",
"-rpath",
"-Xlinker",
"@executable_path/../../Frameworks",
],
deps = [
"//App/Resources:IntentsDefinition",
"//App/Resources:IntentsStringResources",
],
frameworks = [
"$SDKROOT/System/Library/Frameworks/Intents.framework",
],
)

apple_bundle(
name = intent_bundle_name,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If necessary you can also set product_name to name the .appex file and its associated binary, but that's only necessary if you want name to be different.

Copy link
Collaborator Author

@bachand bachand May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When unspecified product_name == name.

binary = ":" + intent_binary_name,
extension = "appex",
info_plist = "SiriShortcut/ExampleIntent/Info.plist",
info_plist_substitutions = intent_info_plist_substitutions,
xcode_product_type = "com.apple.product-type.app-extension",
)

# The UI code for displaying the response to `BuckPhotoIntent`.
intentui_bundle_identifier = bundle_identifier("ExampleApp.IntentUIExtension")
intentui_binary_name = "ExampleIntentUIBinary"
intentui_bundle_name = "ExampleIntentUIExtension"
intentui_resources_name = intentui_bundle_name + "Resources"
intentui_info_plist_substitutions = {
"DEVELOPMENT_LANGUAGE": "en-us",
"EXECUTABLE_NAME": intentui_bundle_name,
"PRODUCT_BUNDLE_DISPLAY_NAME": intentui_bundle_name,
"PRODUCT_BUNDLE_IDENTIFIER": intentui_bundle_identifier,
"PRODUCT_NAME": intentui_bundle_name,
}

apple_binary(
name = intentui_binary_name,
srcs = glob([
"SiriShortcut/ExampleIntentUI/**/*.swift",
]) + [":BuckPhotoIntentInterface"],
configs = intent_binary_configs(intentui_info_plist_substitutions),

# "-e _NSExtensionMain" tell linker this binary is app extension, so it won't fail due to
# missing _main "-Xlinker -rpath -Xlinker @executable_path/../../Frameworks" tells the
# executable binary to look for frameworks in ExampleApp.app/Frameworks instead of PlugIns, so
# that we don't need to have the libSwift*.dylib in ExampleApp.app/PlugIns/*.appex/Frameworks
linker_flags = [
"-e",
"_NSExtensionMain",
"-Xlinker",
"-rpath",
"-Xlinker",
"@executable_path/../../Frameworks",
],
deps = [
"//App/Resources:IntentsDefinition",
"//App/Resources:IntentsStringResources",
],
frameworks = [
"$SDKROOT/System/Library/Frameworks/Intents.framework",
"$SDKROOT/System/Library/Frameworks/IntentsUI.framework",
],
)

apple_resource(
name = intentui_resources_name,
dirs = [],
# WORKAROUND: Buck CLI requires you to explicitly set the "Module Name" of the
# `IntentViewController` class to `ExampleIntentUIBinary` in MainInterface.storyboard.
files = glob(["SiriShortcut/ExampleIntentUI/**/*.storyboard"])
)

apple_bundle(
name = intentui_bundle_name,
binary = ":" + intentui_binary_name,
extension = "appex",
info_plist = "SiriShortcut/ExampleIntentUI/Info.plist",
info_plist_substitutions = intentui_info_plist_substitutions,
xcode_product_type = "com.apple.product-type.app-extension",
deps = [
":" + intentui_resources_name,
],
)

### Siri Shortcut End ###

### Watch App Begin ###
# Define the watch app in the same BUCK file as the binary into which the watch app will be installed.
# Xcode is finicky when it comes to how it embeds watch apps into main app bundles. Watch apps are
Expand Down
8 changes: 8 additions & 0 deletions App/ExampleApp.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.siri</key>
<true/>
</dict>
</plist>
4 changes: 4 additions & 0 deletions App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSUserActivityTypes</key>
<array>
<string>BuckPhotoIntent</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
13 changes: 13 additions & 0 deletions App/Resources/BUCK
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//Config:buck_rule_macros.bzl", "intentdefinition_resource")

apple_resource(
name = "ExampleAppStringResources",
visibility = ["//App:"],
Expand All @@ -7,10 +9,21 @@ apple_resource(
]),
)

apple_resource(
name = "IntentsStringResources",
visibility = ["//App:"],
files = [],
variants = glob([
"*.lproj/Intents.strings",
]),
)

apple_resource(
name = "StoryboardResources",
visibility = ["//App:"],
variants = glob([
"*.lproj/*.storyboard",
]),
)

intentdefinition_resource("IntentsDefinition", "./en.lproj/", "Intents", "en")
3 changes: 2 additions & 1 deletion App/Resources/en.lproj/ExampleApp.strings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
ExampleApp.strings
ExampleApp

Expand All @@ -7,3 +7,4 @@
*/

"Hello, world" = "Hello, world";
"Show me a buck" = "Show me a buck";
Loading