Skip to content

Commit cbd1efc

Browse files
Vitalii Topoliukfacebook-github-bot
authored andcommitted
Add support for LoginItems destination
Summary: Sandboxed macOS applications have specific requirements for launching on user login. Helped app should be placed under `App.app/Contents/Library/LoginItems`. This change will add new destination for this specific path Reviewed By: blackm00n fbshipit-source-id: 6dc7b24228ed90fcba10f571943e4192f65f0a9a
1 parent 0745246 commit cbd1efc

11 files changed

Lines changed: 68 additions & 3 deletions

File tree

src/com/facebook/buck/apple/AppleBundleDestination.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public enum AppleBundleDestination {
3737
QUICKLOOK,
3838
WATCHKITSTUB,
3939
BUNDLEROOT,
40+
LOGINITEMS,
4041
;
4142

4243
/**
@@ -69,6 +70,8 @@ public Path getPath(AppleBundleDestinations destinations) {
6970
return destinations.getWatchKitStubPath();
7071
case BUNDLEROOT:
7172
return Paths.get("");
73+
case LOGINITEMS:
74+
return destinations.getLoginItemsPath();
7275
}
7376
throw new IllegalStateException("Unhandled AppleBundleDestination " + this);
7477
}

src/com/facebook/buck/apple/AppleBundleDestinations.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
5959
@AddToRuleKey(stringify = true)
6060
public abstract Path getWatchKitStubPath();
6161

62+
@AddToRuleKey(stringify = true)
63+
public abstract Path getLoginItemsPath();
64+
6265
private static final Path OSX_CONTENTS_PATH = Paths.get("Contents");
6366
public static final AppleBundleDestinations OSX_DESTINATIONS =
6467
ImmutableAppleBundleDestinations.ofImpl(
@@ -72,7 +75,8 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
7275
OSX_CONTENTS_PATH,
7376
OSX_CONTENTS_PATH.resolve("XPCServices"),
7477
OSX_CONTENTS_PATH.resolve("Library/QuickLook"),
75-
OSX_CONTENTS_PATH);
78+
OSX_CONTENTS_PATH,
79+
OSX_CONTENTS_PATH.resolve("Library/LoginItems"));
7680

7781
private static final Path OSX_FRAMEWORK_CONTENTS_PATH = Paths.get("");
7882
public static final AppleBundleDestinations OSX_FRAMEWORK_DESTINATIONS =
@@ -87,6 +91,7 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
8791
OSX_FRAMEWORK_CONTENTS_PATH.resolve("Modules"),
8892
OSX_FRAMEWORK_CONTENTS_PATH.resolve("XPCServices"),
8993
OSX_FRAMEWORK_CONTENTS_PATH,
94+
OSX_FRAMEWORK_CONTENTS_PATH,
9095
OSX_FRAMEWORK_CONTENTS_PATH);
9196

9297
private static final Path IOS_CONTENTS_PATH = Paths.get("");
@@ -102,7 +107,8 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
102107
IOS_CONTENTS_PATH,
103108
IOS_CONTENTS_PATH.resolve("XPCServices"),
104109
IOS_CONTENTS_PATH.resolve("Library/QuickLook"),
105-
IOS_CONTENTS_PATH.resolve("_WatchKitStub"));
110+
IOS_CONTENTS_PATH.resolve("_WatchKitStub"),
111+
IOS_CONTENTS_PATH);
106112

107113
private static final Path IOS_FRAMEWORK_CONTENTS_PATH = Paths.get("");
108114
public static final AppleBundleDestinations IOS_FRAMEWORK_DESTINATIONS =
@@ -117,6 +123,7 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
117123
IOS_FRAMEWORK_CONTENTS_PATH.resolve("Modules"),
118124
IOS_FRAMEWORK_CONTENTS_PATH.resolve("XPCServices"),
119125
IOS_FRAMEWORK_CONTENTS_PATH,
126+
IOS_FRAMEWORK_CONTENTS_PATH,
120127
IOS_FRAMEWORK_CONTENTS_PATH);
121128

122129
public static AppleBundleDestinations platformDestinations(ApplePlatform platform) {

src/com/facebook/buck/apple/AppleResourceBundleDestination.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public enum AppleResourceBundleDestination {
2727
EXECUTABLES,
2828
PLUGINS,
2929
XPCSERVICES,
30-
;
30+
LOGINITEMS;
3131

3232
public static AppleResourceBundleDestination defaultValue() {
3333
return RESOURCES;
@@ -46,6 +46,8 @@ public AppleBundleDestination asGenericDestination() {
4646
return AppleBundleDestination.PLUGINS;
4747
case XPCSERVICES:
4848
return AppleBundleDestination.XPCSERVICES;
49+
case LOGINITEMS:
50+
return AppleBundleDestination.LOGINITEMS;
4951
}
5052
throw new IllegalStateException("Unhandled AppleResourceBundleDestination " + this);
5153
}

src/com/facebook/buck/apple/xcode/xcodeproj/PBXCopyFilesBuildPhase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class PBXCopyFilesBuildPhase extends PBXBuildPhase {
2626
public enum Destination {
2727
ABSOLUTE(0),
2828
WRAPPER(1),
29+
LOGINITEMS(1),
2930
EXECUTABLES(6),
3031
RESOURCES(7),
3132
FRAMEWORKS(10),

src/com/facebook/buck/features/apple/project/NewNativeTargetProjectMutator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ private PBXCopyFilesBuildPhase.Destination pbxCopyPhaseDestination(
666666
return PBXCopyFilesBuildPhase.Destination.PLUGINS;
667667
case XPCSERVICES:
668668
return PBXCopyFilesBuildPhase.Destination.XPC;
669+
case LOGINITEMS:
670+
return PBXCopyFilesBuildPhase.Destination.LOGINITEMS;
669671
}
670672
throw new IllegalStateException("Unhandled AppleResourceBundleDestination " + destination);
671673
}

test/com/facebook/buck/apple/AppleBundleIntegrationTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,21 @@ public void resourcesWithFrameworksDestinationsAreProperlyCopiedOnMacosxPlatform
17721772
Files.isRegularFile(outputPath.resolve("Contents/Frameworks/file.txt")));
17731773
}
17741774

1775+
@Test
1776+
public void resourcesWithLoginitemsDestinationsAreProperlyCopiedOnMacosxPlatform()
1777+
throws IOException {
1778+
ProjectWorkspace workspace =
1779+
TestDataHelper.createProjectWorkspaceForScenario(
1780+
this, "bundle_with_resource_with_logintimes_destination", tmp);
1781+
workspace.setUp();
1782+
Path outputPath =
1783+
workspace.buildAndReturnOutput(
1784+
"//:bundle#macosx-x86_64", "--config", "apple.codesign=/usr/bin/true");
1785+
assertTrue(
1786+
"Resource file should exist in Frameworks directory.",
1787+
Files.isRegularFile(outputPath.resolve("Contents/Library/LoginItems/file.txt")));
1788+
}
1789+
17751790
@Test
17761791
public void resourcesWithExecutablesDestinationsAreProperlyCopiedOnIosPlatform()
17771792
throws IOException {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[repositories]
2+
root_cell = .
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apple_bundle(
2+
name = "bundle",
3+
binary = ":noop",
4+
extension = "bundle",
5+
info_plist = "Info.plist",
6+
deps = [
7+
":file_resource",
8+
],
9+
)
10+
11+
apple_binary(
12+
name = "noop",
13+
srcs = ["main.c"],
14+
)
15+
16+
apple_resource(
17+
name = "file_resource",
18+
destination = "loginitems",
19+
dirs = [],
20+
files = [
21+
"file.txt",
22+
],
23+
visibility = ["PUBLIC"],
24+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
</dict>
6+
</plist>

test/com/facebook/buck/apple/testdata/bundle_with_resource_with_logintimes_destination/file.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)