Skip to content

Commit

Permalink
Support running executable Gradle tasks on Windows with WSL (hyperled…
Browse files Browse the repository at this point in the history
…ger#6803)

Signed-off-by: Fabio Di Fabio <[email protected]>
Signed-off-by: Justin Florentine <[email protected]>
  • Loading branch information
fab-10 authored and jflo committed Mar 26, 2024
1 parent 03d8a13 commit a97108c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
41 changes: 22 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def _strListCmdArg(name) {
return _strListCmdArg(name, null)
}

// set the shell command to use according to os
def shell = org.gradle.internal.os.OperatingSystem.current().isWindows() ? "${projectDir}\\wslsh.bat" : '/bin/bash'

licenseReport {
// This is for the allowed-licenses-file in checkLicense Task
// Accepts File, URL or String path to local or remote file
Expand Down Expand Up @@ -760,20 +763,20 @@ task distDocker {
println "Building for platform ${project.getProperty('docker-platform')}"
}
def gitDetails = getGitCommitDetails(10)
executable "sh"
executable shell
workingDir dockerBuildDir
args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ."
}
}

// tag the "default" (which is the variant in the zero position)
exec {
executable "sh"
executable shell
args "-c", "docker tag '${dockerImageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${dockerImageName}:${dockerBuildVersion}'"
}
// create a static tag for the benchmark target
exec {
executable "sh"
executable shell
args "-c", "docker tag '${dockerImageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${dockerImageName}:benchmark'"
}
}
Expand All @@ -792,8 +795,8 @@ task testDocker {
exec {
def image = project.hasProperty('release.releaseVersion') ? "${dockerImageName}:" + project.property('release.releaseVersion') : "${dockerImageName}:${project.version}"
workingDir "${projectDir}/docker/${variant}"
executable "sh"
args "-c", "bash ../test.sh ${image}-${variant}"
executable shell
args "-c", "../test.sh ${image}-${variant}"
}
}
}
Expand Down Expand Up @@ -821,7 +824,7 @@ task dockerUpload {
def cmd = "docker tag '${variantImage}' '${archVariantImage}' && docker push '${archVariantImage}'"
additionalTags.each { tag -> cmd += " && docker tag '${variantImage}' '${dockerImageName}:${tag.trim()}-${variant}-${architecture}' && docker push '${dockerImageName}:${tag.trim()}-${variant}-${architecture}'" }
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand All @@ -831,7 +834,7 @@ task dockerUpload {
def cmd = "docker tag ${image} ${archImage} && docker push '${archImage}'"
additionalTags.each { tag -> cmd += " && docker tag '${image}' '${dockerImageName}:${tag.trim()}-${architecture}' && docker push '${dockerImageName}:${tag.trim()}-${architecture}'" }
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand All @@ -848,13 +851,13 @@ task dockerUploadRelease {
exec {
def cmd = "docker pull '${variantImage}-${architecture}' && docker tag '${variantImage}-${architecture}' '${dockerImageName}:latest-${variant}-${architecture}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker push '${dockerImageName}:latest-${variant}-${architecture}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand All @@ -863,13 +866,13 @@ task dockerUploadRelease {
def archImage = "${image}-${architecture}"
def cmd = "docker pull '${archImage}' && docker tag ${archImage} '${dockerImageName}:latest-${architecture}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker push '${dockerImageName}:latest-${architecture}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand Down Expand Up @@ -899,13 +902,13 @@ task manifestDocker {
exec {
def cmd = "docker manifest create '${variantImage}' ${targets}"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${variantImage}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand All @@ -915,13 +918,13 @@ task manifestDocker {
archs.forEach { arch -> targets += "'${baseTag}-${arch}' " }
def cmd = "docker manifest create '${baseTag}' ${targets}"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${baseTag}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand All @@ -941,13 +944,13 @@ task manifestDockerRelease {
exec {
def cmd = "docker manifest create '${variantImage}' ${targets} --amend"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${variantImage}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand All @@ -957,13 +960,13 @@ task manifestDockerRelease {
archs.forEach { arch -> targets += "'${baseTag}-${arch}' " }
def cmd = "docker manifest create '${baseTag}' ${targets} --amend"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${baseTag}'"
println "Executing '${cmd}'"
executable "sh"
executable shell
args "-c", cmd
}
}
Expand Down
2 changes: 2 additions & 0 deletions wslsh.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set WSLENV=architecture/u
wsl /bin/bash %*

0 comments on commit a97108c

Please sign in to comment.