@@ -64,7 +64,7 @@ enum PluginUtils {
6464
6565 /// Find the config file.
6666 private static func findConfig( inputFiles: FileList , targetName: String ) -> Result < Path , FileError > {
67- let matchedConfigs = inputFiles. filter { supportedConfigFiles. contains ( $0. path. lastComponent ) } . map ( \. path)
67+ let matchedConfigs = inputFiles. filter { supportedConfigFiles. contains ( $0. path. lastComponent_fixed ) } . map ( \. path)
6868 guard matchedConfigs. count > 0 else {
6969 return . failure( FileError ( targetName: targetName, fileKind: . config, issue: . noFilesFound) )
7070 }
@@ -78,7 +78,7 @@ enum PluginUtils {
7878
7979 /// Find the document file.
8080 private static func findDocument( inputFiles: FileList , targetName: String ) -> Result < Path , FileError > {
81- let matchedDocs = inputFiles. filter { supportedDocFiles. contains ( $0. path. lastComponent ) } . map ( \. path)
81+ let matchedDocs = inputFiles. filter { supportedDocFiles. contains ( $0. path. lastComponent_fixed ) } . map ( \. path)
8282 guard matchedDocs. count > 0 else {
8383 return . failure( FileError ( targetName: targetName, fileKind: . document, issue: . noFilesFound) )
8484 }
@@ -97,3 +97,23 @@ extension Array where Element == String {
9797 return " \( self . dropLast ( ) . joined ( separator: separator) ) \( lastSeparator) \( self . last!) "
9898 }
9999}
100+
101+ extension PackagePlugin . Path {
102+ /// Workaround for the ``lastComponent`` property being broken on Windows
103+ /// due to hardcoded assumptions about the path separator being forward slash.
104+ @available ( _PackageDescription, deprecated: 6.0 , message: " Use `URL` type instead of `Path`. " )
105+ public var lastComponent_fixed : String {
106+ #if !os(Windows)
107+ lastComponent
108+ #else
109+ // Find the last path separator.
110+ guard let idx = string. lastIndex ( where: { $0 == " / " || $0 == " \\ " } ) else {
111+ // No path separators, so the basename is the whole string.
112+ return self . string
113+ }
114+ // Otherwise, it's the string from (but not including) the last path
115+ // separator.
116+ return String ( self . string. suffix ( from: self . string. index ( after: idx) ) )
117+ #endif
118+ }
119+ }
0 commit comments