Skip to content

Commit

Permalink
Add support for LoginItems destination
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Vitalii Topoliuk authored and facebook-github-bot committed Sep 29, 2021
1 parent 0745246 commit cbd1efc
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/com/facebook/buck/apple/AppleBundleDestination.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum AppleBundleDestination {
QUICKLOOK,
WATCHKITSTUB,
BUNDLEROOT,
LOGINITEMS,
;

/**
Expand Down Expand Up @@ -69,6 +70,8 @@ public Path getPath(AppleBundleDestinations destinations) {
return destinations.getWatchKitStubPath();
case BUNDLEROOT:
return Paths.get("");
case LOGINITEMS:
return destinations.getLoginItemsPath();
}
throw new IllegalStateException("Unhandled AppleBundleDestination " + this);
}
Expand Down
11 changes: 9 additions & 2 deletions src/com/facebook/buck/apple/AppleBundleDestinations.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
@AddToRuleKey(stringify = true)
public abstract Path getWatchKitStubPath();

@AddToRuleKey(stringify = true)
public abstract Path getLoginItemsPath();

private static final Path OSX_CONTENTS_PATH = Paths.get("Contents");
public static final AppleBundleDestinations OSX_DESTINATIONS =
ImmutableAppleBundleDestinations.ofImpl(
Expand All @@ -72,7 +75,8 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
OSX_CONTENTS_PATH,
OSX_CONTENTS_PATH.resolve("XPCServices"),
OSX_CONTENTS_PATH.resolve("Library/QuickLook"),
OSX_CONTENTS_PATH);
OSX_CONTENTS_PATH,
OSX_CONTENTS_PATH.resolve("Library/LoginItems"));

private static final Path OSX_FRAMEWORK_CONTENTS_PATH = Paths.get("");
public static final AppleBundleDestinations OSX_FRAMEWORK_DESTINATIONS =
Expand All @@ -87,6 +91,7 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
OSX_FRAMEWORK_CONTENTS_PATH.resolve("Modules"),
OSX_FRAMEWORK_CONTENTS_PATH.resolve("XPCServices"),
OSX_FRAMEWORK_CONTENTS_PATH,
OSX_FRAMEWORK_CONTENTS_PATH,
OSX_FRAMEWORK_CONTENTS_PATH);

private static final Path IOS_CONTENTS_PATH = Paths.get("");
Expand All @@ -102,7 +107,8 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
IOS_CONTENTS_PATH,
IOS_CONTENTS_PATH.resolve("XPCServices"),
IOS_CONTENTS_PATH.resolve("Library/QuickLook"),
IOS_CONTENTS_PATH.resolve("_WatchKitStub"));
IOS_CONTENTS_PATH.resolve("_WatchKitStub"),
IOS_CONTENTS_PATH);

private static final Path IOS_FRAMEWORK_CONTENTS_PATH = Paths.get("");
public static final AppleBundleDestinations IOS_FRAMEWORK_DESTINATIONS =
Expand All @@ -117,6 +123,7 @@ abstract class AppleBundleDestinations implements AddsToRuleKey {
IOS_FRAMEWORK_CONTENTS_PATH.resolve("Modules"),
IOS_FRAMEWORK_CONTENTS_PATH.resolve("XPCServices"),
IOS_FRAMEWORK_CONTENTS_PATH,
IOS_FRAMEWORK_CONTENTS_PATH,
IOS_FRAMEWORK_CONTENTS_PATH);

public static AppleBundleDestinations platformDestinations(ApplePlatform platform) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum AppleResourceBundleDestination {
EXECUTABLES,
PLUGINS,
XPCSERVICES,
;
LOGINITEMS;

public static AppleResourceBundleDestination defaultValue() {
return RESOURCES;
Expand All @@ -46,6 +46,8 @@ public AppleBundleDestination asGenericDestination() {
return AppleBundleDestination.PLUGINS;
case XPCSERVICES:
return AppleBundleDestination.XPCSERVICES;
case LOGINITEMS:
return AppleBundleDestination.LOGINITEMS;
}
throw new IllegalStateException("Unhandled AppleResourceBundleDestination " + this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PBXCopyFilesBuildPhase extends PBXBuildPhase {
public enum Destination {
ABSOLUTE(0),
WRAPPER(1),
LOGINITEMS(1),
EXECUTABLES(6),
RESOURCES(7),
FRAMEWORKS(10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ private PBXCopyFilesBuildPhase.Destination pbxCopyPhaseDestination(
return PBXCopyFilesBuildPhase.Destination.PLUGINS;
case XPCSERVICES:
return PBXCopyFilesBuildPhase.Destination.XPC;
case LOGINITEMS:
return PBXCopyFilesBuildPhase.Destination.LOGINITEMS;
}
throw new IllegalStateException("Unhandled AppleResourceBundleDestination " + destination);
}
Expand Down
15 changes: 15 additions & 0 deletions test/com/facebook/buck/apple/AppleBundleIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,21 @@ public void resourcesWithFrameworksDestinationsAreProperlyCopiedOnMacosxPlatform
Files.isRegularFile(outputPath.resolve("Contents/Frameworks/file.txt")));
}

@Test
public void resourcesWithLoginitemsDestinationsAreProperlyCopiedOnMacosxPlatform()
throws IOException {
ProjectWorkspace workspace =
TestDataHelper.createProjectWorkspaceForScenario(
this, "bundle_with_resource_with_logintimes_destination", tmp);
workspace.setUp();
Path outputPath =
workspace.buildAndReturnOutput(
"//:bundle#macosx-x86_64", "--config", "apple.codesign=/usr/bin/true");
assertTrue(
"Resource file should exist in Frameworks directory.",
Files.isRegularFile(outputPath.resolve("Contents/Library/LoginItems/file.txt")));
}

@Test
public void resourcesWithExecutablesDestinationsAreProperlyCopiedOnIosPlatform()
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[repositories]
root_cell = .
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apple_bundle(
name = "bundle",
binary = ":noop",
extension = "bundle",
info_plist = "Info.plist",
deps = [
":file_resource",
],
)

apple_binary(
name = "noop",
srcs = ["main.c"],
)

apple_resource(
name = "file_resource",
destination = "loginitems",
dirs = [],
files = [
"file.txt",
],
visibility = ["PUBLIC"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?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>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(int argc, char *argv[]) {
return 0;
}

0 comments on commit cbd1efc

Please sign in to comment.