-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Ensure resource bundles aren't marked as executable #9354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // swift-tools-version:5.3 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "TIF", | ||
| products: [ | ||
| .library(name: "TIF", targets: ["TIF"]) | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "TIF", | ||
| resources: [ | ||
| .copy("some.txt") | ||
| ] | ||
| ), | ||
| ] | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # TIF | ||
|
|
||
| A description of this package. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // | ||
| // SomeAlert.swift | ||
| // MyFwk | ||
| // | ||
| // Created by ankit on 10/31/19. | ||
| // Copyright © 2019 Ankit. All rights reserved. | ||
| // | ||
|
|
||
| import Cocoa | ||
|
|
||
| public class SomeAlert: NSViewController { | ||
|
|
||
| @IBOutlet var label: NSTextField! | ||
|
|
||
| override public func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| let bundlePath = Bundle.main.path(forResource: "TIF_TIF", ofType: "bundle")! | ||
| let bundle = Bundle(path: bundlePath)! | ||
|
|
||
| let txt = bundle.path(forResource: "some", ofType: "txt")! | ||
| let c = FileManager.default.contents(atPath: txt)! | ||
|
|
||
| label.stringValue = String(data:c, encoding: .utf8)! | ||
| // Do view setup here. | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14850.00" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> | ||
| <dependencies> | ||
| <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14850.00"/> | ||
| <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
| </dependencies> | ||
| <objects> | ||
| <customObject id="-2" userLabel="File's Owner" customClass="SomeAlert" customModule="MyFwk" customModuleProvider="target"> | ||
| <connections> | ||
| <outlet property="label" destination="AaI-7f-Hna" id="9Qf-KY-ZKZ"/> | ||
| <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/> | ||
| </connections> | ||
| </customObject> | ||
| <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | ||
| <customObject id="-3" userLabel="Application" customClass="NSObject"/> | ||
| <customView id="Hz6-mo-xeY"> | ||
| <rect key="frame" x="0.0" y="0.0" width="800" height="521"/> | ||
| <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | ||
| <subviews> | ||
| <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="PbM-Nr-mVI"> | ||
| <rect key="frame" x="0.0" y="0.0" width="800" height="521"/> | ||
| <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="this_is_fine" id="oAz-HJ-kbb"/> | ||
| </imageView> | ||
| <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AaI-7f-Hna"> | ||
| <rect key="frame" x="373" y="10" width="37" height="16"/> | ||
| <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="8Nf-Ba-Sor"> | ||
| <font key="font" metaFont="system"/> | ||
| <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> | ||
| <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> | ||
| </textFieldCell> | ||
| </textField> | ||
| </subviews> | ||
| <constraints> | ||
| <constraint firstItem="PbM-Nr-mVI" firstAttribute="centerY" secondItem="Hz6-mo-xeY" secondAttribute="centerY" id="6qc-mk-w7c"/> | ||
| <constraint firstItem="PbM-Nr-mVI" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="7oF-4c-nPi"/> | ||
| <constraint firstAttribute="trailing" secondItem="PbM-Nr-mVI" secondAttribute="trailing" id="Ixf-fF-M1X"/> | ||
| <constraint firstItem="AaI-7f-Hna" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="375" id="cSk-iC-InE"/> | ||
| <constraint firstItem="AaI-7f-Hna" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="495" id="ikr-Qp-hYt"/> | ||
| <constraint firstItem="PbM-Nr-mVI" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="pbz-et-fp8"/> | ||
| <constraint firstAttribute="bottom" secondItem="AaI-7f-Hna" secondAttribute="bottom" constant="10" id="pwH-7O-7xL"/> | ||
| <constraint firstItem="PbM-Nr-mVI" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="tzP-BG-gDa"/> | ||
| </constraints> | ||
| <point key="canvasLocation" x="139" y="189.5"/> | ||
| </customView> | ||
| </objects> | ||
| <resources> | ||
| <image name="this_is_fine" width="800" height="450"/> | ||
| </resources> | ||
| </document> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "this_is_fine.jpg", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| This is being read from some.txt file in the bundle. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,9 @@ struct PackagePIFProjectBuilder { | |
| settings[.PRODUCT_MODULE_NAME] = bundleName | ||
| settings[.PRODUCT_BUNDLE_IDENTIFIER] = "\(self.package.identity).\(module.name).resources" | ||
| .spm_mangledToBundleIdentifier() | ||
| // Resource bundles are not executable. Setting the name to an empty string will | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CFBundleExecutable doesn't mean the binary is executable per se. It's present if the bundle has an executable (which could be a dylib). Was this found to cause an actual problem somewhere, or just speculative? |
||
| // omit the CFBundleExecutable key from the Info.plist. | ||
| settings[.EXECUTABLE_NAME] = "" | ||
plemarquand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| settings[.GENERATE_INFOPLIST_FILE] = "YES" | ||
| settings[.PACKAGE_RESOURCE_TARGET_KIND] = "resource" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1760,6 +1760,45 @@ struct BuildCommandTestCases { | |
| data.config == .release | ||
| } | ||
| } | ||
|
|
||
| @Test( | ||
| .requireHostOS(.macOS), | ||
| .tags( | ||
| .Feature.CommandLineArguments.BuildSystem, | ||
| .Feature.CommandLineArguments.Configuration, | ||
| ), | ||
| arguments: getBuildData(for: [.swiftbuild]), | ||
| ) | ||
| func trivialPackageResources( | ||
| data: BuildData, | ||
| ) async throws { | ||
| let buildSystem = data.buildSystem | ||
| try await fixture(name: "Miscellaneous/TIF") { fixturePath in | ||
| let result = try await build( | ||
| [], | ||
| packagePath: fixturePath, | ||
| configuration: data.config, | ||
| cleanAfterward: false, | ||
| buildSystem: buildSystem, | ||
| ) | ||
| try #require(result.binContents.contains("TIF_TIF.bundle")) | ||
| let contentsDir = result.binPath.appending("TIF_TIF.bundle", "Contents") | ||
| let bundleResourceDir = contentsDir.appending("Resources") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: is there value is validating this path exists so we can have "better" message in the event it does not? |
||
|
|
||
| let bundleResources = try localFileSystem.getDirectoryContents(bundleResourceDir) | ||
| #expect(bundleResources.contains("some.txt")) | ||
| #expect(bundleResources.contains("Assets.car")) | ||
| #expect(bundleResources.contains("SomeAlert.nib")) | ||
|
|
||
| // Check that the Info.plist of the resource bundle looks reasonable. In particular, it shouldn't have a CFBundleExecutable key, since it's a codeless bundle. | ||
| let infoPlistPath = contentsDir.appending("Info.plist") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: SwiftPM has no control over the contents of the info.plist file. As a result, changes to the SwiftBuild service can impact this test. Can we move the intent of this test to SwiftBuild?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SwiftPM does have control depending on what build settings it passes down to swift-build. This PR is not test only, it reverts a line of code that changed the structure of the Info.plist in resource bundles. |
||
| let infoPlistBytes = try localFileSystem.readFileContents(infoPlistPath) | ||
| let infoPlist = try infoPlistBytes.withData({ | ||
| try #require(PropertyListSerialization.propertyList(from: $0, options: [], format: nil) as? NSDictionary, "couldn't parse built resource bundle's Info.plist as a property list") | ||
| }) | ||
| #expect(infoPlist["CFBundleExecutable"] == nil, "Expected CFBundleExecutable to be omitted from the Info.plist of a codeless resource bundle") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension Triple { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest: can we rename "TIF" with something more descriptive?