Skip to content

Commit 5238e5a

Browse files
committed
Sync with SwiftPM trunk
1 parent 05e8dd5 commit 5238e5a

File tree

8 files changed

+69
-7
lines changed

8 files changed

+69
-7
lines changed

Sources/TSCBasic/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ target_link_libraries(TSCBasic PUBLIC
5555
set_target_properties(TSCBasic PROPERTIES
5656
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
5757

58-
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCBasic)
5958

6059
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
6160
install(TARGETS TSCBasic

Sources/TSCBasic/PathShims.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
2828
// that implements readlink and not realpath.
2929
if let resultPtr = TSCLibc.realpath(pathStr, nil) {
3030
let result = String(cString: resultPtr)
31+
// If `resolved_path` is specified as NULL, then `realpath` uses
32+
// malloc(3) to allocate a buffer [...]. The caller should deallocate
33+
// this buffer using free(3).
34+
//
35+
// String.init(cString:) creates a new string by copying the
36+
// null-terminated UTF-8 data referenced by the given pointer.
37+
resultPtr.deallocate()
3138
// FIXME: We should measure if it's really more efficient to compare the strings first.
3239
return result == pathStr ? path : AbsolutePath(result)
3340
}

Sources/TSCLibc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ target_link_libraries(TSCLibc PUBLIC
1919
set_target_properties(TSCLibc PROPERTIES
2020
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
2121

22-
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCLibc)
2322

2423
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
2524
install(TARGETS TSCLibc

Sources/TSCLibc/libc.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,46 @@
1818
#endif
1919

2020
@_exported import TSCclibc
21+
22+
#if os(Windows)
23+
// char *realpath(const char *path, char *resolved_path);
24+
public func realpath(
25+
_ path: String,
26+
_ resolvedPath: UnsafeMutablePointer<CChar>?
27+
) -> UnsafeMutablePointer<CChar>? {
28+
fatalError("realpath is unimplemented")
29+
}
30+
31+
// char *mkdtemp(char *template);
32+
public func mkdtemp(
33+
_ template: UnsafeMutablePointer<CChar>?
34+
) -> UnsafeMutablePointer<CChar>? {
35+
fatalError("mkdtemp is unimplemented")
36+
}
37+
38+
// int mkstemps(char *template, int suffixlen);
39+
public func mkstemps(
40+
_ template: UnsafeMutablePointer<CChar>?,
41+
_ suffixlen: Int32
42+
) -> Int32 {
43+
guard let template = template else { return -EINVAL }
44+
return String(cString: template).withCString(encodedAs: UTF16.self) {
45+
let capacity: Int = wcslen($0) + 1
46+
return $0.withMemoryRebound(to: wchar_t.self, capacity: capacity) {
47+
guard _wmktemp_s(UnsafeMutablePointer(mutating: $0), capacity) == 0 else {
48+
return -EINVAL
49+
}
50+
51+
var fd: Int32 = -1
52+
_wsopen_s(&fd, $0, _O_RDWR | _O_CREAT | _O_BINARY | _O_NOINHERIT,
53+
_SH_DENYNO, _S_IREAD | _S_IWRITE)
54+
55+
String(decodingCString: $0, as: UTF16.self).utf8CString.withUnsafeBytes {
56+
template.assign(from: $0.bindMemory(to: CChar.self).baseAddress!,
57+
count: $0.count)
58+
}
59+
return fd
60+
}
61+
}
62+
}
63+
#endif

Sources/TSCUtility/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@ target_link_libraries(TSCUtility PUBLIC
3434
# NOTE(compnerd) workaround for CMake not setting up include flags yet
3535
set_target_properties(TSCUtility PROPERTIES
3636
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
37-
38-
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCUtility)

Sources/TSCclibc/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ if(NOT BUILD_SHARED_LIBS)
1515
install(TARGETS TSCclibc
1616
ARCHIVE DESTINATION lib)
1717
endif()
18-
19-
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCclibc)

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ class FileSystemTests: XCTestCase {
181181

182182
// Check read/write against root.
183183
XCTAssertThrows(FileSystemError.ioError) {
184+
#if os(Android)
185+
_ = try fs.readFileContents(AbsolutePath("/system/"))
186+
#else
184187
_ = try fs.readFileContents(AbsolutePath("/"))
188+
#endif
185189
}
186190
XCTAssertThrows(FileSystemError.isDirectory) {
187191
try fs.writeFileContents(AbsolutePath("/"), bytes: [])

Tests/TSCBasicTests/PathShimTests.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,30 @@ class PathShimTests : XCTestCase {
6464
class WalkTests : XCTestCase {
6565

6666
func testNonRecursive() {
67+
#if os(Android)
68+
let root = "/system"
69+
var expected = [
70+
AbsolutePath("\(root)/usr"),
71+
AbsolutePath("\(root)/bin"),
72+
AbsolutePath("\(root)/xbin")
73+
]
74+
#else
75+
let root = ""
6776
var expected = [
6877
AbsolutePath("/usr"),
6978
AbsolutePath("/bin"),
7079
AbsolutePath("/sbin")
7180
]
72-
for x in try! walk(AbsolutePath("/"), recursively: false) {
81+
#endif
82+
for x in try! walk(AbsolutePath("\(root)/"), recursively: false) {
7383
if let i = expected.firstIndex(of: x) {
7484
expected.remove(at: i)
7585
}
86+
#if os(Android)
87+
XCTAssertEqual(3, x.components.count)
88+
#else
7689
XCTAssertEqual(2, x.components.count)
90+
#endif
7791
}
7892
XCTAssertEqual(expected.count, 0)
7993
}

0 commit comments

Comments
 (0)