Add the file a symbol is declared in to Reflection (#6613)

* Add the file a symbol is declared in to Reflection

If we move a code-generator to depend on Reflection,
it may need to know which file something was declared in
to properly name generated files.

* Doc comments in reflection, and more precise tests

* Add --project-root flag to flatc, normalize declaraion_file to this root

* fix --project-root stuff

* posixpath

* fix scripts

* format

* rename --project-root to --bfbs-filenames

Also, make it optional, rather than defaulting to `./`, if its not
specified, then don't serialize the filenames.

* bfbs generation

* fix some tests

* uncomment a thing

* add  to project root directory conditionally

* fix

* git clang format

* Added help description and removed != nullptr

* "

* Remove accidental change to docs

* Remove accidental change to docs

* Pool strings

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2021-06-17 11:50:04 -04:00
committed by GitHub
parent 2cf7bb7966
commit c58ae94225
20 changed files with 868 additions and 674 deletions

View File

@@ -178,6 +178,9 @@ std::string PosixPath(const char *path) {
std::replace(p.begin(), p.end(), '\\', '/');
return p;
}
std::string PosixPath(const std::string &path) {
return PosixPath(path.c_str());
}
void EnsureDirExists(const std::string &filepath) {
auto parent = StripFileName(filepath);
@@ -217,6 +220,27 @@ std::string AbsolutePath(const std::string &filepath) {
// clang-format on
}
std::string RelativeToRootPath(const std::string &project,
const std::string &filepath) {
std::string absolute_project = PosixPath(AbsolutePath(project));
if (absolute_project.back() != '/') absolute_project += "/";
std::string absolute_filepath = PosixPath(AbsolutePath(filepath));
if (absolute_filepath.size() < absolute_project.size() ||
absolute_filepath.substr(0, absolute_project.size()) !=
absolute_project) {
printf(
"The --bfbs-filenames directory must contain all files and included "
"files.\n");
printf("project: %s\n", project.c_str());
printf("filepath: %s\n", filepath.c_str());
printf("absolute_project: %s\n", absolute_project.c_str());
printf("absolute_filepath:%s\n", absolute_filepath.c_str());
FLATBUFFERS_ASSERT(0);
}
const std::string relpath = absolute_filepath.substr(absolute_project.size());
return "//" + relpath;
}
// Locale-independent code.
#if defined(FLATBUFFERS_LOCALE_INDEPENDENT) && \
(FLATBUFFERS_LOCALE_INDEPENDENT > 0)