From 4fc0b87e22eba4ab880bd251a698668fec9d9864 Mon Sep 17 00:00:00 2001 From: zhoushan Date: Tue, 14 Sep 2021 20:54:47 +0800 Subject: [PATCH] add version check of flatc for flclient --- .../lite/java/java/fl_client/build.gradle | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/mindspore/lite/java/java/fl_client/build.gradle b/mindspore/lite/java/java/fl_client/build.gradle index 5a176dbe9ab..947e85292e8 100644 --- a/mindspore/lite/java/java/fl_client/build.gradle +++ b/mindspore/lite/java/java/fl_client/build.gradle @@ -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 flatbuffers { 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 = '' - msLibTree.each {File file -> - msLibPath = file.toString() + String libPath = '' + 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) { - flatcPath = '../../../build/_deps/flatbuffers-src/_build/flatc' - } else { + if (file('../../../build/_deps/flatbuffers-src/_build/flatc').exists()) { + String version = getFlatVersion('../../../build/_deps/flatbuffers-src/_build/flatc') + 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 + } 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) {