Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
[fix] handle bazelisk exec on windows | #BAZEL-330 Done
Browse files Browse the repository at this point in the history
Merge-request: BAZEL-MR-162
Merged-by: Xuan Son Trinh <[email protected]>
  • Loading branch information
xuansontrinh authored and Space Team committed Mar 15, 2023
1 parent 4ad14f6 commit 6294219
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,25 @@ internal object BazelPathSpecMapper : ProjectViewToExecutionContextEntityMapper<

private fun findBazelOnPathOrNull(): BazelPathSpec? =
splitPath()
.filterNot { isBazeliskPath(it) }
.map { mapToBazel(it) }
.firstOrNull { it.canExecute() }
?.toPath()
?.let { BazelPathSpec(it) }

private fun splitPath(): List<String> = System.getenv("PATH").split(File.pathSeparator)

private fun isBazeliskPath(path: String): Boolean = path.contains("bazelisk/")
private fun mapToBazel(path: String): File = File(path, calculateBazeliskExecName())

private fun mapToBazel(path: String): File = File(path, "bazel")
// TODO: update tests for the whole flow and mock different OSes
private fun calculateBazeliskExecName(): String {
val osName = System.getProperty("os.name").lowercase()
return with(osName) {
when {
startsWith("windows") -> "bazel.exe"
else -> "bazel"
}
}
}

private fun map(bazelPathSection: ProjectViewBazelPathSection): BazelPathSpec =
BazelPathSpec(bazelPathSection.value)
Expand Down

0 comments on commit 6294219

Please sign in to comment.