Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ extension ElementCreator.CreateFileElement {
let content = """
{isa = PBXFileReference; \
\(calculateFileTypeType(basename: name, extension: impliedExt)) = \(
impliedExt.flatMap(Xcode.pbxProjEscapedFileType) ?? "file"
impliedExt.flatMap(Xcode.pbxProjEscapedFileType) ??
Comment thread
brentleyjones marked this conversation as resolved.
Xcode.unknownFileType
); \
\(nameAttribute)\
path = \(attributes.elementAttributes.path.pbxProjEscaped); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension ElementCreator.CreateLocalizedFileElement {
fileTypeType = "lastKnownFileType"
fileType = ext
.flatMap { Xcode.pbxProjEscapedFileType(extension: $0) } ??
"file"
Xcode.unknownFileType
}

let content = """
Expand Down
11 changes: 11 additions & 0 deletions tools/generators/files_and_groups/src/Xcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ enum Xcode {
"Podfile": "rb",
]

/// The `lastKnownFileType` used for files whose extension isn't in
/// `pbxProjEscapedFileTypes`.
///
/// Xcode determines the type of such files by sniffing their contents,
/// and writes `text` for text files (e.g. `.graphql`, `LICENSE`) and
/// `file` for binary ones. We only see paths (and the files might not
/// exist yet, e.g. generated files), so we use `text`, as unknown files in
/// source trees are overwhelmingly text. Matching Xcode prevents it from
/// rewriting the `project.pbxproj` when it next saves the project.
public static let unknownFileType = "text"

/// Returns the Xcode file type for any given extension.
///
/// - Parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ final class CreateFileElementTests: XCTestCase {
)

let expectedContent = #"""
{isa = PBXFileReference; lastKnownFileType = file; path = "a path"; sourceTree = SOURCE_ROOT; }
{isa = PBXFileReference; lastKnownFileType = text; path = "a path"; sourceTree = SOURCE_ROOT; }
"""#

// Act
Expand Down Expand Up @@ -160,7 +160,7 @@ final class CreateFileElementTests: XCTestCase {
)

let expectedContent = #"""
{isa = PBXFileReference; lastKnownFileType = file; path = a_path; sourceTree = "<group>"; }
{isa = PBXFileReference; lastKnownFileType = text; path = a_path; sourceTree = "<group>"; }
"""#

// Act
Expand Down Expand Up @@ -428,7 +428,7 @@ final class CreateFileElementTests: XCTestCase {
)

let expectedContent = #"""
{isa = PBXFileReference; lastKnownFileType = file; name = "a name"; path = a_path; sourceTree = "<group>"; }
{isa = PBXFileReference; lastKnownFileType = text; name = "a name"; path = a_path; sourceTree = "<group>"; }
"""#

// Act
Expand Down
Loading