-
Notifications
You must be signed in to change notification settings - Fork 24k
/
Os.kt
44 lines (36 loc) · 1.21 KB
/
Os.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.utils
import java.io.File
internal object Os {
fun isWindows(): Boolean =
System.getProperty("os.name")?.lowercase()?.contains("windows") ?: false
fun isMac(): Boolean = System.getProperty("os.name")?.lowercase()?.contains("mac") ?: false
fun isLinuxAmd64(): Boolean {
val osNameMatch = System.getProperty("os.name")?.lowercase()?.contains("linux") ?: false
val archMatch = System.getProperty("os.arch")?.lowercase()?.contains("amd64") ?: false
return osNameMatch && archMatch
}
fun String.unixifyPath() =
this.replace('\\', '/').replace(":", "").let {
if (!it.startsWith("/")) {
"/$it"
} else {
it
}
}
/**
* As Gradle doesn't support well path with spaces on Windows, we need to return relative path on
* Win. On Linux & Mac we'll default to return absolute path.
*/
fun File.cliPath(base: File): String =
if (isWindows()) {
this.relativeTo(base).path
} else {
this.absolutePath
}
}