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

Add support for Xcode 10 inputFileListPaths and outputFileListPaths #271

Merged
merged 2 commits into from
Jun 20, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## next version

### Changed
- **Breaking** Rename `filesReferences` to `fileReferences` https://github.com/xcode-project-manager/xcodeproj/pull/271 by @pepibumur

### Added
- Xcode 10 inputFileListPaths and outputFileListPaths attributes https://github.com/xcode-project-manager/xcodeproj/pull/271 by @pepibumur

## 5.0.0-rc1

### Breaking
Expand Down
6 changes: 4 additions & 2 deletions Sources/xcodeproj/Equality.generated.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated using Sourcery 0.11.2 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 0.13.1 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

import Foundation
Expand Down Expand Up @@ -26,7 +26,9 @@ extension PBXBuildPhase {
@objc public override func isEqual(to object: Any?) -> Bool {
guard let rhs = object as? PBXBuildPhase else { return false }
if buildActionMask != rhs.buildActionMask { return false }
if filesReferences != rhs.filesReferences { return false }
if fileReferences != rhs.fileReferences { return false }
if inputFileListPaths != rhs.inputFileListPaths { return false }
if outputFileListPaths != rhs.outputFileListPaths { return false }
if runOnlyForDeploymentPostprocessing != rhs.runOnlyForDeploymentPostprocessing { return false }
return super.isEqual(to: rhs)
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/xcodeproj/PBXBuildFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ extension PBXBuildFile {
/// - Throws: an error if this method is called before the build file is added to any project.
func buildPhaseType() throws -> BuildPhase? {
let projectObjects = try objects()
if projectObjects.sourcesBuildPhases.contains(where: { _, val in val.filesReferences.map({ $0.value }).contains(reference.value) }) {
if projectObjects.sourcesBuildPhases.contains(where: { _, val in val.fileReferences.map({ $0.value }).contains(reference.value) }) {
return .sources
} else if projectObjects.frameworksBuildPhases
.contains(where: { _, val in val.filesReferences.map({ $0.value }).contains(reference.value) }) {
.contains(where: { _, val in val.fileReferences.map({ $0.value }).contains(reference.value) }) {
return .frameworks
} else if projectObjects.resourcesBuildPhases.contains(where: { _, val in val.filesReferences.map({ $0.value }).contains(reference.value) }) {
} else if projectObjects.resourcesBuildPhases.contains(where: { _, val in val.fileReferences.map({ $0.value }).contains(reference.value) }) {
return .resources
} else if projectObjects.copyFilesBuildPhases.contains(where: { _, val in val.filesReferences.map({ $0.value }).contains(reference.value) }) {
} else if projectObjects.copyFilesBuildPhases.contains(where: { _, val in val.fileReferences.map({ $0.value }).contains(reference.value) }) {
return .copyFiles
} else if projectObjects.headersBuildPhases.contains(where: { _, val in val.filesReferences.map({ $0.value }).contains(reference.value) }) {
} else if projectObjects.headersBuildPhases.contains(where: { _, val in val.fileReferences.map({ $0.value }).contains(reference.value) }) {
return .headers
} else if projectObjects.carbonResourcesBuildPhases
.contains(where: { _, val in val.filesReferences.map({ $0.value }).contains(reference.value) }) {
.contains(where: { _, val in val.fileReferences.map({ $0.value }).contains(reference.value) }) {
return .carbonResources
}
return nil
Expand All @@ -101,7 +101,7 @@ extension PBXBuildFile {
let projectObjects = try objects()
switch type {
case .copyFiles?:
return projectObjects.copyFilesBuildPhases.first(where: { _, val in val.filesReferences.contains(self.reference) })?.value.name ?? type?.rawValue
return projectObjects.copyFilesBuildPhases.first(where: { _, val in val.fileReferences.contains(self.reference) })?.value.name ?? type?.rawValue
default:
return type?.rawValue
}
Expand Down
38 changes: 30 additions & 8 deletions Sources/xcodeproj/PBXBuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ public class PBXBuildPhase: PBXContainerItem {
public var buildActionMask: UInt

/// Element files references.
public var filesReferences: [PBXObjectReference]
public var fileReferences: [PBXObjectReference]

/// Paths to the input file lists.
/// Note: Introduced in Xcode 10
public var inputFileListPaths: [String]?

/// Paths to the output file lists.
/// Note: Introduced in Xcode 10
public var outputFileListPaths: [String]?

/// Element run only for deployment post processing value.
public var runOnlyForDeploymentPostprocessing: Bool
Expand All @@ -19,10 +27,14 @@ public class PBXBuildPhase: PBXContainerItem {
fatalError("This property must be overriden")
}

public init(filesReferences: [PBXObjectReference] = [],
public init(fileReferences: [PBXObjectReference] = [],
inputFileListPaths: [String]? = nil,
outputFileListPaths: [String]? = nil,
buildActionMask: UInt = defaultBuildActionMask,
runOnlyForDeploymentPostprocessing: Bool = false) {
self.filesReferences = filesReferences
self.fileReferences = fileReferences
self.inputFileListPaths = inputFileListPaths
self.outputFileListPaths = outputFileListPaths
self.buildActionMask = buildActionMask
self.runOnlyForDeploymentPostprocessing = runOnlyForDeploymentPostprocessing
super.init()
Expand All @@ -34,23 +46,27 @@ public class PBXBuildPhase: PBXContainerItem {
case buildActionMask
case files
case runOnlyForDeploymentPostprocessing
case inputFileListPaths
case outputFileListPaths
}

public required init(from decoder: Decoder) throws {
let objects = decoder.context.objects
let objectReferenceRepository = decoder.context.objectReferenceRepository
let container = try decoder.container(keyedBy: CodingKeys.self)
buildActionMask = try container.decodeIntIfPresent(.buildActionMask) ?? PBXBuildPhase.defaultBuildActionMask
let filesReferences: [String] = try container.decodeIfPresent(.files) ?? []
self.filesReferences = filesReferences.map({ objectReferenceRepository.getOrCreate(reference: $0, objects: objects) })
let fileReferences: [String] = try container.decodeIfPresent(.files) ?? []
self.fileReferences = fileReferences.map({ objectReferenceRepository.getOrCreate(reference: $0, objects: objects) })
inputFileListPaths = try container.decodeIfPresent(.inputFileListPaths)
outputFileListPaths = try container.decodeIfPresent(.outputFileListPaths)
runOnlyForDeploymentPostprocessing = try container.decodeIntBool(.runOnlyForDeploymentPostprocessing)
try super.init(from: decoder)
}

override func plistValues(proj: PBXProj, reference: String) throws -> [CommentedString: PlistValue] {
var dictionary = try super.plistValues(proj: proj, reference: reference)
dictionary["buildActionMask"] = .string(CommentedString("\(buildActionMask)"))
dictionary["files"] = .array(filesReferences.map { fileReference in
dictionary["files"] = .array(fileReferences.map { fileReference in
let buildFile: PBXBuildFile? = try? fileReference.object()
let name = buildFile.flatMap { try? $0.fileName() } ?? nil
let fileName: String = name ?? "(null)"
Expand All @@ -60,6 +76,12 @@ public class PBXBuildPhase: PBXContainerItem {
let comment = (type.flatMap { "\(fileName) in \($0)" }) ?? name
return .string(CommentedString(fileReference.value, comment: comment))
})
if let inputFileListPaths = inputFileListPaths {
dictionary["inputFileListPaths"] = .array(inputFileListPaths.map({ .string(CommentedString($0)) }))
}
if let outputFileListPaths = outputFileListPaths {
dictionary["outputFileListPaths"] = .array(outputFileListPaths.map({ .string(CommentedString($0)) }))
}
dictionary["runOnlyForDeploymentPostprocessing"] = .string(CommentedString("\(runOnlyForDeploymentPostprocessing.int)"))
return dictionary
}
Expand All @@ -74,13 +96,13 @@ public extension PBXBuildPhase {
/// - Returns: reference to the build file added to the build phase.
/// - Throws: an error if the reference cannot be added
public func addFile(_ reference: PBXObjectReference) throws -> PBXObjectReference {
if let existing = try filesReferences.compactMap({ try $0.object() as PBXBuildFile }).first(where: { $0.fileReference == reference }) {
if let existing = try fileReferences.compactMap({ try $0.object() as PBXBuildFile }).first(where: { $0.fileReference == reference }) {
return existing.reference
}
let projectObjects = try objects()
let buildFile = PBXBuildFile(fileReference: reference)
let buildFileReference = projectObjects.addObject(buildFile)
filesReferences.append(buildFileReference)
fileReferences.append(buildFileReference)
return buildFileReference
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/xcodeproj/PBXCopyFilesBuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ public final class PBXCopyFilesBuildPhase: PBXBuildPhase {
/// - dstPath: destination path.
/// - dstSubfolderSpec: destination subfolder spec.
/// - buildActionMask: build action mask.
/// - files: files to copy.
/// - fileReferences: files to copy.
/// - runOnlyForDeploymentPostprocessing: run only for deployment post processing.
public init(dstPath: String? = nil,
dstSubfolderSpec: SubFolder? = nil,
name: String? = nil,
buildActionMask: UInt = defaultBuildActionMask,
filesReferences: [PBXObjectReference] = [],
fileReferences: [PBXObjectReference] = [],
runOnlyForDeploymentPostprocessing: Bool = false) {
self.dstPath = dstPath
self.dstSubfolderSpec = dstSubfolderSpec
self.name = name
super.init(filesReferences: filesReferences,
super.init(fileReferences: fileReferences,
buildActionMask: buildActionMask,
runOnlyForDeploymentPostprocessing:
runOnlyForDeploymentPostprocessing)
Expand Down
12 changes: 9 additions & 3 deletions Sources/xcodeproj/PBXShellScriptBuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ public final class PBXShellScriptBuildPhase: PBXBuildPhase {
/// Initializes the shell script build phase with its attributes.
///
/// - Parameters:
/// - files: shell script files.
/// - fileReferences: shell script files.
/// - inputPaths: input paths.
/// - outputPaths: output paths.
/// - inputFileListPaths: input file list paths.
/// - outputFileListPaths: output file list paths.
/// - shellPath: shell path.
/// - shellScript: shell script.
/// - buildActionMask: build action mask.
public init(filesReferences: [PBXObjectReference] = [],
public init(fileReferences: [PBXObjectReference] = [],
name: String? = nil,
inputPaths: [String] = [],
outputPaths: [String] = [],
inputFileListPaths: [String]? = nil,
outputFileListPaths: [String]? = nil,
shellPath: String = "/bin/sh",
shellScript: String? = nil,
buildActionMask: UInt = defaultBuildActionMask,
Expand All @@ -53,7 +57,9 @@ public final class PBXShellScriptBuildPhase: PBXBuildPhase {
self.shellPath = shellPath
self.shellScript = shellScript
self.showEnvVarsInLog = showEnvVarsInLog
super.init(filesReferences: filesReferences,
super.init(fileReferences: fileReferences,
inputFileListPaths: inputFileListPaths,
outputFileListPaths: outputFileListPaths,
buildActionMask: buildActionMask,
runOnlyForDeploymentPostprocessing: runOnlyForDeploymentPostprocessing)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/xcodeproj/PBXTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public extension PBXTarget {
/// - Returns: source files.
/// - Throws: an error if something goes wrong.
public func sourceFiles() throws -> [PBXFileElement] {
return try sourcesBuildPhase()?.filesReferences
return try sourcesBuildPhase()?.fileReferences
.compactMap { try $0.object() as PBXBuildFile }
.filter { $0.fileReference != nil }
.compactMap { try $0.fileReference!.object() as PBXFileElement }
Expand Down
2 changes: 1 addition & 1 deletion Sources/xcodeproj/ReferenceGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ final class ReferenceGenerator: ReferenceGenerating {
}

// Build files
buildPhase.filesReferences.forEach { buildFileReference in
buildPhase.fileReferences.forEach { buildFileReference in
if !buildFileReference.temporary { return }

guard let buildFile: PBXBuildFile = try? buildFileReference.object() else { return }
Expand Down
2 changes: 1 addition & 1 deletion Sources/xcodeproj/Xcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct Xcode {
public static let swiftVersion = "4.1"

/// Last known object version for Xcodeproj.
public static let objectVersion: UInt = 50
public static let objectVersion: UInt = 51

/// Last known upgrade check.
public static let upgradeCheck = "0930"
Expand Down