mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
* TS/ES6 modules spike iteration 1 * Initial modularized dasherized output * Remove obsoleted parts and namespace wrapping * Use _flatbuffers_ prefix * First part of imports logic * Second part of imports logic * Fix TS/JS code removal mixup * Alias imported symbols if same name from different namespaces and some fixes * Use star import for bare imports * Fix messed up string concat * var to const and remove not needed semi * Remove some cases of ns prefixing * Add missing space * Cleanups * Completed initial import tracking logic * Compilable output * Adjust TypeScriptTest and dependents to work * Use local flatbuffers package for tests * Refactor away use of any * Remove obsolete imported_fileset and reexport_map * Still need any and fix JavaScriptTest.sh * Fix test runs out of the box * Temp add generated files * TypeScriptTest replaces JavaScriptTest and cleanups * Also remove reference to JavaScriptTest in TestAll.sh * Remove old generated ts/js files * Remove use of --js in generate_code scripts * idl_gen_js_ts to idl_gen_ts and removal of js gen * Remove obsoleted options * Fix obsolete ts test detection * Tweak ts compilation be as strict as possible * Remove jsdoc type annotation generation * Generated test ts files * Fix search and replace messup * Regenerated ts test output * Use CharToLower * Use normal for loop * Rework namespacedir * Revert "Rework namespacedir" This reverts commit 6f4eb0104ceeb86011bb076ebca901138c48e068. * Revert "Use normal for loop" This reverts commit 676b2135bfaa1853dfbb06c92b5c16a0d81bb13a. * Revert "Use CharToLower" This reverts commit 2d08648d0d72d0af201fad80d54cdc76412b35e9. * Again do rework but correct * Avoid runtime cast * Fix test runs * Also add npm install to get tsc * Bump node test versions * for range to std for loop * Clang format * Missed one clang format * Move accessor to later * Attempt to make windows version of TypeScriptTest * Want to see the output * Try to get newer node at appveyor * Style changes
119 lines
5.1 KiB
C++
119 lines
5.1 KiB
C++
/*
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "flatbuffers/flatc.h"
|
|
#include "flatbuffers/util.h"
|
|
|
|
static const char *g_program_name = nullptr;
|
|
|
|
static void Warn(const flatbuffers::FlatCompiler *flatc,
|
|
const std::string &warn, bool show_exe_name) {
|
|
(void)flatc;
|
|
if (show_exe_name) { printf("%s: ", g_program_name); }
|
|
printf("warning: %s\n", warn.c_str());
|
|
}
|
|
|
|
static void Error(const flatbuffers::FlatCompiler *flatc,
|
|
const std::string &err, bool usage, bool show_exe_name) {
|
|
if (show_exe_name) { printf("%s: ", g_program_name); }
|
|
printf("error: %s\n", err.c_str());
|
|
if (usage && flatc) {
|
|
printf("%s", flatc->GetUsageString(g_program_name).c_str());
|
|
}
|
|
exit(1);
|
|
}
|
|
|
|
namespace flatbuffers {
|
|
void LogCompilerWarn(const std::string &warn) {
|
|
Warn(static_cast<const flatbuffers::FlatCompiler *>(nullptr), warn, true);
|
|
}
|
|
void LogCompilerError(const std::string &err) {
|
|
Error(static_cast<const flatbuffers::FlatCompiler *>(nullptr), err, false,
|
|
true);
|
|
}
|
|
} // namespace flatbuffers
|
|
|
|
int main(int argc, const char *argv[]) {
|
|
// Prevent Appveyor-CI hangs.
|
|
flatbuffers::SetupDefaultCRTReportMode();
|
|
|
|
g_program_name = argv[0];
|
|
|
|
const flatbuffers::FlatCompiler::Generator generators[] = {
|
|
{ flatbuffers::GenerateBinary, "-b", "--binary", "binary", false, nullptr,
|
|
flatbuffers::IDLOptions::kBinary,
|
|
"Generate wire format binaries for any data definitions",
|
|
flatbuffers::BinaryMakeRule },
|
|
{ flatbuffers::GenerateTextFile, "-t", "--json", "text", false, nullptr,
|
|
flatbuffers::IDLOptions::kJson,
|
|
"Generate text output for any data definitions",
|
|
flatbuffers::TextMakeRule },
|
|
{ flatbuffers::GenerateCPP, "-c", "--cpp", "C++", true,
|
|
flatbuffers::GenerateCppGRPC, flatbuffers::IDLOptions::kCpp,
|
|
"Generate C++ headers for tables/structs", flatbuffers::CPPMakeRule },
|
|
{ flatbuffers::GenerateGo, "-g", "--go", "Go", true,
|
|
flatbuffers::GenerateGoGRPC, flatbuffers::IDLOptions::kGo,
|
|
"Generate Go files for tables/structs", nullptr },
|
|
{ flatbuffers::GenerateJava, "-j", "--java", "Java", true,
|
|
flatbuffers::GenerateJavaGRPC, flatbuffers::IDLOptions::kJava,
|
|
"Generate Java classes for tables/structs",
|
|
flatbuffers::JavaCSharpMakeRule },
|
|
{ flatbuffers::GenerateDart, "-d", "--dart", "Dart", true, nullptr,
|
|
flatbuffers::IDLOptions::kDart,
|
|
"Generate Dart classes for tables/structs", flatbuffers::DartMakeRule },
|
|
{ flatbuffers::GenerateTS, "-T", "--ts", "TypeScript", true,
|
|
flatbuffers::GenerateTSGRPC, flatbuffers::IDLOptions::kTs,
|
|
"Generate TypeScript code for tables/structs", flatbuffers::TSMakeRule },
|
|
{ flatbuffers::GenerateCSharp, "-n", "--csharp", "C#", true, nullptr,
|
|
flatbuffers::IDLOptions::kCSharp,
|
|
"Generate C# classes for tables/structs",
|
|
flatbuffers::JavaCSharpMakeRule },
|
|
{ flatbuffers::GeneratePython, "-p", "--python", "Python", true,
|
|
flatbuffers::GeneratePythonGRPC, flatbuffers::IDLOptions::kPython,
|
|
"Generate Python files for tables/structs", nullptr },
|
|
{ flatbuffers::GenerateLobster, nullptr, "--lobster", "Lobster", true,
|
|
nullptr, flatbuffers::IDLOptions::kLobster,
|
|
"Generate Lobster files for tables/structs", nullptr },
|
|
{ flatbuffers::GenerateLua, "-l", "--lua", "Lua", true, nullptr,
|
|
flatbuffers::IDLOptions::kLua, "Generate Lua files for tables/structs",
|
|
nullptr },
|
|
{ flatbuffers::GenerateRust, "-r", "--rust", "Rust", true, nullptr,
|
|
flatbuffers::IDLOptions::kRust, "Generate Rust files for tables/structs",
|
|
flatbuffers::RustMakeRule },
|
|
{ flatbuffers::GeneratePhp, nullptr, "--php", "PHP", true, nullptr,
|
|
flatbuffers::IDLOptions::kPhp, "Generate PHP files for tables/structs",
|
|
nullptr },
|
|
{ flatbuffers::GenerateKotlin, nullptr, "--kotlin", "Kotlin", true, nullptr,
|
|
flatbuffers::IDLOptions::kKotlin,
|
|
"Generate Kotlin classes for tables/structs", nullptr },
|
|
{ flatbuffers::GenerateJsonSchema, nullptr, "--jsonschema", "JsonSchema",
|
|
true, nullptr, flatbuffers::IDLOptions::kJsonSchema,
|
|
"Generate Json schema", nullptr },
|
|
{ flatbuffers::GenerateSwift, nullptr, "--swift", "swift", true,
|
|
flatbuffers::GenerateSwiftGRPC, flatbuffers::IDLOptions::kSwift,
|
|
"Generate Swift files for tables/structs", nullptr },
|
|
};
|
|
|
|
flatbuffers::FlatCompiler::InitParams params;
|
|
params.generators = generators;
|
|
params.num_generators = sizeof(generators) / sizeof(generators[0]);
|
|
params.warn_fn = Warn;
|
|
params.error_fn = Error;
|
|
|
|
flatbuffers::FlatCompiler flatc(params);
|
|
return flatc.Compile(argc - 1, argv + 1);
|
|
}
|