From 284ef2015e549c88bb9a636c71f38194566de9c4 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 1 Sep 2023 19:11:27 -0700 Subject: [PATCH 1/2] ASTGen: account for alternate path separators Windows supports `\` and `/` as path separators. Account for both in computing the basename. This repairs a few test failures on Windows. --- .../Sources/ASTGen/SourceManager+MacroExpansionContext.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift b/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift index 9f74cb212aa62..ce7facc258308 100644 --- a/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift +++ b/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift @@ -43,7 +43,7 @@ extension String { /// Retrieve the base name of a string that represents a path, removing the /// directory. var basename: String { - guard let lastSlash = lastIndex(of: "/") else { + guard let lastSlash = lastIndex(where: { ["/", "\\"].contains($0) }) else { return self } From a61e6e709c4fccbb64bcf14abce2386050ffeed9 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 3 Sep 2023 10:51:00 -0700 Subject: [PATCH 2/2] ASTGen: special case the Apple and Linux platforms There is no real reason to split the behaviour here as this is a file system primitive. Special case Apple and Linux platforms to address feedback. --- .../ASTGen/SourceManager+MacroExpansionContext.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift b/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift index ce7facc258308..b42fbc6186d7d 100644 --- a/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift +++ b/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift @@ -43,7 +43,13 @@ extension String { /// Retrieve the base name of a string that represents a path, removing the /// directory. var basename: String { - guard let lastSlash = lastIndex(where: { ["/", "\\"].contains($0) }) else { + guard let lastSlash = lastIndex(where: { +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || os(Android) || os(Linux) + ["/"].contains($0) +#else + ["/", "\\"].contains($0) +#endif + }) else { return self }