-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix bfbs Lua/Nim generators: honor -o and create namespace dirs #8765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beingbrijesh
wants to merge
4
commits into
google:master
Choose a base branch
from
beingbrijesh:pr/fix-bfbs-namespace-output
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+374
−13
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9832f33
Fix bfbs Lua and Nim generators to respect -o output path
beingbrijesh a502c38
Add CTest integration and Python unit tests for bfbs namespace output
beingbrijesh 8edf3bd
Add golden schema and generated goldens for namespace-first case
beingbrijesh a38f03c
Merge branch 'master' into pr/fix-bfbs-namespace-output
aardappel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --[[ MyGame.Example.NamespaceTest | ||
|
|
||
| Automatically generated by the FlatBuffers compiler, do not modify. | ||
| Or modify. I'm a message, not a cop. | ||
|
|
||
| flatc version: 25.9.23 | ||
|
|
||
| Declared by : //namespace_first.fbs | ||
| Rooting type : MyGame.Example.NamespaceTest (//namespace_first.fbs) | ||
|
|
||
| --]] | ||
|
|
||
| local flatbuffers = require('flatbuffers') | ||
|
|
||
| local NamespaceTest = {} | ||
| local mt = {} | ||
|
|
||
| function NamespaceTest.New() | ||
| local o = {} | ||
| setmetatable(o, {__index = mt}) | ||
| return o | ||
| end | ||
|
|
||
| function NamespaceTest.GetRootAsNamespaceTest(buf, offset) | ||
| if type(buf) == "string" then | ||
| buf = flatbuffers.binaryArray.New(buf) | ||
| end | ||
|
|
||
| local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) | ||
| local o = NamespaceTest.New() | ||
| o:Init(buf, n + offset) | ||
| return o | ||
| end | ||
|
|
||
| function mt:Init(buf, pos) | ||
| self.view = flatbuffers.view.New(buf, pos) | ||
| end | ||
|
|
||
| function mt:Name() | ||
| local o = self.view:Offset(4) | ||
| if o ~= 0 then | ||
| return self.view:String(self.view.pos + o) | ||
| end | ||
| end | ||
|
|
||
| function mt:Value() | ||
| local o = self.view:Offset(6) | ||
| if o ~= 0 then | ||
| return self.view:Get(flatbuffers.N.Int32, self.view.pos + o) | ||
| end | ||
| return 0 | ||
| end | ||
|
|
||
| function NamespaceTest.Start(builder) | ||
| builder:StartObject(2) | ||
| end | ||
|
|
||
| function NamespaceTest.AddName(builder, name) | ||
| builder:PrependUOffsetTRelativeSlot(0, name, 0) | ||
| end | ||
|
|
||
| function NamespaceTest.AddValue(builder, value) | ||
| builder:PrependInt32Slot(1, value, 0) | ||
| end | ||
|
|
||
| function NamespaceTest.End(builder) | ||
| return builder:EndObject() | ||
| end | ||
|
|
||
| return NamespaceTest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --[[ flatbuffers.goldens.Galaxy | ||
|
|
||
| Automatically generated by the FlatBuffers compiler, do not modify. | ||
| Or modify. I'm a message, not a cop. | ||
|
|
||
| flatc version: 25.9.23 | ||
|
|
||
| Declared by : //basic.fbs | ||
| Rooting type : flatbuffers.goldens.Universe (//basic.fbs) | ||
|
|
||
| --]] | ||
|
|
||
| local flatbuffers = require('flatbuffers') | ||
|
|
||
| local Galaxy = {} | ||
| local mt = {} | ||
|
|
||
| function Galaxy.New() | ||
| local o = {} | ||
| setmetatable(o, {__index = mt}) | ||
| return o | ||
| end | ||
|
|
||
| function mt:Init(buf, pos) | ||
| self.view = flatbuffers.view.New(buf, pos) | ||
| end | ||
|
|
||
| function mt:NumStars() | ||
| local o = self.view:Offset(4) | ||
| if o ~= 0 then | ||
| return self.view:Get(flatbuffers.N.Int64, self.view.pos + o) | ||
| end | ||
| return 0 | ||
| end | ||
|
|
||
| function Galaxy.Start(builder) | ||
| builder:StartObject(1) | ||
| end | ||
|
|
||
| function Galaxy.AddNumStars(builder, numStars) | ||
| builder:PrependInt64Slot(0, numStars, 0) | ||
| end | ||
|
|
||
| function Galaxy.End(builder) | ||
| return builder:EndObject() | ||
| end | ||
|
|
||
| return Galaxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --[[ flatbuffers.goldens.Universe | ||
|
|
||
| Automatically generated by the FlatBuffers compiler, do not modify. | ||
| Or modify. I'm a message, not a cop. | ||
|
|
||
| flatc version: 25.9.23 | ||
|
|
||
| Declared by : //basic.fbs | ||
| Rooting type : flatbuffers.goldens.Universe (//basic.fbs) | ||
|
|
||
| --]] | ||
|
|
||
| local __flatbuffers_goldens_Galaxy = require('flatbuffers.goldens.Galaxy') | ||
| local flatbuffers = require('flatbuffers') | ||
|
|
||
| local Universe = {} | ||
| local mt = {} | ||
|
|
||
| function Universe.New() | ||
| local o = {} | ||
| setmetatable(o, {__index = mt}) | ||
| return o | ||
| end | ||
|
|
||
| function Universe.GetRootAsUniverse(buf, offset) | ||
| if type(buf) == "string" then | ||
| buf = flatbuffers.binaryArray.New(buf) | ||
| end | ||
|
|
||
| local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) | ||
| local o = Universe.New() | ||
| o:Init(buf, n + offset) | ||
| return o | ||
| end | ||
|
|
||
| function mt:Init(buf, pos) | ||
| self.view = flatbuffers.view.New(buf, pos) | ||
| end | ||
|
|
||
| function mt:Age() | ||
| local o = self.view:Offset(4) | ||
| if o ~= 0 then | ||
| return self.view:Get(flatbuffers.N.Float64, self.view.pos + o) | ||
| end | ||
| return 0.0 | ||
| end | ||
|
|
||
| function mt:Galaxies(j) | ||
| local o = self.view:Offset(6) | ||
| if o ~= 0 then | ||
| local x = self.view:Vector(o) | ||
| x = x + ((j-1) * 4) | ||
| x = self.view:Indirect(x) | ||
| local obj = __flatbuffers_goldens_Galaxy.New() | ||
| obj:Init(self.view.bytes, x) | ||
| return obj | ||
| end | ||
| end | ||
|
|
||
| function mt:GalaxiesLength() | ||
| local o = self.view:Offset(6) | ||
| if o ~= 0 then | ||
| return self.view:VectorLen(o) | ||
| end | ||
| return 0 | ||
| end | ||
|
|
||
| function Universe.Start(builder) | ||
| builder:StartObject(2) | ||
| end | ||
|
|
||
| function Universe.AddAge(builder, age) | ||
| builder:PrependFloat64Slot(0, age, 0.0) | ||
| end | ||
|
|
||
| function Universe.AddGalaxies(builder, galaxies) | ||
| builder:PrependUOffsetTRelativeSlot(1, galaxies, 0) | ||
| end | ||
|
|
||
| function Universe.StartGalaxiesVector(builder, numElems) | ||
| return builder:StartVector(4, numElems, 4) | ||
| end | ||
|
|
||
| function Universe.End(builder) | ||
| return builder:EndObject() | ||
| end | ||
|
|
||
| return Universe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #[ flatbuffers.goldens.Galaxy | ||
| Automatically generated by the FlatBuffers compiler, do not modify. | ||
| Or modify. I'm a message, not a cop. | ||
|
|
||
| flatc version: 25.9.23 | ||
|
|
||
| Declared by : //basic.fbs | ||
| Rooting type : flatbuffers.goldens.Universe (//basic.fbs) | ||
| ]# | ||
|
|
||
| import flatbuffers | ||
|
|
||
| type Galaxy* = object of FlatObj | ||
| func numStars*(self: Galaxy): int64 = | ||
| let o = self.tab.Offset(4) | ||
| if o != 0: | ||
| return Get[int64](self.tab, self.tab.Pos + o) | ||
| return 0 | ||
| func `numStars=`*(self: var Galaxy, n: int64): bool = | ||
| return self.tab.MutateSlot(4, n) | ||
| proc GalaxyStart*(builder: var Builder) = | ||
| builder.StartObject(1) | ||
| proc GalaxyAddnumStars*(builder: var Builder, numStars: int64) = | ||
| builder.PrependSlot(0, numStars, default(int64)) | ||
| proc GalaxyEnd*(builder: var Builder): uoffset = | ||
| return builder.EndObject() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #[ flatbuffers.goldens.Universe | ||
| Automatically generated by the FlatBuffers compiler, do not modify. | ||
| Or modify. I'm a message, not a cop. | ||
|
|
||
| flatc version: 25.9.23 | ||
|
|
||
| Declared by : //basic.fbs | ||
| Rooting type : flatbuffers.goldens.Universe (//basic.fbs) | ||
| ]# | ||
|
|
||
| import Galaxy as flatbuffers_goldens_Galaxy | ||
| import flatbuffers | ||
| import std/options | ||
|
|
||
| type Universe* = object of FlatObj | ||
| func age*(self: Universe): float64 = | ||
| let o = self.tab.Offset(4) | ||
| if o != 0: | ||
| return Get[float64](self.tab, self.tab.Pos + o) | ||
| return 0.0 | ||
| func `age=`*(self: var Universe, n: float64): bool = | ||
| return self.tab.MutateSlot(4, n) | ||
| func galaxiesLength*(self: Universe): int = | ||
| let o = self.tab.Offset(6) | ||
| if o != 0: | ||
| return self.tab.VectorLen(o) | ||
| func galaxies*(self: Universe, j: int): flatbuffers_goldens_Galaxy.Galaxy = | ||
| let o = self.tab.Offset(6) | ||
| if o != 0: | ||
| var x = self.tab.Vector(o) | ||
| x += j.uoffset * 4.uoffset | ||
| return flatbuffers_goldens_Galaxy.Galaxy(tab: Vtable(Bytes: self.tab.Bytes, Pos: x)) | ||
| func galaxies*(self: Universe): seq[flatbuffers_goldens_Galaxy.Galaxy] = | ||
| let len = self.galaxiesLength | ||
| for i in countup(0, len - 1): | ||
| result.add(self.galaxies(i)) | ||
| proc UniverseStart*(builder: var Builder) = | ||
| builder.StartObject(2) | ||
| proc UniverseAddage*(builder: var Builder, age: float64) = | ||
| builder.PrependSlot(0, age, default(float64)) | ||
| proc UniverseAddgalaxies*(builder: var Builder, galaxies: uoffset) = | ||
| builder.PrependSlot(1, galaxies, default(uoffset)) | ||
| proc UniverseStartgalaxiesVector*(builder: var Builder, numElems: uoffset) = | ||
| builder.StartVector(4, numElems, 4) | ||
| proc UniverseEnd*(builder: var Builder): uoffset = | ||
| return builder.EndObject() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| namespace MyGame.Example; | ||
|
|
||
| table NamespaceTest { | ||
| name:string; | ||
| value:int; | ||
| } | ||
|
|
||
| root_type NamespaceTest; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Test that bfbs generators handle namespace-first schemas correctly | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love this change since it integrates with IDEs better. Would you be able to add |
||
| find_package(Python3 REQUIRED COMPONENTS Interpreter) | ||
|
|
||
| add_test( | ||
| NAME test_bfbs_namespace_output | ||
| COMMAND ${Python3_EXECUTABLE} -m unittest test_bfbs_namespace_output.py -v | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the old TODO which was here is still relevant