From: Stewart Miles Date: Tue, 22 Jul 2014 00:56:53 +0000 (-0700) Subject: Terminate the output directory argument of flatc. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=60acef94e1c3b9b8bf6e94e8b06ff3651dab0627;p=platform%2Fupstream%2Fflatbuffers.git Terminate the output directory argument of flatc. Given the command flatc -o . -c test.fbs it would generate header file .test_generated.h rather than ./test_generated.h This fixes this issue. Tested: Manually verified that flatc generates the correct output files given output paths ending with and without '/' on Linux and Windows. Bug: 16464827 Change-Id: I854cb881286f22690f1885f942cf3fd2fc59ca8d --- diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index 0a3b051..a356f68 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -25,6 +25,13 @@ namespace flatbuffers { +static const char kPosixPathSeparator = '/'; +#ifdef _WIN32 +static const char kPathSeparator = '\\'; +#else +static const char kPathSeparator = kPosixPathSeparator; +#endif // _WIN32 + // Convert an integer or floating point value to a string. // In contrast to std::stringstream, "char" values are // converted to a string of digits. diff --git a/src/flatc.cpp b/src/flatc.cpp index 4327de7..058f402 100755 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -134,6 +134,10 @@ int main(int argc, const char *argv[]) { case 'o': if (++i >= argc) Error("missing path following", arg, true); output_path = argv[i]; + if (!(output_path.back() == flatbuffers::kPathSeparator || + output_path.back() == flatbuffers::kPosixPathSeparator)) { + output_path += flatbuffers::kPathSeparator; + } break; case 'S': opts.strict_json = true; @@ -212,4 +216,3 @@ int main(int argc, const char *argv[]) { return 0; } - diff --git a/src/idl_gen_java.cpp b/src/idl_gen_java.cpp index 35628cb..0d50dbe 100755 --- a/src/idl_gen_java.cpp +++ b/src/idl_gen_java.cpp @@ -22,11 +22,9 @@ #ifdef _WIN32 #include -#define PATH_SEPARATOR "\\" #define mkdir(n, m) _mkdir(n) #else #include -#define PATH_SEPARATOR "/" #endif namespace flatbuffers { @@ -360,7 +358,7 @@ static bool SaveClass(const Parser &parser, const Definition &def, it != parser.name_space_.end(); ++it) { if (name_space_java.length()) { name_space_java += "."; - name_space_dir += PATH_SEPARATOR; + name_space_dir += kPathSeparator; } name_space_java += *it; name_space_dir += *it; @@ -374,7 +372,7 @@ static bool SaveClass(const Parser &parser, const Definition &def, code += "import flatbuffers.*;\n\n"; } code += classcode; - auto filename = name_space_dir + PATH_SEPARATOR + def.name + ".java"; + auto filename = name_space_dir + kPathSeparator + def.name + ".java"; return SaveFile(filename.c_str(), code, false); } @@ -406,4 +404,3 @@ bool GenerateJava(const Parser &parser, } } // namespace flatbuffers -