@@ -64,7 +64,8 @@ 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) }
68+ . map ( \. path)
6869 guard matchedConfigs. count > 0 else {
6970 return . failure( FileError ( targetName: targetName, fileKind: . config, issue: . noFilesFound) )
7071 }
@@ -78,7 +79,8 @@ enum PluginUtils {
7879
7980 /// Find the document file.
8081 private static func findDocument( inputFiles: FileList , targetName: String ) -> Result < Path , FileError > {
81- let matchedDocs = inputFiles. filter { supportedDocFiles. contains ( $0. path. lastComponent) } . map ( \. path)
82+ let matchedDocs = inputFiles. filter { supportedDocFiles. contains ( $0. path. lastComponent_fixed) }
83+ . map ( \. path)
8284 guard matchedDocs. count > 0 else {
8385 return . failure( FileError ( targetName: targetName, fileKind: . document, issue: . noFilesFound) )
8486 }
@@ -97,3 +99,24 @@ extension Array where Element == String {
9799 return " \( self . dropLast ( ) . joined ( separator: separator) ) \( lastSeparator) \( self . last!) "
98100 }
99101}
102+
103+ extension PackagePlugin . Path {
104+ /// Workaround for the ``lastComponent`` property being broken on Windows
105+ /// due to hardcoded assumptions about the path separator being forward slash.
106+ @available ( _PackageDescription, deprecated: 6.0 , message: " Use `URL` type instead of `Path`. " ) public
107+ var lastComponent_fixed : String
108+ {
109+ #if !os(Windows)
110+ lastComponent
111+ #else
112+ // Find the last path separator.
113+ guard let idx = string. lastIndex ( where: { $0 == " / " || $0 == " \\ " } ) else {
114+ // No path separators, so the basename is the whole string.
115+ return self . string
116+ }
117+ // Otherwise, it's the string from (but not including) the last path
118+ // separator.
119+ return String ( self . string. suffix ( from: self . string. index ( after: idx) ) )
120+ #endif
121+ }
122+ }
0 commit comments