Skip to content
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

Don't generate CFBundleExecutable for targets of type bundle #689

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Fixed
- Add base localisation by default even if no base localised files were found. Fixes warning in Xcode 11 [#685](https://github.com/yonaskolb/XcodeGen/pull/685) @yonaskolb
- Don't generate CFBundleExecutable for target of type `bundle` @FranzBusch

## 2.9.0

Expand Down
4 changes: 2 additions & 2 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ Settings are merged in the following order: groups, base, configs.
- `TEST_TARGET_NAME`: for ui tests that target an application
- `TEST_HOST`: for unit tests that target an application
- [ ] **dependencies**: **[[Dependency](#dependency)]** - Dependencies for the target
- [ ] **info**: **[Plist](#plist)** - If defined, this will generate and write an `Info.plist` to the specified path and use it by setting the `INFOPLIST_FILE` build setting for every configuration, unless `INFOPLIST_FILE` is already defined in **settings** for this configuration. The following properties are generated automatically, the rest will have to be provided.
- [ ] **info**: **[Plist](#plist)** - If defined, this will generate and write an `Info.plist` to the specified path and use it by setting the `INFOPLIST_FILE` build setting for every configuration, unless `INFOPLIST_FILE` is already defined in **settings** for this configuration. The following properties are generated automatically if appropriate, the rest will have to be provided.
- `CFBundleIdentifier`
- `CFBundleInfoDictionaryVersion`
- `CFBundleExecutable`
- `CFBundleExecutable` **Not generated for targets of type bundle**
- `CFBundleName`
- `CFBundleDevelopmentRegion`
- `CFBundleShortVersionString`
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeGenKit/FileWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FileWriter {
for target in project.targets {
// write Info.plist
if let plist = target.info {
let properties = infoPlistGenerator.generateProperties(target: target).merged(plist.properties)
let properties = infoPlistGenerator.generateProperties(for: target).merged(plist.properties)
try writePlist(properties, path: plist.path)
}

Expand Down
16 changes: 11 additions & 5 deletions Sources/XcodeGenKit/InfoPlistGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ public class InfoPlistGenerator {
Default info plist attributes taken from:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Base/Base_DefinitionsInfoPlist.xctemplate/TemplateInfo.plist
*/
var defaultInfoPlist: [String: Any] = {
private func generateDefaultInfoPlist(for target: Target) -> [String: Any] {
var dictionary: [String: Any] = [:]
dictionary["CFBundleIdentifier"] = "$(PRODUCT_BUNDLE_IDENTIFIER)"
dictionary["CFBundleInfoDictionaryVersion"] = "6.0"
dictionary["CFBundleExecutable"] = "$(EXECUTABLE_NAME)"

dictionary["CFBundleName"] = "$(PRODUCT_NAME)"
dictionary["CFBundleDevelopmentRegion"] = "$(DEVELOPMENT_LANGUAGE)"
dictionary["CFBundleShortVersionString"] = "1.0"
dictionary["CFBundleVersion"] = "1"

// Bundles should not contain any CFBundleExecutable otherwise they will be rejected when uploading.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you update ProjectSpec documentation too?
https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#target

The following properties are generated automatically

if target.type != .bundle {
dictionary["CFBundleExecutable"] = "$(EXECUTABLE_NAME)"
}

return dictionary
}()
}

public func generateProperties(target: Target) -> [String: Any] {
var targetInfoPlist = defaultInfoPlist
public func generateProperties(for target: Target) -> [String: Any] {
var targetInfoPlist = generateDefaultInfoPlist(for: target)
switch target.type {
case .uiTestBundle,
.unitTestBundle:
Expand Down
51 changes: 41 additions & 10 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -971,16 +971,17 @@ class ProjectGeneratorTests: XCTestCase {
let infoPlistFile = tempPath + plist.path
let data: Data = try infoPlistFile.read()
let infoPlist = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String: Any]
var expectedInfoPlist: [String: Any] = [:]
expectedInfoPlist["CFBundleIdentifier"] = "$(PRODUCT_BUNDLE_IDENTIFIER)"
expectedInfoPlist["CFBundleInfoDictionaryVersion"] = "6.0"
expectedInfoPlist["CFBundleExecutable"] = "$(EXECUTABLE_NAME)"
expectedInfoPlist["CFBundleName"] = "$(PRODUCT_NAME)"
expectedInfoPlist["CFBundleDevelopmentRegion"] = "$(DEVELOPMENT_LANGUAGE)"
expectedInfoPlist["CFBundleShortVersionString"] = "1.0"
expectedInfoPlist["CFBundleVersion"] = "1"
expectedInfoPlist["CFBundlePackageType"] = "APPL"
expectedInfoPlist["UISupportedInterfaceOrientations"] = ["UIInterfaceOrientationPortrait", "UIInterfaceOrientationLandscapeLeft"]
let expectedInfoPlist: [String: Any] = [
"CFBundleIdentifier": "$(PRODUCT_BUNDLE_IDENTIFIER)",
"CFBundleInfoDictionaryVersion": "6.0",
"CFBundleName": "$(PRODUCT_NAME)",
"CFBundleExecutable": "$(EXECUTABLE_NAME)",
"CFBundleDevelopmentRegion": "$(DEVELOPMENT_LANGUAGE)",
"CFBundleShortVersionString": "1.0",
"CFBundleVersion": "1",
"CFBundlePackageType": "APPL",
"UISupportedInterfaceOrientations": ["UIInterfaceOrientationPortrait", "UIInterfaceOrientationLandscapeLeft"]
]

try expect(NSDictionary(dictionary: expectedInfoPlist).isEqual(to: infoPlist)).beTrue()
}
Expand All @@ -1002,6 +1003,36 @@ class ProjectGeneratorTests: XCTestCase {
// generated plist should not be in buildsettings
try expect(targetConfig.buildSettings["INFOPLIST_FILE"] as? String) == predefinedPlistPath
}

$0.it("generate info.plist doesn't generate CFBundleExecutable for targets with type bundle") {
let plist = Plist(path: "Info.plist", attributes: [:])
let tempPath = Path.temporary + "info"
let project = Project(basePath: tempPath, name: "", targets: [Target(name: "", type: .bundle, platform: .iOS, info: plist)])
let pbxProject = try project.generatePbxProj()
let writer = FileWriter(project: project)
try writer.writePlists()

guard let targetConfig = pbxProject.nativeTargets.first?.buildConfigurationList?.buildConfigurations.first else {
throw failure("Couldn't find Target config")
}

try expect(targetConfig.buildSettings["INFOPLIST_FILE"] as? String) == plist.path

let infoPlistFile = tempPath + plist.path
let data: Data = try infoPlistFile.read()
let infoPlist = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String: Any]
let expectedInfoPlist: [String: Any] = [
"CFBundleIdentifier": "$(PRODUCT_BUNDLE_IDENTIFIER)",
"CFBundleInfoDictionaryVersion": "6.0",
"CFBundleName": "$(PRODUCT_NAME)",
"CFBundleDevelopmentRegion": "$(DEVELOPMENT_LANGUAGE)",
"CFBundleShortVersionString": "1.0",
"CFBundleVersion": "1",
"CFBundlePackageType": "BNDL"
]

try expect(NSDictionary(dictionary: expectedInfoPlist).isEqual(to: infoPlist)).beTrue()
}
}
}
}