@@ -3,8 +3,9 @@ import java.nio.file.Paths
33ext {
44 NDK_VERSION = project. properties[' io.github.x0b.rcx.ndkVersion' ]
55 RCLONE_VERSION = project. properties[' io.github.x0b.rcx.rCloneVersion' ]
6- RCLONE_REPOSITORY = ' github.com/rclone/rclone'
7- GO_PATH = Paths . get(projectDir. absolutePath, ' gopath' ). toAbsolutePath(). toString()
6+ RCLONE_MODULE = ' github.com/rclone/rclone'
7+ CACHE_PATH = Paths . get(projectDir. absolutePath, ' cache' ). toAbsolutePath(). toString()
8+ GOPATH = Paths . get(CACHE_PATH , " gopath" ). toString()
89}
910
1011def findSdkDir () {
@@ -83,29 +84,35 @@ def buildRclone(compiler, arch, abi, env = [:]) {
8384 return {
8485 doLast {
8586 exec {
86- environment ' GOPATH' , GO_PATH
87+ environment ' GOPATH' , GOPATH
8788 def crossCompiler = getCrossCompiler(compiler)
8889 environment ' CC' , crossCompiler
8990 environment ' CC_FOR_TARGET' , crossCompiler
9091 environment ' GOOS' , ' android'
9192 environment ' GOARCH' , arch
9293 environment ' CGO_ENABLED' , ' 1'
9394 env. each {entry -> environment " $entry . key " , " $entry . value " }
94- commandLine ' go' , ' build' , ' -tags' , ' linux' , ' -o' , getLibrclone(abi), RCLONE_REPOSITORY
95+ workingDir CACHE_PATH
96+ commandLine ' go' , ' build' , ' -tags' , ' linux' , ' -o' , getLibrclone(abi), RCLONE_MODULE
9597 }
9698 }
9799 }
98100}
99101
100- task fetchRclone (type : Exec ) {
101- mkdir GO_PATH
102- environment ' GOPATH' , GO_PATH
103- commandLine ' go' , ' get' , ' -d' , RCLONE_REPOSITORY
102+ task createRcloneModule (type : Exec ) {
103+ // We create a fake go module as it's the only way to checkout
104+ // a specific tag.
105+ onlyIf { ! Paths . get(CACHE_PATH , ' go.mod' ). toFile(). exists() }
106+ mkdir CACHE_PATH
107+ workingDir CACHE_PATH
108+ environment ' GOPATH' , GOPATH
109+ commandLine ' go' , ' mod' , ' init' , ' rclone'
104110}
105111
106- task checkoutRclone (type : Exec , dependsOn : fetchRclone) {
107- workingDir Paths . get(GO_PATH , ' src' , * RCLONE_REPOSITORY . split(' /' ))
108- commandLine ' git' , ' checkout' , ' v' + RCLONE_VERSION
112+ task checkoutRclone (type : Exec , dependsOn : createRcloneModule) {
113+ workingDir CACHE_PATH
114+ environment ' GOPATH' , GOPATH
115+ commandLine ' go' , ' get' , ' -v' , ' -d' , " ${ RCLONE_MODULE} @v${ RCLONE_VERSION} "
109116}
110117
111118task cleanNative {
0 commit comments