Skip to content

Commit

Permalink
Update foundation patches on CI for upstreamed Android support
Browse files Browse the repository at this point in the history
  • Loading branch information
finagolfin committed Oct 9, 2024
1 parent dd4e27b commit e0084e6
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 231 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ jobs:
tar xf ~/$SWIFT_TAG-ubuntu22.04.tar.gz
TOOLCHAIN=${PWD}/$SWIFT_TAG-ubuntu22.04/usr
fi
perl -pi -e 's%canImport\(Bionic%canImport\(Android%' $TOOLCHAIN/bin/swift-package
perl -pi -e 's%import Bionic%import Android%' $TOOLCHAIN/bin/swift-package
perl -pi -e 's%TSCBasic, would be%TSCBasic, would %' $TOOLCHAIN/bin/swift-package
if [ ${{ matrix.version }} != 'devel' ]; then
perl -pi -e 's%canImport\(Bionic%canImport\(Android%' $TOOLCHAIN/bin/swift-package
perl -pi -e 's%import Bionic%import Android%' $TOOLCHAIN/bin/swift-package
perl -pi -e 's%TSCBasic, would be%TSCBasic, would %' $TOOLCHAIN/bin/swift-package
fi
echo "TOOLCHAIN=${TOOLCHAIN}" >> $GITHUB_ENV
${TOOLCHAIN}/bin/swift --version
Expand Down Expand Up @@ -174,7 +176,9 @@ jobs:
git apply swift-android-ci-except-trunk.patch swift-android-foundation-except-trunk.patch
git apply -C1 swift-android-foundation-armv7-except-trunk.patch
if [ ${{ matrix.version }} = 'devel' ]; then
git apply swift-android-foundation-devel.patch
perl -pi -e 's%Musl%Bionic%g' swift-corelibs-foundation/Sources/Testing/Testing.swift
else
git apply swift-android-foundation-release.patch
fi
fi
Expand Down
26 changes: 0 additions & 26 deletions swift-android-foundation-devel.patch

This file was deleted.

213 changes: 12 additions & 201 deletions swift-android-foundation-except-trunk.patch
Original file line number Diff line number Diff line change
@@ -1,204 +1,3 @@
From d7239ae4001af292087c45dd46513285aba4ab34
Date: Tue, 17 Sep 2024 21:10:40 +0530
Subject: [PATCH] [Android] Enable more code and tests (#871)

* [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.

* Remove incorrect WASI check

diff --git a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift
index 48b95214d..612681d2d 100644
--- a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift
+++ b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift
@@ -34,7 +34,7 @@ import WASILibc
func _fgetxattr(_ fd: Int32, _ name: UnsafePointer<CChar>!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int {
#if canImport(Darwin)
return fgetxattr(fd, name, value, size, position, options)
-#elseif canImport(Glibc) || canImport(Musl)
+#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
return fgetxattr(fd, name, value, size)
#else
return -1
@@ -355,7 +355,7 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma
let localProgress = (reportProgress && Progress.current() != nil) ? Progress(totalUnitCount: Int64(fileSize)) : nil

if fileSize == 0 {
- #if os(Linux)
+ #if os(Linux) || os(Android)
// Linux has some files that may report a size of 0 but actually have contents
let chunkSize = 1024 * 4
var buffer = malloc(chunkSize)!
diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
@@ -169,7 +169,7 @@
return
}

- state = [UnsafeMutablePointer(mutating: path), nil].withUnsafeBufferPointer { dirList in
+ state = [UnsafeMutablePointer(mutating: path), unsafeBitCast(0, to: UnsafeMutablePointer<CChar>.self)].withUnsafeBufferPointer { dirList in
guard let stream = fts_open(dirList.baseAddress!, opts, nil) else {
return .error(errno, String(cString: path))
}
diff --git a/swift-foundation/Sources/FoundationEssentials/Platform.swift b/swift-foundation/Sources/FoundationEssentials/Platform.swift
index 4549a4524..0a0aaa393 100644
--- a/swift-foundation/Sources/FoundationEssentials/Platform.swift
+++ b/swift-foundation/Sources/FoundationEssentials/Platform.swift
@@ -192,7 +192,7 @@ extension Platform {
extension Platform {
@discardableResult
package static func copyCString(dst: UnsafeMutablePointer<CChar>, src: UnsafePointer<CChar>, size: Int) -> Int {
- #if canImport(Darwin)
+ #if canImport(Darwin) || canImport(Android)
return strlcpy(dst, src, size)
#else
// Glibc doesn't support strlcpy
@@ -267,7 +267,7 @@ extension Platform {
return String(cString: buffer.baseAddress!).standardizingPath
#endif
}
-#elseif os(Linux)
+#elseif os(Linux) || os(Android)
// For Linux, read /proc/self/exe
return try? FileManager.default.destinationOfSymbolicLink(
atPath: "/proc/self/exe").standardizingPath
diff --git a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
index eb55c273d..bb487c7f5 100644
--- a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
+++ b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
@@ -437,7 +437,7 @@ extension _ProcessInfo {
var siInfo = SYSTEM_INFO()
GetSystemInfo(&siInfo)
return Int(siInfo.dwNumberOfProcessors)
-#elseif os(Linux) || os(FreeBSD)
+#elseif os(Linux) || os(FreeBSD) || canImport(Android)
return Int(sysconf(Int32(_SC_NPROCESSORS_CONF)))
#else
return 1
@@ -454,7 +454,7 @@ extension _ProcessInfo {
return 0
}
return Int(count)
-#elseif os(Linux) || os(FreeBSD)
+#elseif os(Linux) || os(FreeBSD) || canImport(Android)
#if os(Linux)
if let fsCount = Self.fsCoreCount() {
return fsCount
@@ -548,7 +548,7 @@ extension _ProcessInfo {
return 0
}
return totalMemoryKB * 1024
-#elseif os(Linux) || os(FreeBSD)
+#elseif os(Linux) || os(FreeBSD) || canImport(Android)
var memory = sysconf(Int32(_SC_PHYS_PAGES))
memory *= sysconf(Int32(_SC_PAGESIZE))
return UInt64(memory)
diff --git a/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift b/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift
index 744d77b3b..efb8d678f 100644
--- a/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift
+++ b/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift
@@ -173,7 +173,7 @@ struct TimeZoneCache : Sendable {
}
}

-#if os(Linux) && !os(WASI)
+#if os(Linux)
// Try localtime
tzset()
var t = time(nil)
diff --git a/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift
index 5087168ac..6b9ecf3f4 100644
--- a/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift
+++ b/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift
@@ -238,7 +238,7 @@ class DataIOTests : XCTestCase {
}

func test_zeroSizeFile() throws {
- #if !os(Linux)
+ #if !os(Linux) && !os(Android)
throw XCTSkip("This test is only applicable on Linux")
#else
// Some files in /proc report a file size of 0 bytes via a stat call
diff --git a/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift
index 7eae4692f..88428bfef 100644
--- a/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift
+++ b/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift
@@ -1837,7 +1837,7 @@ extension DataTests {
}

func testEOPNOTSUPP() throws {
- #if !canImport(Darwin) && !os(Linux)
+ #if !canImport(Darwin) && !os(Linux) && !os(Android)
throw XCTSkip("POSIXError.Code is not supported on this platform")
#else
// Opening a socket via open(2) on Darwin can result in the EOPNOTSUPP error code
diff --git a/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift
index a25638ab4..62dc23260 100644
--- a/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift
+++ b/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift
@@ -23,6 +23,10 @@ import TestSupport
@testable import Foundation
#endif

+#if canImport(Android)
+import Android
+#endif
+
extension FileManager {
fileprivate var delegateCaptures: DelegateCaptures {
(self.delegate as! CapturingFileManagerDelegate).captures
@@ -329,8 +333,13 @@ final class FileManagerTests : XCTestCase {
XCTAssertTrue($0.delegateCaptures.isEmpty)
try $0.linkItem(atPath: "foo", toPath: "bar")
XCTAssertEqual($0.delegateCaptures.shouldLink, [.init("foo", "bar")])
+ #if os(Android) // Hard links are not normally allowed on Android.
+ XCTAssertEqual($0.delegateCaptures.shouldProceedAfterLinkError, [.init("foo", "bar", code: .fileWriteNoPermission)])
+ XCTAssertFalse($0.fileExists(atPath: "bar"))
+ #else
XCTAssertEqual($0.delegateCaptures.shouldProceedAfterLinkError, [])
XCTAssertTrue($0.fileExists(atPath: "bar"))
+ #endif
}

try FileManagerPlayground {
diff --git a/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift
index 340b21a4a..d0972b537 100644
--- a/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift
+++ b/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift
@@ -364,7 +364,7 @@ final class PredicateTests: XCTestCase {
func testRegex_RegexBuilder() throws {
#if !canImport(RegexBuilder)
throw XCTSkip("RegexBuilder is unavavailable on this platform")
- #elseif !os(Linux) && !FOUNDATION_FRAMEWORK
+ #elseif !os(Linux) && !os(Android) && !FOUNDATION_FRAMEWORK
// Disable this test in swift-foundation macOS CI because of incorrect availability annotations in the StringProcessing module
throw XCTSkip("This test is currently disabled on this platform")
#else
diff --git a/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift
index 1e73a9fbf..5b2cc36cf 100644
--- a/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift
+++ b/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift
@@ -115,7 +115,7 @@ final class ProcessInfoTests : XCTestCase {
let expectedMinMajorVersion = 2
#endif
XCTAssertGreaterThanOrEqual(version.majorVersion, expectedMinMajorVersion, "Unrealistic major system version")
- #elseif os(Windows) || os(Linux)
+ #elseif os(Windows) || os(Linux) || os(Android)
let minVersion = OperatingSystemVersion(majorVersion: 1, minorVersion: 0, patchVersion: 0)
XCTAssertTrue(ProcessInfo.processInfo.isOperatingSystemAtLeast(minVersion))
#else
@@ -171,7 +171,7 @@ final class ProcessInfoTests : XCTestCase {
func testProcessName() {
#if FOUNDATION_FRAMEWORK
let targetName = "TestHost"
-#elseif os(Linux) || os(Windows)
+#elseif os(Linux) || os(Windows) || os(Android)
let targetName = "FoundationPreviewPackageTests.xctest"
#else
let targetName = "xctest"
diff --git a/swift-corelibs-foundation/Package.swift b/swift-corelibs-foundation/Package.swift
--- a/swift-corelibs-foundation/Package.swift
+++ b/swift-corelibs-foundation/Package.swift
Expand Down Expand Up @@ -270,3 +69,15 @@ index d6e63a3f..d550a520 100644

target_compile_options(_CFXMLInterface INTERFACE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/../CoreFoundation/include/module.modulemap>"
diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
@@ -169,7 +169,7 @@
return
}

- state = [UnsafeMutablePointer(mutating: path), nil].withUnsafeBufferPointer { dirList in
+ state = [UnsafeMutablePointer(mutating: path), unsafeBitCast(0, to: UnsafeMutablePointer<CChar>.self)].withUnsafeBufferPointer { dirList in
guard let stream = fts_open(dirList.baseAddress!, opts, nil) else {
return .error(errno, String(cString: path))
}
Loading

0 comments on commit e0084e6

Please sign in to comment.