add version check of flatc for flclient

This commit is contained in:
zhoushan 2021-09-14 20:54:47 +08:00
parent 46ff960ebe
commit 4fc0b87e22
1 changed files with 35 additions and 6 deletions

View File

@ -57,20 +57,49 @@ dependencies {
} }
def getFlatVersion(path) {
def version = new ByteArrayOutputStream()
def cmd = path + ' --version'
exec {
ExecSpec execSpec ->
executable 'bash'
args '-c', cmd
standardOutput = version
}
return version.toString().split()[2]
}
import io.netifi.flatbuffers.plugin.tasks.FlatBuffers import io.netifi.flatbuffers.plugin.tasks.FlatBuffers
flatbuffers { flatbuffers {
String msLib = System.getenv("MSLIBS_CACHE_PATH").toString() String msLib = System.getenv("MSLIBS_CACHE_PATH").toString()
FileTree msLibTree = fileTree(dir: msLib, include: ["flatbuffers_*/bin/flatc"]) //flatbuffers_*/bin/flatc FileTree msLibTree = fileTree(dir: msLib, include: ["flatbuffers_*/bin/flatc"])
String msLibPath = '' String msLibPath = ''
msLibTree.each {File file -> String libPath = ''
msLibPath = file.toString() msLibTree.find {File file ->
libPath = file.toString()
println('flatc Path: ' + libPath)
String version = getFlatVersion(libPath)
println('version: ' + version)
if ('1.11.0' == version) {
msLibPath = libPath
return true
}
} }
if (msLibTree.empty) { if (file('../../../build/_deps/flatbuffers-src/_build/flatc').exists()) {
flatcPath = '../../../build/_deps/flatbuffers-src/_build/flatc' String version = getFlatVersion('../../../build/_deps/flatbuffers-src/_build/flatc')
} else { println('version: ' + version)
if ('1.11.0' == version) {
flatcPath = '../../../build/_deps/flatbuffers-src/_build/flatc'
} else {
println('the version of build flatc is not valid, will find the other flatc')
}
} else if (msLibPath != '' && file(msLibPath).exists()){
flatcPath = msLibPath flatcPath = msLibPath
} else {
println("the needed flatc of version 1.11.0 is not exist, please check")
} }
println("the used flatc path: " + flatcPath)
} }
task createFlatBuffers(type: FlatBuffers) { task createFlatBuffers(type: FlatBuffers) {