Skip to content

Commit

Permalink
Merge pull request #67 from yonaskolb/bundleIdPrefix
Browse files Browse the repository at this point in the history
Add bundleIdPrefix
  • Loading branch information
yonaskolb authored Sep 25, 2017
2 parents 829fb59 + d20d6b5 commit 658c3f8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
10 changes: 6 additions & 4 deletions Fixtures/TestProject/GeneratedProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.framework;
PRODUCT_BUNDLE_IDENTIFIER = com.test.MyFramework;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -409,7 +409,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.application;
PRODUCT_BUNDLE_IDENTIFIER = com.test.TestProject;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -483,6 +483,7 @@
"$(inherited)",
"@executable_path/Frameworks @loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.TestProjectTests;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestProject.app/TestProject";
Expand All @@ -500,7 +501,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.application;
PRODUCT_BUNDLE_IDENTIFIER = com.test.TestProject;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -566,6 +567,7 @@
"$(inherited)",
"@executable_path/Frameworks @loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.TestProjectTests;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestProject.app/TestProject";
Expand All @@ -586,7 +588,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.framework;
PRODUCT_BUNDLE_IDENTIFIER = com.test.MyFramework;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
Expand Down
4 changes: 2 additions & 2 deletions Fixtures/TestProject/spec.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: GeneratedProject
options:
bundleIdPrefix: com.test
fileGroups:
- Configs
targets:
Expand All @@ -8,7 +10,6 @@ targets:
sources: TestProject
settings:
INFOPLIST_FILE: TestProject/Info.plist
PRODUCT_BUNDLE_IDENTIFIER: com.test.application
dependencies:
- target: MyFramework
scheme:
Expand All @@ -33,7 +34,6 @@ targets:
sources: MyFramework
settings:
INFOPLIST_FILE: MyFramework/Info.plist
PRODUCT_BUNDLE_IDENTIFIER: com.test.framework
postbuildScripts:
- name: Swiftlint
path: scripts/swiftlint.sh
Expand Down
9 changes: 6 additions & 3 deletions Sources/ProjectSpec/ProjectSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ public struct ProjectSpec {

public struct Options {
public var carthageBuildPath: String?
public var bundleIdPrefix: String?

public init() {

public init(carthageBuildPath: String? = nil) {
self.carthageBuildPath = carthageBuildPath
}
}

Expand Down Expand Up @@ -88,7 +89,8 @@ extension ProjectSpec: Equatable {
lhs.schemes == rhs.schemes &&
lhs.fileGroups == rhs.fileGroups &&
lhs.configFiles == rhs.configFiles &&
lhs.options == rhs.options
lhs.options == rhs.options &&
NSDictionary(dictionary: lhs.attributes).isEqual(to: rhs.attributes)
}
}

Expand Down Expand Up @@ -130,5 +132,6 @@ extension ProjectSpec.Options: JSONObjectConvertible {

public init(jsonDictionary: JSONDictionary) throws {
carthageBuildPath = jsonDictionary.json(atKeyPath: "carthageBuildPath")
bundleIdPrefix = jsonDictionary.json(atKeyPath: "bundleIdPrefix")
}
}
4 changes: 4 additions & 0 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public class PBXProjGenerator {
buildSettings["INFOPLIST_FILE"] = plistPath.byRemovingBase(path: basePath)
}

if let bundleIdPrefix = spec.options.bundleIdPrefix, !spec.targetHasBuildSetting("PRODUCT_BUNDLE_IDENTIFIER", basePath: basePath, target: target, config: config) {
buildSettings["PRODUCT_BUNDLE_IDENTIFIER"] = bundleIdPrefix + "." + target.name
}

// set Carthage search paths
if !carthageFrameworks.isEmpty {
let frameworkSearchPaths = "FRAMEWORK_SEARCH_PATHS"
Expand Down
17 changes: 17 additions & 0 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ func projectGeneratorTests() {

let targets = [application, framework]

$0.describe("Options") {

$0.it("generates bundle id") {
var options = ProjectSpec.Options()
options.bundleIdPrefix = "com.test"
let spec = ProjectSpec(name: "test", targets: [framework], options: options)
let project = try getProject(spec)
guard let target = project.pbxproj.nativeTargets.first,
let buildConfigs = project.pbxproj.configurationLists.getReference(target.buildConfigurationList),
let buildConfigReference = buildConfigs.buildConfigurations.first,
let buildConfig = project.pbxproj.buildConfigurations.getReference(buildConfigReference) else {
throw failure("Build Config not found")
}
try expect(buildConfig.buildSettings["PRODUCT_BUNDLE_IDENTIFIER"] as? String) == "com.test.MyFramework"
}
}

$0.describe("Config") {

$0.it("generates config defaults") {
Expand Down
7 changes: 5 additions & 2 deletions Tests/XcodeGenKitTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ func specLoadingTests() {
}

$0.it("parses options") {
let expected = ProjectSpec(name: "test", options: .init(carthageBuildPath: "../Carthage/Build"))
let parsedSpec = try getProjectSpec(["options": ["carthageBuildPath": "../Carthage/Build"]])
var options = ProjectSpec.Options()
options.carthageBuildPath = "../Carthage/Build"
options.bundleIdPrefix = "com.test"
let expected = ProjectSpec(name: "test", options: options)
let parsedSpec = try getProjectSpec(["options": ["carthageBuildPath": "../Carthage/Build", "bundleIdPrefix": "com.test"]])
try expect(parsedSpec) == expected
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Required properties are marked 🔵 and optional properties with ⚪️.

### Options
- ⚪️ **carthageBuildPath**: `String` - The path to the carthage build directory. Defaults to `Carthage/Build`. This is used when specifying target carthage dependencies
- ⚪️ **bundleIdPrefix**: `String` - If this is specified then any target that doesn't have an `PRODUCT_BUNDLE_IDENTIFIER` (via all levels of build settings) will get an autogenerated one by combining `bundleIdPrefix` and the target name: `bundleIdPrefix.name`

### Configs
Each config maps to a build type of either `debug` or `release` which will then apply default build settings. Any value other than `debug` or `release` (for example "none"), will mean no default build settings will be applied.
Expand Down

0 comments on commit 658c3f8

Please sign in to comment.