Changed Os.WINDOWS to no longer include Cygwin, MinGW or MSYS.

This commit is contained in:
Erik C. Thauvin 2017-04-29 17:11:06 -07:00
parent 6530e8f7be
commit 43d55803a9
3 changed files with 37 additions and 14 deletions

View file

@ -84,9 +84,11 @@ Name | Operating System
`Os.OS400` | OS/400
`Os.SOLARIS` | Solaris / SunOS
`Os.TANDEM` | Tandem's Non-Stop
`Os.WINDOWS` | Microsoft Windows
`Os.WINDOWS` | Microsoft Windows*
`Os.ZOS` | z/OS / OS/390
<sub>* Not including Cygwin, MinGW or MSYS.</sub>
```kotlin
exec {
commandLine("cmd", "/c", "stop.cmd", os = setOf(Os.WINDOWS))
@ -135,7 +137,7 @@ exec {
}
```
```shell
```sh
./kobaltw start
./kobaltw stop
```
@ -155,6 +157,7 @@ exec {
## Logging / Debugging
To view the output of the `exec` task, use:
```sh
./kobaltw exec --log 2
```

View file

@ -30,8 +30,6 @@ val example = project {
}
exec {
commandLine("echo", "Test Example 1", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN))
commandLine("cmd", "/c", "echo", "Test", "Example", "1", os = setOf(Os.WINDOWS))
commandLine("ls", "-l", dir = "../kobalt/wrapper", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN))
commandLine("cmd", "/c", "dir /Q", dir = "../kobalt/wrapper", os = setOf(Os.WINDOWS))
}
@ -40,7 +38,7 @@ val example = project {
taskName = "echo"
dependsOn = listOf("exec", "run")
val echo = arrayOf("echo", "Test", "Example", "2")
val echo = arrayOf("echo", "Test", "Example")
commandLine("cmd", "/c", *echo, os = setOf(Os.WINDOWS))
commandLine(*echo, os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN))
}
@ -49,6 +47,6 @@ val example = project {
taskName = "ps"
dependsOn = listOf() // no dependencies
commandLine("cmd", "/c", "tasklist | find \"cmd.exe\"", os = setOf(Os.WINDOWS), fail = setOf(Fail.NONE))
commandLine("/bin/sh", "-c", "ps aux | grep bash", os = setOf(Os.LINUX))
commandLine("sh", "-c", "ps aux | grep bash", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN))
}
}

View file

@ -76,7 +76,11 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c
val curOs: String = System.getProperty("os.name").toLowerCase(Locale.US)
when (os) {
Os.WINDOWS -> {
return curOs.contains("windows")
if (!isMinGW(any = true) && !isCygwin()) {
return curOs.contains("windows")
} else {
return false
}
}
Os.MAC -> {
return (curOs.contains("mac") || curOs.contains("darwin") || curOs.contains("osx"))
@ -103,20 +107,38 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c
return curOs.contains("os/400")
}
Os.CYGWIN -> {
val cygwin: String? = System.getenv("ORIGINAL_PATH")
return cygwin?.contains("/cygdrive/") ?: false
return isCygwin()
}
Os.MINGW -> {
val mingw: String? = System.getenv("MSYSTEM")
return mingw?.startsWith("MINGW") ?: false
return isMinGW()
}
Os.MSYS -> {
val msys: String? = System.getenv("MSYSTEM")
return msys?.startsWith("MSYS") ?: false
return isMinGW(Os.MSYS)
}
}
}
private fun isCygwin() : Boolean {
val path: String? = System.getenv("ORIGINAL_PATH")
return path?.contains("/cygdrive/") ?: false
}
private fun isMinGW(os: Os = Os.MINGW, any: Boolean = false) : Boolean {
val msys: String? = System.getenv("MSYSTEM")
if (!msys.isNullOrBlank()) {
if (any) {
return true
} else if (os.equals(Os.MSYS)) {
return msys!!.startsWith("MSYS")
} else if (os.equals(Os.MINGW)) {
return msys!!.startsWith("MINGW")
}
}
return false
}
private fun executeCommands(project: Project, config: ExecConfig): TaskResult {
var success = true
val errorMessage = StringBuilder()
@ -132,7 +154,7 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c
}
}
if (execute) {
log(2, "> " + args.joinToString(" "))
log(2, (if (!wrkDir.name.equals(".")) wrkDir.name else "") + "> " + args.joinToString(" "))
val pb = ProcessBuilder().command(args.toList())
pb.directory(wrkDir)
val proc = pb.start()