@@ -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,24 @@ 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`. " ) public
105+ var lastComponent_fixed : String
106+ {
107+ #if !os(Windows)
108+ lastComponent
109+ #else
110+ // Find the last path separator.
111+ guard let idx = string. lastIndex ( where: { $0 == " / " || $0 == " \\ " } ) else {
112+ // No path separators, so the basename is the whole string.
113+ return self . string
114+ }
115+ // Otherwise, it's the string from (but not including) the last path
116+ // separator.
117+ return String ( self . string. suffix ( from: self . string. index ( after: idx) ) )
118+ #endif
119+ }
120+ }
0 commit comments