File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1
1
2
2
import class Foundation. Process
3
3
import class Foundation. Pipe
4
+ import class Foundation. NSRegularExpression
5
+ import struct Foundation. NSRange
4
6
5
7
enum DynamicLibraries {
6
8
@@ -55,4 +57,24 @@ enum DynamicLibraries {
55
57
. replacingOccurrences ( of: " \" \" " , with: " \" " )
56
58
. split ( separator: " \" " ) . map ( String . init)
57
59
}
60
+
61
+ static func listImports( ) -> [ String ] {
62
+ let lines = read ( )
63
+
64
+ var matches : [ String ] = [ ]
65
+
66
+ for line in lines {
67
+ if let match = line. range ( of: " import .*Config " , options: . regularExpression) {
68
+ matches. append ( String ( line [ match] ) )
69
+ }
70
+ }
71
+
72
+ debugLog ( " MATCHES: \( matches) " )
73
+
74
+ return matches
75
+ . compactMap { $0. split ( separator: " " ) }
76
+ . compactMap { $0. last }
77
+ . map ( String . init)
78
+ . filter { !$0. contains ( " PackageDescription " ) }
79
+ }
58
80
}
Original file line number Diff line number Diff line change @@ -121,8 +121,21 @@ enum Package {
121
121
guard let packageConfigPath = libraryPath ( for: packageConfigLib) else {
122
122
throw Error ( " PackageConfig: Could not find lib \( packageConfigLib) to link against, is it possible you've not built yet? " )
123
123
}
124
+ let dyLibs = try DynamicLibraries . listImports ( ) . map { ( libraryName: String ) -> [ String ] in
125
+ guard let path = libraryPath ( for: libraryName) else {
126
+ throw Error ( " PackageConfig: Could not find lib \( libraryName) to link against, is it possible you've not built yet? " )
127
+ }
128
+
129
+ return [
130
+ " -L " , path,
131
+ " -I " , path,
132
+ " -l \( libraryName) " ,
133
+ ]
134
+ } . reduce ( [ ] , + )
135
+
136
+ debugLog ( " DYLIBS by IMPORT: \( dyLibs) " )
124
137
125
- return try DynamicLibraries . list ( ) . map { libraryName in
138
+ let configLibs = try DynamicLibraries . list ( ) . map { libraryName in
126
139
guard let path = libraryPath ( for: libraryName) else {
127
140
throw Error ( " PackageConfig: Could not find lib \( libraryName) to link against, is it possible you've not built yet? " )
128
141
}
@@ -137,6 +150,10 @@ enum Package {
137
150
" -I " , packageConfigPath,
138
151
" -l \( packageConfigLib) " ,
139
152
] , + )
153
+
154
+ debugLog ( " CONFIG LIBS: \( configLibs) " )
155
+
156
+ return dyLibs + configLibs
140
157
}
141
158
142
159
private static func getSwiftPMManifestArgs( swiftPath: String ) -> [ String ] {
You can’t perform that action at this time.
0 commit comments