Flatbuffers: incorrect import in generated Dart file

Created on 3 Apr 2019  路  9Comments  路  Source: google/flatbuffers

Hi,

I think there is a problem with generated import statements in Dart.

what I have:

  1. a schema and a lib directories within the current directory
  2. the schema has the following structure:
./schema
    +-message-types.fbs
    +-ws
      +-place-search-req.fbs
  1. the lib directory and it's contents is automatically generated by flatc to form the following structure:
./lib
   +-dart
       +-message-types_s_t_m_g_generated.dart
       +-ws
          +-place-search-req_s_t_m_g_generated.dart
  1. the message-types.fbs file's content:
file_identifier "STMG";
file_extension "bin";

namespace STMG;

enum MessageType : uint64 {
  SEARCH_PLACE_REQUEST,
  SEARCH_PLACE_RESULT,
}
  1. the place-search-req.fbs file's content:
include "../message-types.fbs";

file_identifier "STMG";
file_extension "bin";

namespace STMG;

table PlaceSearchReq {
  mType: MessageType;
  terms: [string];
}

root_type PlaceSearchReq;

The place-search-req_s_t_m_g_generated.dart has an import statement with the following value: import 'message-types_s_t_m_g_generated.dart';.

As you can see, the generated import statement is incorrect, because the file being imported is located in the parent directory. In other words, this would be a correct import statement: import '../message-types_s_t_m_g_generated.dart';

The question is: am I _missing_ something? Seems that -I PATH, --include-prefix PATH, and --keep-prefix options do not affect this case.

flatc version 1.10.0 (Oct 5 2018 07:47:40)

Thanks!

stale

All 9 comments

@dnfield ?

I believe the culprit is https://github.com/google/flatbuffers/blob/master/src/idl_gen_dart.cpp#L88

I can try to take a look at this at some point, or would be happy to review a patch for it.

I believe the culprit is https://github.com/google/flatbuffers/blob/master/src/idl_gen_dart.cpp#L88

I can try to take a look at this at some point, or would be happy to review a patch for it.

thank you sir. unfortunately I cannot write C++, I wish idl generator had been written in python...

How are you generating these files?

If I generate them all in one go with something like:

~/src/flatbuffers/flatc --dart schema/message-types.fbs schema/ws/place-search-req.fbs 

I get my generated files right in the same directory with the imports looking correct.

I call the following command for each file:

flatc --gen-all --dart -I <some-path-here> -o <output-dir> <single>.fbs

ah.. okey

How are you generating these files?

If I generate them all in one go with something like:

~/src/flatbuffers/flatc --dart schema/message-types.fbs schema/ws/place-search-req.fbs 

I get my generated files right in the same directory with the imports looking correct.

I grouped *.fbs files in directories and want to replicate the same directory structure for generated files. It seems that this is not feasible with your approach :(

Do the other generators work this way?

Do the other generators work this way?

not sure. Will try it in couple of days and report back (dart)

This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lixin-wei picture lixin-wei  路  7Comments

mjvankampen picture mjvankampen  路  5Comments

siebeneicher picture siebeneicher  路  6Comments

Yooong-W picture Yooong-W  路  4Comments

dakom picture dakom  路  8Comments