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 require xcodegen settings preset files. All configuration shoul… #84

Merged
merged 1 commit into from
Oct 17, 2018
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 Sources/XCHammer/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ enum Generator {
let options = SpecOptions(
carthageBuildPath: nil,
createIntermediateGroups: true,
settingPresets: .none,
indentWidth: 4,
tabWidth: 4,
usesTabs: false
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCHammer/OrderedArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct OrderedArray<T: Hashable>: Sequence {

extension OrderedArray: ExpressibleByArrayLiteral {
typealias ArrayLiteralElement = Element

init(arrayLiteral elements: T...) {
self.init(elements)
}
Expand Down
17 changes: 16 additions & 1 deletion Sources/XCHammer/XCBuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ struct Setting<T: XCSettingStringEncodeable & Semigroup>: Semigroup {
}
}




struct XCBuildSettings: Encodable {
var copts: [String] = []
var productName: First<String>?
Expand Down Expand Up @@ -163,6 +166,11 @@ struct XCBuildSettings: Encodable {
var useHeaderMap: First<String>? = First("NO")
var testTargetName: First<String>?
var pythonPath: First<String>?
var sdkRoot: First<String>?
var targetedDeviceFamily: OrderedArray<String> = OrderedArray.empty
Copy link
Contributor

Choose a reason for hiding this comment

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

What's an OrderedArray?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ordered array is poorly named, it's basically an implementation of ordered set that conform to a few protocols used to serialize build settings. We wanted uniqueness with consistent ordering which is why this was originally written, happy to revisit


Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: remove spaces?




enum CodingKeys: String, CodingKey {
// Add to this list the known XCConfig keys
Expand Down Expand Up @@ -201,6 +209,9 @@ struct XCBuildSettings: Encodable {
case codeSignEntitlementsFile = "HAMMER_ENTITLEMENTS_FILE"
case mobileProvisionProfileFile = "HAMMER_PROFILE_FILE"
case tulsiWR = "TULSI_WR"
case sdkRoot = "SDKROOT"
case targetedDeviceFamily = "TARGETED_DEVICE_FAMILY"

}

func encode(to encoder: Encoder) throws {
Expand Down Expand Up @@ -244,6 +255,8 @@ struct XCBuildSettings: Encodable {
try useHeaderMap.map { try container.encode($0.v, forKey: .useHeaderMap) }
try testTargetName.map { try container.encode($0.v, forKey: .testTargetName) }
try pythonPath.map { try container.encode($0.v, forKey: .pythonPath) }
try sdkRoot.map { try container.encode($0.v, forKey: .sdkRoot) }
try container.encode(targetedDeviceFamily.joined(separator: ","), forKey: .targetedDeviceFamily)

// XCHammer only supports Xcode projects at the root directory
try container.encode("$SOURCE_ROOT", forKey: .tulsiWR)
Expand Down Expand Up @@ -288,7 +301,9 @@ extension XCBuildSettings: Monoid {
moduleMapFile: lhs.moduleMapFile <> rhs.moduleMapFile,
useHeaderMap: lhs.useHeaderMap <> rhs.useHeaderMap,
testTargetName: lhs.testTargetName <> rhs.testTargetName,
pythonPath: lhs.pythonPath <> rhs.pythonPath
pythonPath: lhs.pythonPath <> rhs.pythonPath,
sdkRoot: lhs.sdkRoot <> rhs.sdkRoot,
targetedDeviceFamily: lhs.targetedDeviceFamily <> rhs.targetedDeviceFamily
)
}

Expand Down
46 changes: 32 additions & 14 deletions Sources/XCHammer/XcodeTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public class XcodeTarget: Hashable, Equatable {
.map { sourceInfo -> String in
return self.getRelativePath(for: sourceInfo)
}

// This is a massive error if this will not allocate with a string.
let sourceFiles = sourceFilePaths
.filter { !$0.hasSuffix(".modulemap") && !$0.hasSuffix(".hmap") }
Expand Down Expand Up @@ -338,7 +338,7 @@ public class XcodeTarget: Hashable, Equatable {
return []
}
var visited: Set<XcodeTarget> = [self]

var transitiveTargets: [XcodeTarget] = []
var queue = unfilteredDependencies
while let xcodeTarget = queue.first {
Expand All @@ -365,7 +365,7 @@ public class XcodeTarget: Hashable, Equatable {

func makePathFiltersTransitionPredicate(paths: Set<String>) -> TraversalTransitionPredicate<XcodeTarget> {
let pathPredicate = makePathFiltersPredicate(paths)
return TraversalTransitionPredicate { xcodeTarget -> Transition in
return TraversalTransitionPredicate { xcodeTarget -> Transition in
guard let buildFilePath = xcodeTarget.buildFilePath else {
fatalError()
}
Expand Down Expand Up @@ -457,7 +457,7 @@ public class XcodeTarget: Hashable, Equatable {
case .StaticLibrary:
return xcTargetName
default:
fatalError()
return "$(TARGET_NAME)"
}
}

Expand Down Expand Up @@ -599,8 +599,14 @@ public class XcodeTarget: Hashable, Equatable {
}

// Product Name

settings.productName <>= self.bundleName.map { First($0) }

if settings.productName == nil {
settings.productName = First(self.extractBuiltProductName())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this code path ever be hit? It doesn't seem like it if you set the value in the initializer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it will now that there isn't a default value

}


// Product Bundle Identifier
settings.productBundleId <>= self.bundleID.map { First($0) }

Expand Down Expand Up @@ -645,13 +651,24 @@ public class XcodeTarget: Hashable, Equatable {
// Set thes deployment target if available
if let deploymentTgt = self.deploymentTarget {
switch deploymentTgt.platform {
case .ios: settings.iOSDeploymentTarget <>= First(deploymentTgt.osVersion)
case .tvos: settings.tvOSDeploymentTarget <>= First(deploymentTgt.osVersion)
case .watchos: settings.watchOSDeploymentTarget <>= First(deploymentTgt.osVersion)
case .macos: settings.macOSDeploymentTarget <>= First(deploymentTgt.osVersion)
case .ios:
settings.iOSDeploymentTarget <>= First(deploymentTgt.osVersion)
settings.sdkRoot <>= First("iphoneos")
settings.targetedDeviceFamily <>= ["1", "2"]
case .tvos:
settings.tvOSDeploymentTarget <>= First(deploymentTgt.osVersion)
settings.sdkRoot <>= First("appletvos")
settings.targetedDeviceFamily <>= ["3"]
case .watchos:
settings.watchOSDeploymentTarget <>= First(deploymentTgt.osVersion)
settings.sdkRoot <>= First("watchos")
settings.targetedDeviceFamily <>= ["4"]
case .macos:
settings.macOSDeploymentTarget <>= First(deploymentTgt.osVersion)
settings.sdkRoot <>= First("macosx")
}
}

// Add defines as copts
settings.copts <>= processDefines(defines: self.extractDefines(map: targetMap))

Expand Down Expand Up @@ -826,7 +843,7 @@ public class XcodeTarget: Hashable, Equatable {
bundle_id = "\(bundleID)",
platform_type = \"ios\"
)
"""
"""
}
}

Expand All @@ -848,7 +865,7 @@ public class XcodeTarget: Hashable, Equatable {
entitlements: entitlements,
provisioningProfile: provisioningProfile,
bundleID: bundleID)
return exportEntitlements
return exportEntitlements
}

func extractCodeSignEntitlementsFile(genOptions: XCHammerGenerateOptions) -> String? {
Expand Down Expand Up @@ -936,7 +953,7 @@ public class XcodeTarget: Hashable, Equatable {
// Assume extensions are contained in the same workspace
return extensions
.compactMap { targetMap.xcodeTarget(buildLabel: $0, depender: self) }
.map {
.map {
var mutableDep = ProjectSpec.Dependency(type: .target, reference: $0.xcTargetName,
embed: $0.isExtension)
mutableDep.codeSign = false
Expand Down Expand Up @@ -989,6 +1006,7 @@ public class XcodeTarget: Hashable, Equatable {
]

guard let productType = BuildTypeToTargetType[self.type] else {
print("Unknown product type: \(self.type). Unable to extract xcode equivalent")
return nil
}
return productType
Expand Down Expand Up @@ -1049,7 +1067,7 @@ public class XcodeTarget: Hashable, Equatable {
// Minimal settings for this build
var settings = XCBuildSettings()
settings.codeSigningRequired <>= First("NO")

settings.productName <>= First("$(TARGET_NAME)")
// A custom XCHammerAsset bazel_build_settings.py is loaded by bazel_build.py
settings.pythonPath =
First("${PYTHONPATH}:$(PROJECT_FILE_PATH)/XCHammerAssets")
Expand Down Expand Up @@ -1199,7 +1217,7 @@ public func makeXcodeGenTarget(from xcodeTarget: XcodeTarget) -> ProjectSpec.Tar
return "iOS"
}
}(xcodeTarget)

return ProjectSpec.Target(
name: xcodeTarget.xcTargetName,
type: PBXProductType(rawValue: productType.rawValue)!,
Expand Down
4 changes: 2 additions & 2 deletions sample/Frankenstein/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ objc_library(
"//Vendor/React:Core",
"//Vendor/React:CxxBridge",
"//Vendor/React:DevSupport",
"//Vendor/React:RCTAnimation",
"//Vendor/React:RCTImage",
"//Vendor/React:RCTNetwork",
"//Vendor/React:RCTText",
"//Vendor/React:RCTWebSocket",
"//Vendor/React:RCTAnimation",
"//Vendor/Yoga:Yoga"
"//Vendor/Yoga",
],
)
46 changes: 21 additions & 25 deletions sample/UrlGet/UrlGet.xcodeproj/XCHammerAssets/BUILD
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
load("//UrlGet.xcodeproj/XCHammerAssets:Hammer.bzl", "export_entitlements")

export_entitlements(
name = "ios-app-share-extension_entitlements",
bundle_id = "Google.UrlGet.ShareExtension",
entitlements = None,
platform_type = "ios",
provisioning_profile = None,
name = "ios-app-strings-extension_entitlements",
entitlements = None,
provisioning_profile = None,
bundle_id = "Google.UrlGet.StringsExtension",
platform_type = "ios"
)

export_entitlements(
name = "ios-app-strings-extension_entitlements",
bundle_id = "Google.UrlGet.StringsExtension",
entitlements = None,
platform_type = "ios",
provisioning_profile = None,
name = "ios-app-ios-app_entitlements",
entitlements = None,
provisioning_profile = None,
bundle_id = "Google.UrlGet",
platform_type = "ios"
)

export_entitlements(
name = "ios-app-siri-extension_entitlements",
bundle_id = "Google.UrlGet.SiriExtension",
entitlements = None,
platform_type = "ios",
provisioning_profile = None,
name = "ios-app-share-extension_entitlements",
entitlements = None,
provisioning_profile = None,
bundle_id = "Google.UrlGet.ShareExtension",
platform_type = "ios"
)

export_entitlements(
name = "ios-app-ios-app_entitlements",
bundle_id = "Google.UrlGet",
entitlements = None,
platform_type = "ios",
provisioning_profile = None,
)
name = "ios-app-siri-extension_entitlements",
entitlements = None,
provisioning_profile = None,
bundle_id = "Google.UrlGet.SiriExtension",
platform_type = "ios"
)
1 change: 1 addition & 0 deletions sample/UrlGet/UrlGet.xcodeproj/XCHammerAssets/Hammer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ def export_entitlements(
name = name,
entitlements = ":" + name + "_exported",
visibility = ["//visibility:public"],
tags = ["xchammer"],
)
Loading