diff options
author | Brad King <brad.king@kitware.com> | 2021-02-26 14:21:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-02-26 15:31:27 (GMT) |
commit | 706e16bee5f6b5fccd284476a9157ecc8c39f12c (patch) | |
tree | 78ae9af75529605ffc98631e9a8bd28e9c981b9d /src | |
parent | 212cd97679e783de77230b009b23dd11344644ac (diff) | |
download | Ninja-706e16bee5f6b5fccd284476a9157ecc8c39f12c.zip Ninja-706e16bee5f6b5fccd284476a9157ecc8c39f12c.tar.gz Ninja-706e16bee5f6b5fccd284476a9157ecc8c39f12c.tar.bz2 |
Add tool to print code page information on Windows
Since commit 00459e2b (Use UTF-8 on Windows 10 Version 1903, fix #1195,
2021-02-17), `ninja` does not always expect `build.ninja` to be encoded
in the system's ANSI code page. The expected encoding now depends on
how `ninja` is built and the version of Windows on which it is running.
Add a `-t wincodepage` tool that generators can use to ask `ninja`
what encoding it expects.
Issue: #1195
Diffstat (limited to 'src')
-rw-r--r-- | src/ninja.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/ninja.cc b/src/ninja.cc index 96eac1d..3172ee5 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -133,6 +133,7 @@ struct NinjaMain : public BuildLogUser { int ToolRestat(const Options* options, int argc, char* argv[]); int ToolUrtle(const Options* options, int argc, char** argv); int ToolRules(const Options* options, int argc, char* argv[]); + int ToolWinCodePage(const Options* options, int argc, char* argv[]); /// Open the build log. /// @return LOAD_ERROR on error. @@ -641,6 +642,18 @@ int NinjaMain::ToolRules(const Options* options, int argc, char* argv[]) { return 0; } +#ifdef _WIN32 +int NinjaMain::ToolWinCodePage(const Options* options, int argc, char* argv[]) { + if (argc != 0) { + printf("usage: ninja -t wincodepage\n"); + return 1; + } + printf("ANSI code page: %u\n", GetACP()); + printf("Console code page: %u\n", GetConsoleOutputCP()); + return 0; +} +#endif + enum PrintCommandMode { PCM_Single, PCM_All }; void PrintCommands(Edge* edge, EdgeSet* seen, PrintCommandMode mode) { if (!edge) @@ -1009,6 +1022,10 @@ const Tool* ChooseTool(const string& tool_name) { Tool::RUN_AFTER_LOGS, &NinjaMain::ToolCleanDead }, { "urtle", NULL, Tool::RUN_AFTER_FLAGS, &NinjaMain::ToolUrtle }, +#ifdef _WIN32 + { "wincodepage", "print the Windows ANSI code page identifier", + Tool::RUN_AFTER_FLAGS, &NinjaMain::ToolWinCodePage }, +#endif { NULL, NULL, Tool::RUN_AFTER_FLAGS, NULL } }; |