@@ -1289,41 +1289,12 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
12891289 private static func computeLibraryArgs( _ libraries: [ LibrarySpecifier ] , scope: MacroEvaluationScope ) -> ( args: [ String ] , inputs: [ Path ] ) {
12901290 // Construct the library arguments.
12911291 return libraries. compactMap { specifier -> ( args: [ String ] , inputs: [ Path ] ) in
1292- let basename = specifier. path. basename
1293-
1294- // FIXME: This isn't a good system, we need to redesign how we talk to the linker w.r.t. search paths and our notion of paths.
12951292 switch specifier. kind {
1296- case . static:
1297- if specifier. useSearchPaths, basename. hasPrefix ( " lib " ) , basename. hasSuffix ( " .a " ) {
1298- return ( specifier. searchPathFlagsForLd ( basename. withoutPrefix ( " lib " ) . withoutSuffix ( " .a " ) ) , [ ] )
1299- }
1300- return ( specifier. absolutePathFlagsForLd ( ) , [ specifier. path] )
1301- case . dynamic:
1302- let suffix = " . \( scope. evaluate ( BuiltinMacros . DYNAMIC_LIBRARY_EXTENSION) ) "
1303- if specifier. useSearchPaths, basename. hasPrefix ( " lib " ) , basename. hasSuffix ( suffix) {
1304- return ( specifier. searchPathFlagsForLd ( basename. withoutPrefix ( " lib " ) . withoutSuffix ( suffix) ) , [ ] )
1305- }
1306- return ( specifier. absolutePathFlagsForLd ( ) , [ specifier. path] )
1307- case . textBased:
1308- if specifier. useSearchPaths, basename. hasPrefix ( " lib " ) , basename. hasSuffix ( " .tbd " ) {
1309- // .merge and .reexport are not supported for text-based libraries.
1310- return ( specifier. searchPathFlagsForLd ( basename. withoutPrefix ( " lib " ) . withoutSuffix ( " .tbd " ) ) , [ ] )
1311- }
1312- return ( specifier. absolutePathFlagsForLd ( ) , [ specifier. path] )
1313- case . framework:
1314- let frameworkName = Path ( basename) . withoutSuffix
1293+ case . static, . dynamic, . textBased, . framework:
13151294 if specifier. useSearchPaths {
1316- return ( specifier. searchPathFlagsForLd ( frameworkName) , [ ] )
1317- }
1318- let absPathArgs = specifier. absolutePathFlagsForLd ( )
1319- let returnPath : Path
1320- if let pathArg = absPathArgs. last, Path ( pathArg) . basename == frameworkName {
1321- returnPath = Path ( pathArg)
1322- }
1323- else {
1324- returnPath = specifier. path
1295+ return ( specifier. searchPathFlagsForLd ( ) , [ ] )
13251296 }
1326- return ( absPathArgs , [ returnPath ] )
1297+ return ( specifier . absolutePathFlagsForLd ( ) , [ specifier . path ] )
13271298 case . object:
13281299 // Object files are added to linker inputs in the sources task producer.
13291300 return ( [ ] , [ ] )
@@ -1559,35 +1530,41 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
15591530
15601531/// Extensions to `LinkerSpec.LibrarySpecifier` specific to the dynamic linker.
15611532fileprivate extension LinkerSpec . LibrarySpecifier {
1562- func searchPathFlagsForLd( _ name: String ) -> [ String ] {
1533+ func searchPathFlagsForLd( ) -> [ String ] {
1534+ let strippedName : String
1535+ if path. basename. hasPrefix ( libPrefix) {
1536+ strippedName = Path ( path. basename) . withoutSuffix. withoutPrefix ( libPrefix)
1537+ } else {
1538+ strippedName = Path ( path. basename) . withoutSuffix
1539+ }
15631540 switch ( kind, mode) {
15641541 case ( . dynamic, . normal) :
1565- return [ " -l " + name ]
1542+ return [ " -l " + strippedName ]
15661543 case ( . dynamic, . reexport) :
1567- return [ " -Xlinker " , " -reexport-l " + name ]
1544+ return [ " -Xlinker " , " -reexport-l " + strippedName ]
15681545 case ( . dynamic, . merge) :
1569- return [ " -Xlinker " , " -merge-l " + name ]
1546+ return [ " -Xlinker " , " -merge-l " + strippedName ]
15701547 case ( . dynamic, . reexport_merge) :
1571- return [ " -Xlinker " , " -no_merge-l " + name ]
1548+ return [ " -Xlinker " , " -no_merge-l " + strippedName ]
15721549 case ( . dynamic, . weak) :
1573- return [ " -weak-l " + name ]
1550+ return [ " -weak-l " + strippedName ]
15741551 case ( . static, . weak) ,
15751552 ( . textBased, . weak) :
1576- return [ " -weak-l " + name ]
1553+ return [ " -weak-l " + strippedName ]
15771554 case ( . static, _) ,
15781555 ( . textBased, _) :
15791556 // Other modes are not supported for these kinds.
1580- return [ " -l " + name ]
1557+ return [ " -l " + strippedName ]
15811558 case ( . framework, . normal) :
1582- return [ " -framework " , name ]
1559+ return [ " -framework " , strippedName ]
15831560 case ( . framework, . reexport) :
1584- return [ " -Xlinker " , " -reexport_framework " , " -Xlinker " , name ]
1561+ return [ " -Xlinker " , " -reexport_framework " , " -Xlinker " , strippedName ]
15851562 case ( . framework, . merge) :
1586- return [ " -Xlinker " , " -merge_framework " , " -Xlinker " , name ]
1563+ return [ " -Xlinker " , " -merge_framework " , " -Xlinker " , strippedName ]
15871564 case ( . framework, . reexport_merge) :
1588- return [ " -Xlinker " , " -no_merge_framework " , " -Xlinker " , name ]
1565+ return [ " -Xlinker " , " -no_merge_framework " , " -Xlinker " , strippedName ]
15891566 case ( . framework, . weak) :
1590- return [ " -weak_framework " , name ]
1567+ return [ " -weak_framework " , strippedName ]
15911568 case ( . object, _) :
15921569 // Object files are added to linker inputs in the sources task producer.
15931570 return [ ]
@@ -1724,9 +1701,9 @@ public final class LibtoolLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @u
17241701 delegate. warning ( " Product \( cbc. output. basename) cannot weak-link \( specifier. kind) \( basename) " )
17251702 }
17261703
1727- if specifier. useSearchPaths, basename . hasPrefix ( " lib " ) , basename . hasSuffix ( " .a " ) {
1704+ if specifier. useSearchPaths {
17281705 // Locate using search paths: Add a -l option and *don't* add the path to the library as an input to the task.
1729- return [ " -l " + basename . withoutPrefix ( " lib " ) . withoutSuffix ( " .a " ) ]
1706+ return [ " -l " + Path ( specifier . path . basename ) . withoutSuffix. withoutPrefix ( specifier . libPrefix ) ]
17301707 }
17311708 else {
17321709 // Locate using an absolute path: Add the path as an option and as an input to the task.
0 commit comments