Skip to content

Commit

Permalink
Merge pull request #15 from wttech/os-util
Browse files Browse the repository at this point in the history
True ARM64 detection including Rosetta emulation
  • Loading branch information
krystian-panek-vmltech authored Jul 22, 2022
2 parents 598b981 + 5c04441 commit 328a4d3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies {
implementation("io.pebbletemplates:pebble:3.1.5")
implementation("com.dorkbox:Notify:3.7")
implementation("net.lingala.zip4j:zip4j:2.9.1")
implementation("org.buildobjects:jproc:2.8.0")
}

val functionalTestSourceSet = sourceSets.create("functionalTest")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=1.1.7
version=1.1.8
release.useAutomaticVersion=true

# Performance tuning
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/com/cognifide/gradle/common/build/PropertyGroup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.cognifide.gradle.common.build

class PropertyGroup(val parser: PropertyParser, val group: String, val member: String) {

fun string(prop: String) = parser.string("$group.$member.$prop") ?: parser.string("$group.$DEFAULT.$prop")

fun strings(prop: String) = parser.list("$group.$member.$prop") ?: parser.list("$group.$DEFAULT.$prop")

fun int(prop: String) = parser.int("$group.$member.$prop") ?: parser.int("$group.$DEFAULT.$prop")

fun long(prop: String) = parser.long("$group.$member.$prop") ?: parser.long("$group.$DEFAULT.$prop")

fun boolean(prop: String) = parser.boolean("$group.$member.$prop") ?: parser.boolean("$group.$DEFAULT.$prop")

fun file(prop: String) = parser.file("$group.$member.$prop") ?: parser.file("$group.$member.$DEFAULT")

companion object {
const val DEFAULT = "default"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class PropertyParser(anyProject: Project) {
return if (!value.isBlank()) value.toBoolean() else true
}

fun strings(name: String, delimiter: String = ",") = list(name, delimiter)

fun list(name: String, delimiter: String = ","): List<String>? = when (val value = prop(name)) {
null -> group(name)?.values?.toList()
EMPTY_LIST -> listOf()
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/com/cognifide/gradle/common/os/OSUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.cognifide.gradle.common.os

import org.buildobjects.process.ProcBuilder
import org.gradle.internal.os.OperatingSystem

object OSUtil {

fun arch() = System.getProperty("os.arch")

fun archOfHost() = if (detectRosetta()) "arm64" else arch()

fun detectRosetta(): Boolean = OperatingSystem.current().isMacOsX &&
exec("sysctl", "-n", "sysctl.proc_translated").trim() == "1"

@Suppress("SpreadOperator")
fun exec(command: String, vararg args: String) = ProcBuilder(command)
.withArgs(*args)
.ignoreExitStatus()
.run().outputString
}

0 comments on commit 328a4d3

Please sign in to comment.