mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-02 05:58:18 +00:00
[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:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -168,8 +168,6 @@ jobs:
|
|||||||
|
|
||||||
build-android:
|
build-android:
|
||||||
name: Build Android (on Linux)
|
name: Build Android (on Linux)
|
||||||
# Renable once it is working again.
|
|
||||||
if: false
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ndkVersion "21.3.6528147"
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
path "src/main/cpp/CMakeLists.txt"
|
path "src/main/cpp/CMakeLists.txt"
|
||||||
@@ -52,16 +51,17 @@ android {
|
|||||||
fbsFiles.forEach{
|
fbsFiles.forEach{
|
||||||
commandLineArgs.add(it.path)
|
commandLineArgs.add(it.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
commandLine commandLineArgs
|
commandLine commandLineArgs
|
||||||
|
|
||||||
doFirst {
|
doFirst {
|
||||||
delete "$outputCppDir/"
|
delete "$outputCppDir/"
|
||||||
mkdir "$outputCppDir/"
|
mkdir "$outputCppDir/"
|
||||||
}
|
}
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
if (execResult.getExitValue() != 0) {
|
if (executionResult.get().exitValue != 0) {
|
||||||
println(standardOutput.toString())
|
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
|
||||||
throw new GradleException("flatc command line failed")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,10 @@ android {
|
|||||||
|
|
||||||
standardOutput = new ByteArrayOutputStream()
|
standardOutput = new ByteArrayOutputStream()
|
||||||
errorOutput = new ByteArrayOutputStream()
|
errorOutput = new ByteArrayOutputStream()
|
||||||
|
|
||||||
|
setErrorOutput(errorOutput)
|
||||||
|
setStandardOutput(standardOutput)
|
||||||
|
|
||||||
def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
|
def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
|
||||||
fbsFiles.forEach{
|
fbsFiles.forEach{
|
||||||
commandLineArgs.add(it.path)
|
commandLineArgs.add(it.path)
|
||||||
@@ -85,17 +89,16 @@ android {
|
|||||||
mkdir "$outputKotlinDir/"
|
mkdir "$outputKotlinDir/"
|
||||||
}
|
}
|
||||||
doLast {
|
doLast {
|
||||||
if (execResult.getExitValue() != 0) {
|
if (executionResult.get().exitValue != 0) {
|
||||||
println(standardOutput.toString())
|
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
|
||||||
throw new GradleException("flatc command line failed")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
android.applicationVariants.all { variant ->
|
tasks.named("preBuild") {
|
||||||
variant.javaCompiler.dependsOn(generateFbsKotlin)
|
dependsOn(generateFbsKotlin)
|
||||||
variant.javaCompiler.dependsOn(generateFbsCpp)
|
dependsOn(generateFbsCpp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
verifier.VerifyString(name()) &&
|
verifier.VerifyString(name()) &&
|
||||||
VerifyOffset(verifier, VT_SOUND) &&
|
VerifyOffset(verifier, VT_SOUND) &&
|
||||||
verifier.VerifyString(sound()) &&
|
verifier.VerifyString(sound()) &&
|
||||||
VerifyField<uint16_t>(verifier, VT_WEIGHT) &&
|
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -57,7 +57,6 @@ struct AnimalBuilder {
|
|||||||
: fbb_(_fbb) {
|
: fbb_(_fbb) {
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
}
|
}
|
||||||
AnimalBuilder &operator=(const AnimalBuilder &);
|
|
||||||
flatbuffers::Offset<Animal> Finish() {
|
flatbuffers::Offset<Animal> Finish() {
|
||||||
const auto end = fbb_.EndTable(start_);
|
const auto end = fbb_.EndTable(start_);
|
||||||
auto o = flatbuffers::Offset<Animal>(end);
|
auto o = flatbuffers::Offset<Animal>(end);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import kotlin.math.sign
|
|||||||
import com.google.flatbuffers.*
|
import com.google.flatbuffers.*
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@ExperimentalUnsignedTypes
|
|
||||||
class Animal : Table() {
|
class Animal : Table() {
|
||||||
|
|
||||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -134,9 +134,10 @@ class KotlinGenerator : public BaseGenerator {
|
|||||||
code += "import com.google.flatbuffers.*\n\n";
|
code += "import com.google.flatbuffers.*\n\n";
|
||||||
}
|
}
|
||||||
code += classcode;
|
code += classcode;
|
||||||
auto filename = namer_.Directories(ns)
|
const std::string dirs = namer_.Directories(ns);
|
||||||
+ namer_.File(defname, SkipFile::Suffix);
|
EnsureDirExists(dirs);
|
||||||
|
const std::string filename =
|
||||||
|
dirs + namer_.File(defname, /*skips=*/SkipFile::Suffix);
|
||||||
return SaveFile(filename.c_str(), code, false);
|
return SaveFile(filename.c_str(), code, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user