Skip to content

Commit b19e27b

Browse files
committed
Merge pull request #374 from aciidb0mb3r/rename-so-dylib
[ClangModule] Use correct extension for dynamic shared library on OSX
2 parents 31c1e76 + b2b0e56 commit b19e27b

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

Sources/Build/Command.compile(ClangModule).swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ private extension ClangModule {
5353
return ["-O2"]
5454
}
5555
}
56+
57+
var productName: String {
58+
switch type {
59+
case .library:
60+
return c99name.soname
61+
case .executable:
62+
return c99name
63+
}
64+
}
5665
}
5766

5867
private extension Sources {
@@ -116,7 +125,7 @@ extension Command {
116125
args += ["-shared"]
117126
}
118127

119-
let productPath = Path.join(prefix, module.type == .library ? "lib\(module.c99name).so" : module.c99name)
128+
let productPath = Path.join(prefix, module.productName)
120129
args += ["-o", productPath]
121130

122131
let shell = ShellTool(description: "Linking \(module.name)",

Sources/PackageModel/Product.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
@_exported import enum PackageDescription.ProductType
12+
import Utility
1213

1314
public class Product {
1415
public let name: String
@@ -28,11 +29,7 @@ public class Product {
2829
case .Library(.Static):
2930
return "lib\(name).a"
3031
case .Library(.Dynamic):
31-
#if os(OSX)
32-
return "lib\(name).dylib"
33-
#else
34-
return "lib\(name).so"
35-
#endif
32+
return name.soname
3633
case .Test:
3734
let base = "\(name).xctest"
3835
#if os(OSX)

Sources/Utility/misc.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,16 @@ import Foundation
3434
}
3535
}
3636
#endif
37+
38+
extension String {
39+
/// Returns shared dynmiac library name of a string by
40+
/// appending lib prefix and file extension `dylib` for OSX
41+
/// and `so` for Linux.
42+
public var soname: String {
43+
#if os(OSX)
44+
return "lib\(self).dylib"
45+
#else
46+
return "lib\(self).so"
47+
#endif
48+
}
49+
}

Tests/Functional/ClangModuleTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ class ClangModulesTestCase: XCTestCase {
1616
func testSingleModuleFlatCLibrary() {
1717
fixture(name: "ClangModules/CLibraryFlat") { prefix in
1818
XCTAssertBuilds(prefix)
19-
XCTAssertFileExists(prefix, ".build", "debug", "libCLibraryFlat.so")
19+
XCTAssertFileExists(prefix, ".build", "debug", "CLibraryFlat".soname)
2020
}
2121
}
2222

2323
func testSingleModuleCLibraryInSources() {
2424
fixture(name: "ClangModules/CLibrarySources") { prefix in
2525
XCTAssertBuilds(prefix)
26-
XCTAssertFileExists(prefix, ".build", "debug", "libCLibrarySources.so")
26+
XCTAssertFileExists(prefix, ".build", "debug", "CLibrarySources".soname)
2727
}
2828
}
2929

3030
func testMixedSwiftAndC() {
3131
fixture(name: "ClangModules/SwiftCMixed") { prefix in
3232
XCTAssertBuilds(prefix)
33-
XCTAssertFileExists(prefix, ".build", "debug", "libSeaLib.so")
33+
XCTAssertFileExists(prefix, ".build", "debug", "SeaLib".soname)
3434
let exec = ".build/debug/SeaExec"
3535
XCTAssertFileExists(prefix, exec)
3636
let output = try popen([Path.join(prefix, exec)])
@@ -42,23 +42,23 @@ class ClangModulesTestCase: XCTestCase {
4242
fixture(name: "DependencyResolution/External/SimpleCDep") { prefix in
4343
XCTAssertBuilds(prefix, "Bar")
4444
XCTAssertFileExists(prefix, "Bar/.build/debug/Bar")
45-
XCTAssertFileExists(prefix, "Bar/.build/debug/libFoo.so")
45+
XCTAssertFileExists(prefix, "Bar/.build/debug", "Foo".soname)
4646
XCTAssertDirectoryExists(prefix, "Bar/Packages/Foo-1.2.3")
4747
}
4848
}
4949

5050
func testiquoteDep() {
5151
fixture(name: "ClangModules/CLibraryiquote") { prefix in
5252
XCTAssertBuilds(prefix)
53-
XCTAssertFileExists(prefix, ".build", "debug", "libFoo.so")
54-
XCTAssertFileExists(prefix, ".build", "debug", "libBar.so")
53+
XCTAssertFileExists(prefix, ".build", "debug", "Foo".soname)
54+
XCTAssertFileExists(prefix, ".build", "debug", "Bar".soname)
5555
}
5656
}
5757

5858
func testCUsingCDep() {
5959
fixture(name: "DependencyResolution/External/CUsingCDep") { prefix in
6060
XCTAssertBuilds(prefix, "Bar")
61-
XCTAssertFileExists(prefix, "Bar/.build/debug/libFoo.so")
61+
XCTAssertFileExists(prefix, "Bar/.build/debug", "Foo".soname)
6262
XCTAssertDirectoryExists(prefix, "Bar/Packages/Foo-1.2.3")
6363
}
6464
}
@@ -77,18 +77,18 @@ class ClangModulesTestCase: XCTestCase {
7777
//The C dependency "Foo" has different layout
7878
fixture(name: "DependencyResolution/External/CUsingCDep2") { prefix in
7979
XCTAssertBuilds(prefix, "Bar")
80-
XCTAssertFileExists(prefix, "Bar/.build/debug/libFoo.so")
80+
XCTAssertFileExists(prefix, "Bar/.build/debug", "Foo".soname)
8181
XCTAssertDirectoryExists(prefix, "Bar/Packages/Foo-1.2.3")
8282
}
8383
}
8484

8585
func testModuleMapGenerationCases() {
8686
fixture(name: "ClangModules/ModuleMapGenerationCases") { prefix in
8787
XCTAssertBuilds(prefix)
88-
XCTAssertFileExists(prefix, ".build", "debug", "libUmbrellaHeader.so")
89-
XCTAssertFileExists(prefix, ".build", "debug", "libFlatInclude.so")
90-
XCTAssertFileExists(prefix, ".build", "debug", "libUmbellaModuleNameInclude.so")
91-
XCTAssertFileExists(prefix, ".build", "debug", "libNoIncludeDir.so")
88+
XCTAssertFileExists(prefix, ".build", "debug", "UmbrellaHeader".soname)
89+
XCTAssertFileExists(prefix, ".build", "debug", "FlatInclude".soname)
90+
XCTAssertFileExists(prefix, ".build", "debug", "UmbellaModuleNameInclude".soname)
91+
XCTAssertFileExists(prefix, ".build", "debug", "NoIncludeDir".soname)
9292
XCTAssertFileExists(prefix, ".build", "debug", "Baz")
9393
}
9494
}
@@ -97,7 +97,7 @@ class ClangModulesTestCase: XCTestCase {
9797
// Try building a fixture which needs extra flags to be able to build.
9898
fixture(name: "ClangModules/CDynamicLookup") { prefix in
9999
XCTAssertBuilds(prefix, Xld: ["-undefined", "dynamic_lookup"])
100-
XCTAssertFileExists(prefix, ".build", "debug", "libCDynamicLookup.so")
100+
XCTAssertFileExists(prefix, ".build", "debug", "CDynamicLookup".soname)
101101
}
102102
}
103103
}

Tests/Xcodeproj/FunctionalTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class FunctionalTests: XCTestCase {
5454
func testXcodeProjWithPkgConfig() {
5555
fixture(name: "Miscellaneous/PkgConfig") { prefix in
5656
XCTAssertBuilds(prefix, "SystemModule")
57-
XCTAssertFileExists(prefix, "SystemModule", ".build", "debug", "libSystemModule.so")
57+
XCTAssertFileExists(prefix, "SystemModule", ".build", "debug", "SystemModule".soname)
5858
let pcFile = Path.join(prefix, "libSystemModule.pc")
5959
try! write(path: pcFile) { stream in
6060
stream <<< "prefix=\(Path.join(prefix, "SystemModule"))\n"

0 commit comments

Comments
 (0)