Skip to content

Commit 5dd7287

Browse files
committed
Android: add some build platform support
1 parent 4d0a9e9 commit 5dd7287

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ public struct BuildParameters: Encodable {
226226
var currentPlatform: PackageModel.Platform {
227227
if self.triple.isDarwin() {
228228
return .macOS
229+
} else if self.triple.isAndroid() {
230+
return .android
229231
} else {
230232
return .linux
231233
}

Sources/Build/Triple.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public struct Triple: Encodable {
101101
return nil
102102
}
103103

104+
public func isAndroid() -> Bool {
105+
return os == .linux && abi == .android
106+
}
107+
104108
public func isDarwin() -> Bool {
105109
return vendor == .apple || os == .macOS || os == .darwin
106110
}

Sources/PackageDescription4/SupportedPlatforms.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public struct Platform: Encodable {
3737
/// The Windows platform
3838
@available(_PackageDescription, introduced: 5.2)
3939
public static let windows: Platform = Platform(name: "windows")
40+
41+
/// The Android platform
42+
@available(_PackageDescription, introduced: 5.2)
43+
public static let android: Platform = Platform(name: "android")
4044
}
4145

4246
/// A platform that the Swift package supports.

Sources/PackageModel/Platform.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public final class PlatformRegistry {
2929

3030
/// The static list of known platforms.
3131
private static var _knownPlatforms: [Platform] {
32-
return [.macOS, .iOS, .tvOS, .watchOS, .linux]
32+
return [.macOS, .iOS, .tvOS, .watchOS, .linux, .android]
3333
}
3434
}
3535

@@ -55,6 +55,7 @@ public struct Platform: Equatable, Hashable {
5555
public static let tvOS: Platform = Platform(name: "tvos", oldestSupportedVersion: "9.0")
5656
public static let watchOS: Platform = Platform(name: "watchos", oldestSupportedVersion: "2.0")
5757
public static let linux: Platform = Platform(name: "linux", oldestSupportedVersion: .unknown)
58+
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)
5859
}
5960

6061
/// Represents a platform version.

Sources/TSCUtility/Platform.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Foundation
1313

1414
/// Recognized Platform types.
1515
public enum Platform {
16+
case android
1617
case darwin
1718
case linux(LinuxFlavor)
1819

@@ -33,6 +34,10 @@ public enum Platform {
3334
if localFileSystem.isFile(AbsolutePath("/etc/debian_version")) {
3435
return .linux(.debian)
3536
}
37+
if localFileSystem.isFile(AbsolutePath("/system/bin/toolbox")) ||
38+
localFileSystem.isFile(AbsolutePath("/system/bin/toybox")) {
39+
return .android
40+
}
3641
default:
3742
return nil
3843
}

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ class PackageBuilderTests: XCTestCase {
13761376
"ios": "8.0",
13771377
"tvos": "9.0",
13781378
"watchos": "2.0",
1379+
"android": "0.0",
13791380
]
13801381

13811382
PackageBuilderTester(manifest, in: fs) { result in
@@ -1411,6 +1412,7 @@ class PackageBuilderTests: XCTestCase {
14111412
"linux": "0.0",
14121413
"ios": "8.0",
14131414
"watchos": "2.0",
1415+
"android": "0.0",
14141416
]
14151417

14161418
PackageBuilderTester(manifest, in: fs) { result in

0 commit comments

Comments
 (0)