Skip to content

Commit

Permalink
Have cmake copy flatbuffer schema files to simplify dev (#3446)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptocode authored Sep 13, 2021
1 parent 84f4efd commit 4e2ffe9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 6 additions & 0 deletions nano/ipc_flatbuffers_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ foreach(file ${files})
message(
"Generating flatbuffers code for: ${flatbuffers_filename} into ${CMAKE_CURRENT_SOURCE_DIR}/generated/flatbuffers"
)

configure_file(
${file}
${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/api/flatbuffers/${flatbuffers_filename}.fbs
COPYONLY)

add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/generated/flatbuffers/${flatbuffers_filename}_generated.h
Expand Down
18 changes: 4 additions & 14 deletions nano/node/ipc/flatbuffers_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,15 @@ std::string make_error_response (std::string const & error_message)

/**
* Returns the 'api/flatbuffers' directory, boost::none if not found.
* This searches the binary path as well as the parent (which is mostly useful for development)
*/
boost::optional<boost::filesystem::path> get_api_path ()
{
auto parent_path = boost::dll::program_location ().parent_path ();
if (!boost::filesystem::exists (parent_path / "api" / "flatbuffers"))
boost::filesystem::path const fb_path = "api/flatbuffers";
if (!boost::filesystem::exists (fb_path))
{
// See if the parent directory has the api subdirectories
if (parent_path.has_parent_path ())
{
parent_path = boost::dll::program_location ().parent_path ().parent_path ();
}

if (!boost::filesystem::exists (parent_path / "api" / "flatbuffers"))
{
return boost::none;
}
return boost::none;
}
return parent_path / "api" / "flatbuffers";
return fb_path;
}
}

Expand Down

0 comments on commit 4e2ffe9

Please # to comment.