diff --git a/Plugins/Enlighter/Enlighter.swift b/Plugins/Enlighter/Enlighter.swift index cb95df6..9c46da0 100644 --- a/Plugins/Enlighter/Enlighter.swift +++ b/Plugins/Enlighter/Enlighter.swift @@ -176,8 +176,8 @@ struct Enlighter: BuildToolPlugin { configuration: configuration ) guard !groups.isEmpty else { - print("Target contains not matching files:", target.name) - debugLog("Target contains not matching files:", target.name) + print("Could not find matching files in", target.directory) + debugLog("Could not find matching files in", target.directory) return [] } @@ -340,8 +340,8 @@ extension Enlighter: XcodeBuildToolPlugin { configuration: configuration ) guard !groups.isEmpty else { - print("Target contains not matching files:", target.name) - debugLog("Target contains not matching files:", target.name) + print("Could not find matching files in", target.directory) + debugLog("Could not find matching files in", target.directory) return [] } diff --git a/Plugins/Enlighter/XcodeSPMCompat.swift b/Plugins/Enlighter/XcodeSPMCompat.swift index 61201b2..4899c4d 100644 --- a/Plugins/Enlighter/XcodeSPMCompat.swift +++ b/Plugins/Enlighter/XcodeSPMCompat.swift @@ -54,10 +54,30 @@ extension XcodeTarget { if let matching = directories.first(where: { $0.string.hasSuffix(match) }) { return matching } + if let root = findRootForTarget(named: name, in: directories) { + return root + } // give up and use first :-) + print("Could not infer target root, using an arbitrary directory") return directories[0] } - + + func findRootForTarget(named name: String, in directories: [Path]) -> Path? { + // find the longest path containing the target name + let innerMatch = "/" + name + "/" + guard let path = directories + .filter({ $0.string.contains(innerMatch) }) + .max(by: { $0.string.count > $1.string.count }) + else { return nil } + + // drop everything after the last path component that matches the target name + let components = path.string.split(separator: "/") + let index = components.distance(from: components.startIndex, + to: components.reversed().firstIndex(where: { $0 == name })!) + let targetPathComponents = components.prefix(components.count - index) + return Path("/").appending(targetPathComponents.map({ String($0) })) + } + func doesRecursivelyDependOnTarget(named name: String) -> Bool { for dep in self.dependencies { switch dep {