[Kotlin] Make sure namespace path exist for code generation (#7357)

With a change introduce in 385dda5c3785ed8d6a35868bc169f07e40e889087fd2edc66,
flatc was not able to emit code for Kotlin if a namespace is specified
and the folders do not exist. The fix create folders if neded.

Additional changes are introduced in gradle files to bring more visibility
to the error messages.

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Paulo Pinheiro
2022-08-15 19:13:27 +02:00
committed by GitHub
parent 137fec7164
commit a3508f36d5
6 changed files with 19 additions and 19 deletions

View File

@@ -168,8 +168,6 @@ jobs:
build-android:
name: Build Android (on Linux)
# Renable once it is working again.
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

View File

@@ -33,7 +33,6 @@ android {
}
}
ndkVersion "21.3.6528147"
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
@@ -52,16 +51,17 @@ android {
fbsFiles.forEach{
commandLineArgs.add(it.path)
}
commandLine commandLineArgs
doFirst {
delete "$outputCppDir/"
mkdir "$outputCppDir/"
}
doLast {
if (execResult.getExitValue() != 0) {
println(standardOutput.toString())
throw new GradleException("flatc command line failed")
if (executionResult.get().exitValue != 0) {
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
}
}
}
@@ -74,6 +74,10 @@ android {
standardOutput = new ByteArrayOutputStream()
errorOutput = new ByteArrayOutputStream()
setErrorOutput(errorOutput)
setStandardOutput(standardOutput)
def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
fbsFiles.forEach{
commandLineArgs.add(it.path)
@@ -85,17 +89,16 @@ android {
mkdir "$outputKotlinDir/"
}
doLast {
if (execResult.getExitValue() != 0) {
println(standardOutput.toString())
throw new GradleException("flatc command line failed")
if (executionResult.get().exitValue != 0) {
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
}
}
}
afterEvaluate {
android.applicationVariants.all { variant ->
variant.javaCompiler.dependsOn(generateFbsKotlin)
variant.javaCompiler.dependsOn(generateFbsCpp)
tasks.named("preBuild") {
dependsOn(generateFbsKotlin)
dependsOn(generateFbsCpp)
}
}

View File

@@ -35,7 +35,7 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
verifier.VerifyString(name()) &&
VerifyOffset(verifier, VT_SOUND) &&
verifier.VerifyString(sound()) &&
VerifyField<uint16_t>(verifier, VT_WEIGHT) &&
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) &&
verifier.EndTable();
}
};
@@ -57,7 +57,6 @@ struct AnimalBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
AnimalBuilder &operator=(const AnimalBuilder &);
flatbuffers::Offset<Animal> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Animal>(end);

View File

@@ -7,7 +7,6 @@ import kotlin.math.sign
import com.google.flatbuffers.*
@Suppress("unused")
@ExperimentalUnsignedTypes
class Animal : Table() {
fun __init(_i: Int, _bb: ByteBuffer) {

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -134,9 +134,10 @@ class KotlinGenerator : public BaseGenerator {
code += "import com.google.flatbuffers.*\n\n";
}
code += classcode;
auto filename = namer_.Directories(ns)
+ namer_.File(defname, SkipFile::Suffix);
const std::string dirs = namer_.Directories(ns);
EnsureDirExists(dirs);
const std::string filename =
dirs + namer_.File(defname, /*skips=*/SkipFile::Suffix);
return SaveFile(filename.c_str(), code, false);
}