Merge pull request #7112 from mkurz/sbtn-aarch64

[1.8.x] Make use of sbtn aarch64 binary where possible
This commit is contained in:
eugene yokota 2023-01-03 09:56:55 -05:00 committed by GitHub
commit a47260847f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 17 deletions

View File

@ -72,9 +72,11 @@ val exportRepoCsrDirectory = settingKey[File]("")
val x86MacPlatform = "x86_64-apple-darwin" val x86MacPlatform = "x86_64-apple-darwin"
val x86LinuxPlatform = "x86_64-pc-linux" val x86LinuxPlatform = "x86_64-pc-linux"
val aarch64LinuxPlatform = "aarch64-pc-linux"
val x86WindowsPlatform = "x86_64-pc-win32" val x86WindowsPlatform = "x86_64-pc-win32"
val x86MacImageName = s"sbtn-$x86MacPlatform" val x86MacImageName = s"sbtn-$x86MacPlatform"
val x86LinuxImageName = s"sbtn-$x86LinuxPlatform" val x86LinuxImageName = s"sbtn-$x86LinuxPlatform"
val aarch64LinuxImageName = s"sbtn-$aarch64LinuxPlatform"
val x86WindowsImageName = s"sbtn-$x86WindowsPlatform.exe" val x86WindowsImageName = s"sbtn-$x86WindowsPlatform.exe"
organization in ThisBuild := "org.scala-sbt" organization in ThisBuild := "org.scala-sbt"
@ -119,17 +121,19 @@ val root = (project in file(".")).
file file
}, },
// update sbt.sh at root // update sbt.sh at root
sbtnVersion := "1.7.0", sbtnVersion := "1.8.1-M1",
sbtnJarsBaseUrl := "https://github.com/sbt/sbtn-dist/releases/download", sbtnJarsBaseUrl := "https://github.com/sbt/sbtn-dist/releases/download",
sbtnJarsMappings := { sbtnJarsMappings := {
val baseUrl = sbtnJarsBaseUrl.value val baseUrl = sbtnJarsBaseUrl.value
val v = sbtnVersion.value val v = sbtnVersion.value
val macosImageTar = s"sbtn-$x86MacPlatform-$v.tar.gz" val macosImageTar = s"sbtn-$x86MacPlatform-$v.tar.gz"
val linuxImageTar = s"sbtn-$x86LinuxPlatform-$v.tar.gz" val linuxX86ImageTar = s"sbtn-$x86LinuxPlatform-$v.tar.gz"
val linuxAarch64ImageTar = s"sbtn-$aarch64LinuxPlatform-$v.tar.gz"
val windowsImageZip = s"sbtn-$x86WindowsPlatform-$v.zip" val windowsImageZip = s"sbtn-$x86WindowsPlatform-$v.zip"
val t = target.value val t = target.value
val macosTar = t / macosImageTar val macosTar = t / macosImageTar
val linuxTar = t / linuxImageTar val linuxX86Tar = t / linuxX86ImageTar
val linuxAarch64Tar = t / linuxAarch64ImageTar
val windowsZip = t / windowsImageZip val windowsZip = t / windowsImageZip
import dispatch.classic._ import dispatch.classic._
if(!macosTar.exists && !isWindows && sbtIncludeSbtn) { if(!macosTar.exists && !isWindows && sbtIncludeSbtn) {
@ -142,16 +146,26 @@ val root = (project in file(".")).
s"tar zxvf $macosTar --directory $platformDir".! s"tar zxvf $macosTar --directory $platformDir".!
IO.move(platformDir / "sbtn", t / x86MacImageName) IO.move(platformDir / "sbtn", t / x86MacImageName)
} }
if(!linuxTar.exists && !isWindows && sbtIncludeSbtn) { if(!linuxX86Tar.exists && !isWindows && sbtIncludeSbtn) {
IO.touch(linuxTar) IO.touch(linuxX86Tar)
val writer = new java.io.BufferedOutputStream(new java.io.FileOutputStream(linuxTar)) val writer = new java.io.BufferedOutputStream(new java.io.FileOutputStream(linuxX86Tar))
try Http(url(s"$baseUrl/v$v/$linuxImageTar") >>> writer) try Http(url(s"$baseUrl/v$v/$linuxX86ImageTar") >>> writer)
finally writer.close() finally writer.close()
val platformDir = t / x86LinuxPlatform val platformDir = t / x86LinuxPlatform
IO.createDirectory(platformDir) IO.createDirectory(platformDir)
s"""tar zxvf $linuxTar --directory $platformDir""".! s"""tar zxvf $linuxX86Tar --directory $platformDir""".!
IO.move(platformDir / "sbtn", t / x86LinuxImageName) IO.move(platformDir / "sbtn", t / x86LinuxImageName)
} }
if(!linuxAarch64Tar.exists && !isWindows && sbtIncludeSbtn) {
IO.touch(linuxAarch64Tar)
val writer = new java.io.BufferedOutputStream(new java.io.FileOutputStream(linuxAarch64Tar))
try Http(url(s"$baseUrl/v$v/$linuxAarch64ImageTar") >>> writer)
finally writer.close()
val platformDir = t / aarch64LinuxPlatform
IO.createDirectory(platformDir)
s"""tar zxvf $linuxAarch64Tar --directory $platformDir""".!
IO.move(platformDir / "sbtn", t / aarch64LinuxImageName)
}
if(!windowsZip.exists && sbtIncludeSbtn) { if(!windowsZip.exists && sbtIncludeSbtn) {
IO.touch(windowsZip) IO.touch(windowsZip)
val writer = new java.io.BufferedOutputStream(new java.io.FileOutputStream(windowsZip)) val writer = new java.io.BufferedOutputStream(new java.io.FileOutputStream(windowsZip))
@ -166,6 +180,7 @@ val root = (project in file(".")).
else else
Seq(t / x86MacImageName -> s"bin/$x86MacImageName", Seq(t / x86MacImageName -> s"bin/$x86MacImageName",
t / x86LinuxImageName -> s"bin/$x86LinuxImageName", t / x86LinuxImageName -> s"bin/$x86LinuxImageName",
t / aarch64LinuxImageName -> s"bin/$aarch64LinuxImageName",
t / x86WindowsImageName -> s"bin/$x86WindowsImageName") t / x86WindowsImageName -> s"bin/$x86WindowsImageName")
}, },
@ -222,7 +237,7 @@ val root = (project in file(".")).
val orig = (linuxPackageMappings in Rpm).value val orig = (linuxPackageMappings in Rpm).value
val nativeMappings = sbtnJarsMappings.value val nativeMappings = sbtnJarsMappings.value
orig.map(o => o.copy(mappings = o.mappings.toList filterNot { orig.map(o => o.copy(mappings = o.mappings.toList filterNot {
case (x, p) => p.contains("sbtn-x86_64") case (x, p) => p.contains("sbtn-x86_64") || p.contains("sbtn-aarch64")
})) }))
}, },
rpmVendor := "lightbend", rpmVendor := "lightbend",

View File

@ -64,7 +64,11 @@ private[sbt] object InstallSbtn {
if (Properties.isWin) "pc-win32.exe" if (Properties.isWin) "pc-win32.exe"
else if (Properties.isLinux) "pc-linux" else if (Properties.isLinux) "pc-linux"
else "apple-darwin" else "apple-darwin"
val sbtnName = s"sbt/bin/sbtn-x86_64-$bin" val isArmArchitecture: Boolean = sys.props
.getOrElse("os.arch", "")
.toLowerCase(java.util.Locale.ROOT) == "aarch64"
val arch = if (Properties.isLinux && isArmArchitecture) "aarch64" else "x86_64"
val sbtnName = s"sbt/bin/sbtn-$arch-$bin"
val fis = new FileInputStream(sbtZip.toFile) val fis = new FileInputStream(sbtZip.toFile)
val zipInputStream = new ZipInputStream(fis) val zipInputStream = new ZipInputStream(fis)
var foundBinary = false var foundBinary = false

View File

@ -37,7 +37,7 @@ class InstallSbtnSpec extends AnyFlatSpec {
"InstallSbtn" should "extract native sbtn" ignore "InstallSbtn" should "extract native sbtn" ignore
withTemp(".zip") { tmp => withTemp(".zip") { tmp =>
withTemp(".exe") { sbtn => withTemp(".exe") { sbtn =>
InstallSbtn.extractSbtn(term, "1.4.1", tmp, sbtn) InstallSbtn.extractSbtn(term, "1.8.1-M1", tmp, sbtn)
val tmpDir = Files.createTempDirectory("sbtn-test").toRealPath() val tmpDir = Files.createTempDirectory("sbtn-test").toRealPath()
Files.createDirectories(tmpDir.resolve("project")) Files.createDirectories(tmpDir.resolve("project"))
val foo = tmpDir.resolve("foo") val foo = tmpDir.resolve("foo")
@ -46,7 +46,7 @@ class InstallSbtnSpec extends AnyFlatSpec {
IO.write(tmpDir.resolve("build.sbt").toFile, build) IO.write(tmpDir.resolve("build.sbt").toFile, build)
IO.write( IO.write(
tmpDir.resolve("project").resolve("build.properties").toFile, tmpDir.resolve("project").resolve("build.properties").toFile,
"sbt.version=1.4.1" "sbt.version=1.8.0"
) )
try { try {
val proc = val proc =

18
sbt
View File

@ -24,7 +24,7 @@ declare build_props_sbt_version=
declare use_sbtn= declare use_sbtn=
declare no_server= declare no_server=
declare sbtn_command="$SBTN_CMD" declare sbtn_command="$SBTN_CMD"
declare sbtn_version="1.7.0" declare sbtn_version="1.8.1-M1"
### ------------------------------- ### ### ------------------------------- ###
### Helper methods for BASH scripts ### ### Helper methods for BASH scripts ###
@ -171,9 +171,16 @@ acquire_sbtn () {
local target="$p/sbtn" local target="$p/sbtn"
local archive_target= local archive_target=
local url= local url=
local arch = "x86_64"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then
archive_target="$p/sbtn-x86_64-pc-linux-${sbtn_v}.tar.gz" arch=$(uname -m)
url="https://github.com/sbt/sbtn-dist/releases/download/v${sbtn_v}/sbtn-x86_64-pc-linux-${sbtn_v}.tar.gz" if [[ "$arch" == "aarch64" ]] || [[ "$arch" == "x86_64" ]]; then
archive_target="$p/sbtn-${arch}-pc-linux-${sbtn_v}.tar.gz"
url="https://github.com/sbt/sbtn-dist/releases/download/v${sbtn_v}/sbtn-${arch}-pc-linux-${sbtn_v}.tar.gz"
else
echoerr "sbtn is not supported on $arch"
exit 2
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then
archive_target="$p/sbtn-x86_64-apple-darwin-${sbtn_v}.tar.gz" archive_target="$p/sbtn-x86_64-apple-darwin-${sbtn_v}.tar.gz"
url="https://github.com/sbt/sbtn-dist/releases/download/v${sbtn_v}/sbtn-x86_64-apple-darwin-${sbtn_v}.tar.gz" url="https://github.com/sbt/sbtn-dist/releases/download/v${sbtn_v}/sbtn-x86_64-apple-darwin-${sbtn_v}.tar.gz"
@ -189,7 +196,7 @@ acquire_sbtn () {
if [[ -f "$target" ]]; then if [[ -f "$target" ]]; then
sbtn_command="$target" sbtn_command="$target"
else else
echoerr "downloading sbtn ${sbtn_v}" echoerr "downloading sbtn ${sbtn_v} for ${arch}"
download_url "$url" "$archive_target" download_url "$url" "$archive_target"
if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "darwin"* ]]; then
tar zxf "$archive_target" --directory "$p" tar zxf "$archive_target" --directory "$p"
@ -710,7 +717,8 @@ detectNativeClient() {
if [[ "$sbtn_command" != "" ]]; then if [[ "$sbtn_command" != "" ]]; then
: :
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
[[ -f "${sbt_bin_dir}/sbtn-x86_64-pc-linux" ]] && sbtn_command="${sbt_bin_dir}/sbtn-x86_64-pc-linux" arch=$(uname -m)
[[ -f "${sbt_bin_dir}/sbtn-${arch}-pc-linux" ]] && sbtn_command="${sbt_bin_dir}/sbtn-${arch}-pc-linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then
[[ -f "${sbt_bin_dir}/sbtn-x86_64-apple-darwin" ]] && sbtn_command="${sbt_bin_dir}/sbtn-x86_64-apple-darwin" [[ -f "${sbt_bin_dir}/sbtn-x86_64-apple-darwin" ]] && sbtn_command="${sbt_bin_dir}/sbtn-x86_64-apple-darwin"
elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then