@@ -12,44 +12,59 @@ import TSCBasic
1212import Foundation
1313
1414/// Recognized Platform types.
15- public enum Platform {
15+ public enum Platform : Equatable {
1616 case android
1717 case darwin
1818 case linux( LinuxFlavor )
1919
2020 /// Recognized flavors of linux.
21- public enum LinuxFlavor {
21+ public enum LinuxFlavor : Equatable {
2222 case debian
2323 case fedora
2424 }
2525
2626 /// Lazily checked current platform.
27- public static var currentPlatform = Platform . findCurrentPlatform ( )
27+ public static var currentPlatform = Platform . _findCurrentPlatform ( localFileSystem )
2828 /// Attempt to match `uname` with recognized platforms.
29- private static func findCurrentPlatform ( ) -> Platform ? {
29+ public static func _findCurrentPlatform ( _ fs : FileSystem ) -> Platform ? {
3030 guard let uname = try ? Process . checkNonZeroExit ( args: " uname " ) . spm_chomp ( ) . lowercased ( ) else { return nil }
3131 switch uname {
3232 case " darwin " :
3333 return . darwin
3434 case " linux " :
35- if localFileSystem. isFile ( AbsolutePath ( " /etc/debian_version " ) ) {
36- return . linux( . debian)
37- }
38- if localFileSystem. isFile ( AbsolutePath ( " /system/bin/toolbox " ) ) ||
39- localFileSystem. isFile ( AbsolutePath ( " /system/bin/toybox " ) ) {
40- return . android
41- }
42- if localFileSystem. isFile ( AbsolutePath ( " /etc/redhat-release " ) ) ||
43- localFileSystem. isFile ( AbsolutePath ( " /etc/centos-release " ) ) ||
44- localFileSystem. isFile ( AbsolutePath ( " /etc/fedora-release " ) ) {
45- return . linux( . fedora)
46- }
35+ return Platform . _findCurrentPlatformLinux ( fs)
4736 default :
4837 return nil
4938 }
39+ }
40+
41+ public static func _findCurrentPlatformLinux( _ fs: FileSystem ) -> Platform ? {
42+ if fs. isFile ( AbsolutePath ( " /etc/debian_version " ) ) {
43+ return . linux( . debian)
44+ }
45+ if fs. isFile ( AbsolutePath ( " /system/bin/toolbox " ) ) ||
46+ fs. isFile ( AbsolutePath ( " /system/bin/toybox " ) ) {
47+ return . android
48+ }
49+ if fs. isFile ( AbsolutePath ( " /etc/redhat-release " ) ) ||
50+ fs. isFile ( AbsolutePath ( " /etc/centos-release " ) ) ||
51+ fs. isFile ( AbsolutePath ( " /etc/fedora-release " ) ) ||
52+ Platform . isAmazonLinux2 ( fs) {
53+ return . linux( . fedora)
54+ }
55+
5056 return nil
5157 }
5258
59+ private static func isAmazonLinux2( _ fs: FileSystem ) -> Bool {
60+ do {
61+ let release = try fs. readFileContents ( AbsolutePath ( " /etc/system-release " ) ) . cString
62+ return release. hasPrefix ( " Amazon Linux release 2 " )
63+ } catch {
64+ return false
65+ }
66+ }
67+
5368 /// Returns the cache directories used in Darwin.
5469 public static func darwinCacheDirectories( ) -> [ AbsolutePath ] {
5570 if let value = Platform . _darwinCacheDirectories {
0 commit comments