Skip to content

Commit

Permalink
Merge branch 'master' into compilation-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Piñera Buendía authored May 6, 2019
2 parents e14fdab + 39979d5 commit 8d337f8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
### Added

- **Breaking** Swift 5 support https://github.com/tuist/xcodeproj/pull/397 by @pepibumur.
- **Breaking** Add `SWIFT_COMPILATION_MODE` and `CODE_SIGN_IDENTITY` build settings, remove `DEBUG` flag for Release https://github.com/tuist/xcodeproj/pull/417 @dangthaison91
- `WorkspaceSettings.autoCreateSchemes` attribute https://github.com/tuist/xcodeproj/pull/399 by @pepibumur
- Additional Swift 5 fixes: https://github.com/tuist/xcodeproj/pull/402 by @samisuteria
- Make build phase name public by @llinardos.
- Can access embed frameworks build phase for a target by @llinardos.
- Added `com.apple.product-type.framework.static` to `PBXProductType`. https://github.com/tuist/xcodeproj/pull/347 by @ileitch.
- **Breaking** Add `SWIFT_COMPILATION_MODE` and `CODE_SIGN_IDENTITY` build settings, remove `DEBUG` flag for Release https://github.com/tuist/xcodeproj/pull/417 @dangthaison91
- Can add a not existing file to a group https://github.com/tuist/xcodeproj/pull/418 by @llinardos.

### Fixed

Expand Down
14 changes: 7 additions & 7 deletions Sources/xcodeproj/Objects/Files/PBXFileReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ import PathKit
public final class PBXFileReference: PBXFileElement {
// MARK: - Attributes

/// Element file encoding.
/// Text encoding of file content
public var fileEncoding: UInt?

/// Element explicit file type.
/// User-specified file type. Typically this is not set and you want to use `lastKnownFileType` instead.
public var explicitFileType: String?

/// Element last known file type.
/// Derived file type. For a file named "foo.swift" this value would be "sourcecode.swift"
public var lastKnownFileType: String?

/// Element line ending.
/// Line ending type for the file
public var lineEnding: UInt?

/// Element language specification identifier
/// Legacy programming language identifier
public var languageSpecificationIdentifier: String?

/// Element xc language specification identifier
/// Programming language identifier
public var xcLanguageSpecificationIdentifier: String?

/// Element plist structure definition identifier
/// Plist organizational family identifier
public var plistStructureDefinitionIdentifier: String?

// MARK: - Init
Expand Down
6 changes: 4 additions & 2 deletions Sources/xcodeproj/Objects/Files/PBXGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ public extension PBXGroup {
/// - sourceTree: file sourceTree, default is `.group`.
/// - sourceRoot: path to project's source root.
/// - override: flag to enable overriding of existing file references, default is `true`.
/// - validatePresence: flag to validate the existence of the file in the file system, default is `true`.
/// - Returns: new or existing file and its reference.
@discardableResult
func addFile(
at filePath: Path,
sourceTree: PBXSourceTree = .group,
sourceRoot: Path,
override: Bool = true
override: Bool = true,
validatePresence: Bool = true
) throws -> PBXFileReference {
let projectObjects = try objects()
guard filePath.exists else {
if validatePresence && !filePath.exists {
throw XcodeprojEditingError.unexistingFile(filePath)
}
let groupPath = try fullPath(sourceRoot: sourceRoot)
Expand Down
56 changes: 55 additions & 1 deletion Tests/xcodeprojTests/Objects/Files/PBXGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,61 @@ final class PBXGroupTests: XCTestCase {

XCTAssertNotNil(group.children.first?.parent)
}


func test_addNotExistingFileWithoutValidatinPresence_throws() {
do {
let sourceRoot = Path("/")
let project = PBXProj(
rootObject: nil,
objectVersion: 0,
archiveVersion: 0,
classes: [:],
objects: []
)
let group = PBXGroup(children: [],
sourceTree: .group,
name: "group")
project.add(object: group)
let filePath = try Path.uniqueTemporary() + "file"

// ensure it doesnt exist
let fileManager = FileManager.default
if fileManager.fileExists(atPath: filePath.string) {
try FileManager.default.removeItem(atPath: filePath.string)
}
try group.addFile(at: filePath, sourceRoot: sourceRoot)
XCTFail("Should throw XcodeprojEditingError.unexistingFile")
} catch XcodeprojEditingError.unexistingFile {
XCTAssertTrue(true)
} catch {
XCTFail("Should throw XcodeprojEditingError.unexistingFile but throws \(error)")
}
}

func test_addNotExistingFileValidatinPresence_assignsParent() throws {
let sourceRoot = Path("/")
let project = PBXProj(
rootObject: nil,
objectVersion: 0,
archiveVersion: 0,
classes: [:],
objects: []
)
let group = PBXGroup(children: [],
sourceTree: .group,
name: "group")
project.add(object: group)
let filePath = try Path.uniqueTemporary() + "file"

// ensure it doesnt exist
let fileManager = FileManager.default
if fileManager.fileExists(atPath: filePath.string) {
try FileManager.default.removeItem(atPath: filePath.string)
}
let file = try? group.addFile(at: filePath, sourceRoot: sourceRoot, validatePresence: false)
XCTAssertNotNil(file?.parent)
}

private func testDictionary() -> [String: Any] {
return [
"children": ["child"],
Expand Down

0 comments on commit 8d337f8

Please sign in to comment.