Skip to content

Commit aaf56aa

Browse files
committed
[Android] Enable more code and tests
while disabling setting extended file attributes and a test creating a hard link, features not normally allowed on Android.
1 parent e905df1 commit aaf56aa

File tree

8 files changed

+14
-10
lines changed

8 files changed

+14
-10
lines changed

Sources/FoundationEssentials/Data/Data+Reading.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import WASILibc
3434
func _fgetxattr(_ fd: Int32, _ name: UnsafePointer<CChar>!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int {
3535
#if canImport(Darwin)
3636
return fgetxattr(fd, name, value, size, position, options)
37-
#elseif canImport(Glibc) || canImport(Musl)
37+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
3838
return fgetxattr(fd, name, value, size)
3939
#else
4040
return -1

Sources/FoundationEssentials/FileManager/FileManager+Files.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ extension _FileManagerImpl {
956956
#if os(WASI)
957957
// WASI does not support extended attributes
958958
throw CocoaError.errorWithFilePath(.featureUnsupported, path)
959+
#elseif canImport(Android)
960+
// Android doesn't allow setting this for normal apps, so just skip it.
959961
#else
960962
try Self._setAttributes(extendedAttrs, at: fileSystemRepresentation, followSymLinks: false)
961963
#endif

Sources/FoundationEssentials/Platform.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extension Platform {
192192
extension Platform {
193193
@discardableResult
194194
package static func copyCString(dst: UnsafeMutablePointer<CChar>, src: UnsafePointer<CChar>, size: Int) -> Int {
195-
#if canImport(Darwin)
195+
#if canImport(Darwin) || canImport(Android)
196196
return strlcpy(dst, src, size)
197197
#else
198198
// Glibc doesn't support strlcpy
@@ -267,7 +267,7 @@ extension Platform {
267267
return String(cString: buffer.baseAddress!).standardizingPath
268268
#endif
269269
}
270-
#elseif os(Linux)
270+
#elseif os(Linux) || os(Android)
271271
// For Linux, read /proc/self/exe
272272
return try? FileManager.default.destinationOfSymbolicLink(
273273
atPath: "/proc/self/exe").standardizingPath

Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ extension _ProcessInfo {
450450
var siInfo = SYSTEM_INFO()
451451
GetSystemInfo(&siInfo)
452452
return Int(siInfo.dwNumberOfProcessors)
453-
#elseif os(Linux) || os(FreeBSD)
453+
#elseif os(Linux) || os(FreeBSD) || canImport(Android)
454454
return Int(sysconf(Int32(_SC_NPROCESSORS_CONF)))
455455
#else
456456
return 1
@@ -467,7 +467,7 @@ extension _ProcessInfo {
467467
return 0
468468
}
469469
return Int(count)
470-
#elseif os(Linux) || os(FreeBSD)
470+
#elseif os(Linux) || os(FreeBSD) || canImport(Android)
471471
#if os(Linux)
472472
if let fsCount = Self.fsCoreCount() {
473473
return fsCount
@@ -561,7 +561,7 @@ extension _ProcessInfo {
561561
return 0
562562
}
563563
return totalMemoryKB * 1024
564-
#elseif os(Linux) || os(FreeBSD)
564+
#elseif os(Linux) || os(FreeBSD) || canImport(Android)
565565
var memory = sysconf(Int32(_SC_PHYS_PAGES))
566566
memory *= sysconf(Int32(_SC_PAGESIZE))
567567
return UInt64(memory)

Tests/FoundationEssentialsTests/DataTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ extension DataTests {
18371837
}
18381838

18391839
func testEOPNOTSUPP() throws {
1840-
#if !canImport(Darwin) && !os(Linux)
1840+
#if !canImport(Darwin) && !os(Linux) && !os(Android)
18411841
throw XCTSkip("POSIXError.Code is not supported on this platform")
18421842
#else
18431843
// Opening a socket via open(2) on Darwin can result in the EOPNOTSUPP error code

Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ final class FileManagerTests : XCTestCase {
323323
}
324324

325325
func testLinkFileAtPathToPath() throws {
326+
#if !os(Android) // Hard links are not normally allowed on Android.
326327
try FileManagerPlayground {
327328
"foo"
328329
}.test(captureDelegateCalls: true) {
@@ -332,6 +333,7 @@ final class FileManagerTests : XCTestCase {
332333
XCTAssertEqual($0.delegateCaptures.shouldProceedAfterLinkError, [])
333334
XCTAssertTrue($0.fileExists(atPath: "bar"))
334335
}
336+
#endif
335337

336338
try FileManagerPlayground {
337339
"foo"

Tests/FoundationEssentialsTests/PredicateTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ final class PredicateTests: XCTestCase {
364364
func testRegex_RegexBuilder() throws {
365365
#if !canImport(RegexBuilder)
366366
throw XCTSkip("RegexBuilder is unavavailable on this platform")
367-
#elseif !os(Linux) && !FOUNDATION_FRAMEWORK
367+
#elseif !os(Linux) && !os(Android) && !FOUNDATION_FRAMEWORK
368368
// Disable this test in swift-foundation macOS CI because of incorrect availability annotations in the StringProcessing module
369369
throw XCTSkip("This test is currently disabled on this platform")
370370
#else

Tests/FoundationEssentialsTests/ProcessInfoTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ final class ProcessInfoTests : XCTestCase {
115115
let expectedMinMajorVersion = 2
116116
#endif
117117
XCTAssertGreaterThanOrEqual(version.majorVersion, expectedMinMajorVersion, "Unrealistic major system version")
118-
#elseif os(Windows) || os(Linux)
118+
#elseif os(Windows) || os(Linux) || os(Android)
119119
let minVersion = OperatingSystemVersion(majorVersion: 1, minorVersion: 0, patchVersion: 0)
120120
XCTAssertTrue(ProcessInfo.processInfo.isOperatingSystemAtLeast(minVersion))
121121
#else
@@ -171,7 +171,7 @@ final class ProcessInfoTests : XCTestCase {
171171
func testProcessName() {
172172
#if FOUNDATION_FRAMEWORK
173173
let targetName = "TestHost"
174-
#elseif os(Linux) || os(Windows)
174+
#elseif os(Linux) || os(Windows) || os(Android)
175175
let targetName = "swift-foundationPackageTests.xctest"
176176
#else
177177
let targetName = "xctest"

0 commit comments

Comments
 (0)