diff options
-rw-r--r-- | CMakeLists.txt | 16 | ||||
-rw-r--r-- | src/config.h.in | 2 | ||||
-rw-r--r-- | src/option-parser.cc | 11 | ||||
-rw-r--r-- | src/option-parser.h | 3 | ||||
-rw-r--r-- | src/tools/spectest-interp.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm-decompile.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm-interp.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm-objdump.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm-opcodecnt.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm-strip.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm-validate.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm2c.cc | 1 | ||||
-rw-r--r-- | src/tools/wasm2wat.cc | 1 | ||||
-rw-r--r-- | src/tools/wast2json.cc | 1 | ||||
-rw-r--r-- | src/tools/wat-desugar.cc | 1 | ||||
-rw-r--r-- | src/tools/wat2wasm.cc | 1 | ||||
-rw-r--r-- | test/help/spectest-interp.txt | 3 | ||||
-rw-r--r-- | test/help/wasm-interp.txt | 3 | ||||
-rw-r--r-- | test/help/wasm-objdump.txt | 3 | ||||
-rw-r--r-- | test/help/wasm-opcodecnt.txt | 3 | ||||
-rw-r--r-- | test/help/wasm-validate.txt | 3 | ||||
-rw-r--r-- | test/help/wasm2wat.txt | 3 | ||||
-rw-r--r-- | test/help/wast2json.txt | 3 | ||||
-rw-r--r-- | test/help/wat-desugar.txt | 1 | ||||
-rw-r--r-- | test/help/wat2wasm.txt | 3 |
25 files changed, 48 insertions, 21 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2de12a79..b47aa470 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,22 @@ include(CheckTypeSize) check_type_size(ssize_t SSIZE_T) check_type_size(size_t SIZEOF_SIZE_T) +FIND_PACKAGE(Git QUIET REQUIRED) +EXECUTE_PROCESS(COMMAND + "${GIT_EXECUTABLE}" --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git describe --tags + RESULT_VARIABLE + GIT_HASH_RESULT + OUTPUT_VARIABLE + GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +IF(${GIT_HASH_RESULT}) + MESSAGE(WARNING "Error running git describe to determine version") + SET(WABT_VERSION_INFO "(unable to determine version)") +ELSE() + SET(WABT_VERSION_INFO "${GIT_HASH}") +ENDIF() + configure_file( ${WABT_SOURCE_DIR}/src/config.h.in ${WABT_BINARY_DIR}/config.h diff --git a/src/config.h.in b/src/config.h.in index 136454db..99f1741e 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -20,6 +20,8 @@ #include <stdint.h> #include <stdlib.h> +#cmakedefine WABT_VERSION_INFO "${WABT_VERSION_INFO}" + /* TODO(binji): nice way to define these with WABT_ prefix? */ /* Whether <alloca.h> is available */ diff --git a/src/option-parser.cc b/src/option-parser.cc index 71c2e203..263ef176 100644 --- a/src/option-parser.cc +++ b/src/option-parser.cc @@ -50,6 +50,10 @@ OptionParser::OptionParser(const char* program_name, const char* description) : program_name_(program_name), description_(description), on_error_([this](const std::string& message) { DefaultError(message); }) { + + // Add common options + AddHelpOption(); + AddVersionOption(); } void OptionParser::AddOption(const Option& option) { @@ -96,6 +100,13 @@ void OptionParser::AddHelpOption() { }); } +void OptionParser::AddVersionOption() { + AddOption("version", "Print version information", [this]() { + printf("%s\n", WABT_VERSION_INFO); + exit(0); + }); +} + void OptionParser::SetErrorCallback(const Callback& callback) { on_error_ = callback; } diff --git a/src/option-parser.h b/src/option-parser.h index 945434a9..98b82727 100644 --- a/src/option-parser.h +++ b/src/option-parser.h @@ -78,9 +78,10 @@ class OptionParser { const char* metavar, const char* help, const Callback&); - void AddHelpOption(); private: + void AddHelpOption(); + void AddVersionOption(); static int Match(const char* s, const std::string& full, bool has_argument); void WABT_PRINTF_FORMAT(2, 3) Errorf(const char* format, ...); void HandleArgument(size_t* arg_index, const char* arg_value); diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc index de770d24..e59895d7 100644 --- a/src/tools/spectest-interp.cc +++ b/src/tools/spectest-interp.cc @@ -70,7 +70,6 @@ static void ParseOptions(int argc, char** argv) { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); - parser.AddHelpOption(); s_features.AddOptions(&parser); parser.AddOption('V', "value-stack-size", "SIZE", "Size in elements of the value stack", diff --git a/src/tools/wasm-decompile.cc b/src/tools/wasm-decompile.cc index a50d8801..d351b7bf 100644 --- a/src/tools/wasm-decompile.cc +++ b/src/tools/wasm-decompile.cc @@ -52,7 +52,6 @@ int ProgramMain(int argc, char** argv) { " # parse binary file test.wasm and write text file test.dcmp\n" " $ wasm-decompile test.wasm -o test.dcmp\n"; OptionParser parser("wasm-decompile", s_description); - parser.AddHelpOption(); parser.AddOption( 'o', "output", "FILENAME", "Output file for the decompiled file, by default use stdout", diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index c08a4382..d9c0aa29 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -83,7 +83,6 @@ static void ParseOptions(int argc, char** argv) { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); - parser.AddHelpOption(); s_features.AddOptions(&parser); parser.AddOption('V', "value-stack-size", "SIZE", "Size in elements of the value stack", diff --git a/src/tools/wasm-objdump.cc b/src/tools/wasm-objdump.cc index 28a059d7..f7ef1ddd 100644 --- a/src/tools/wasm-objdump.cc +++ b/src/tools/wasm-objdump.cc @@ -60,7 +60,6 @@ static void ParseOptions(int argc, char** argv) { []() { s_objdump_options.details = true; }); parser.AddOption('r', "reloc", "Show relocations inline with disassembly", []() { s_objdump_options.relocs = true; }); - parser.AddHelpOption(); parser.AddArgument( "filename", OptionParser::ArgumentCount::OneOrMore, [](const char* argument) { s_infiles.push_back(argument); }); diff --git a/src/tools/wasm-opcodecnt.cc b/src/tools/wasm-opcodecnt.cc index 6915dc82..eb49dce4 100644 --- a/src/tools/wasm-opcodecnt.cc +++ b/src/tools/wasm-opcodecnt.cc @@ -60,7 +60,6 @@ static void ParseOptions(int argc, char** argv) { s_log_stream = FileStream::CreateStdout(); s_read_binary_options.log_stream = s_log_stream.get(); }); - parser.AddHelpOption(); s_features.AddOptions(&parser); parser.AddOption('o', "output", "FILENAME", "Output file for the opcode counts, by default use stdout", diff --git a/src/tools/wasm-strip.cc b/src/tools/wasm-strip.cc index 607ea0da..f8386720 100644 --- a/src/tools/wasm-strip.cc +++ b/src/tools/wasm-strip.cc @@ -37,7 +37,6 @@ examples: static void ParseOptions(int argc, char** argv) { OptionParser parser("wasm-strip", s_description); - parser.AddHelpOption(); parser.AddArgument("filename", OptionParser::ArgumentCount::One, [](const char* argument) { s_filename = argument; diff --git a/src/tools/wasm-validate.cc b/src/tools/wasm-validate.cc index 5ec6be1d..3d671b2f 100644 --- a/src/tools/wasm-validate.cc +++ b/src/tools/wasm-validate.cc @@ -52,7 +52,6 @@ static void ParseOptions(int argc, char** argv) { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); - parser.AddHelpOption(); s_features.AddOptions(&parser); parser.AddOption("no-debug-names", "Ignore debug names in the binary file", []() { s_read_debug_names = false; }); diff --git a/src/tools/wasm2c.cc b/src/tools/wasm2c.cc index c7ce2113..d35d5789 100644 --- a/src/tools/wasm2c.cc +++ b/src/tools/wasm2c.cc @@ -62,7 +62,6 @@ static void ParseOptions(int argc, char** argv) { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); - parser.AddHelpOption(); parser.AddOption( 'o', "output", "FILENAME", "Output file for the generated C source file, by default use stdout", diff --git a/src/tools/wasm2wat.cc b/src/tools/wasm2wat.cc index 53c7001c..8167c168 100644 --- a/src/tools/wasm2wat.cc +++ b/src/tools/wasm2wat.cc @@ -64,7 +64,6 @@ static void ParseOptions(int argc, char** argv) { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); - parser.AddHelpOption(); parser.AddOption( 'o', "output", "FILENAME", "Output file for the generated wast file, by default use stdout", diff --git a/src/tools/wast2json.cc b/src/tools/wast2json.cc index 42d8859f..33c4895c 100644 --- a/src/tools/wast2json.cc +++ b/src/tools/wast2json.cc @@ -65,7 +65,6 @@ static void ParseOptions(int argc, char* argv[]) { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); - parser.AddHelpOption(); parser.AddOption("debug-parser", "Turn on debugging the parser of wast files", []() { s_debug_parsing = true; }); s_features.AddOptions(&parser); diff --git a/src/tools/wat-desugar.cc b/src/tools/wat-desugar.cc index 0760100d..cc6a2cba 100644 --- a/src/tools/wat-desugar.cc +++ b/src/tools/wat-desugar.cc @@ -59,7 +59,6 @@ examples: static void ParseOptions(int argc, char** argv) { OptionParser parser("wat-desugar", s_description); - parser.AddHelpOption(); parser.AddOption('o', "output", "FILE", "Output file for the formatted file", [](const char* argument) { s_outfile = argument; }); parser.AddOption("debug-parser", "Turn on debugging the parser of wat files", diff --git a/src/tools/wat2wasm.cc b/src/tools/wat2wasm.cc index 04dc155d..e1bb192a 100644 --- a/src/tools/wat2wasm.cc +++ b/src/tools/wat2wasm.cc @@ -71,7 +71,6 @@ static void ParseOptions(int argc, char* argv[]) { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); - parser.AddHelpOption(); parser.AddOption("debug-parser", "Turn on debugging the parser of wat files", []() { s_debug_parsing = true; }); parser.AddOption('d', "dump-module", diff --git a/test/help/spectest-interp.txt b/test/help/spectest-interp.txt index 46a9e0d3..5aeeb7e6 100644 --- a/test/help/spectest-interp.txt +++ b/test/help/spectest-interp.txt @@ -10,8 +10,9 @@ examples: $ spectest-interp test.json options: - -v, --verbose Use multiple times for more info --help Print this help message + --version Print version information + -v, --verbose Use multiple times for more info --enable-exceptions Enable Experimental exception handling --disable-mutable-globals Disable Import/export mutable globals --enable-saturating-float-to-int Enable Saturating float-to-int operators diff --git a/test/help/wasm-interp.txt b/test/help/wasm-interp.txt index 3872682b..eb530ae3 100644 --- a/test/help/wasm-interp.txt +++ b/test/help/wasm-interp.txt @@ -21,8 +21,9 @@ examples: $ wasm-interp test.wasm -V 100 --run-all-exports options: - -v, --verbose Use multiple times for more info --help Print this help message + --version Print version information + -v, --verbose Use multiple times for more info --enable-exceptions Enable Experimental exception handling --disable-mutable-globals Disable Import/export mutable globals --enable-saturating-float-to-int Enable Saturating float-to-int operators diff --git a/test/help/wasm-objdump.txt b/test/help/wasm-objdump.txt index ec3e2e59..17933879 100644 --- a/test/help/wasm-objdump.txt +++ b/test/help/wasm-objdump.txt @@ -9,6 +9,8 @@ examples: $ wasm-objdump test.wasm options: + --help Print this help message + --version Print version information -h, --headers Print headers -j, --section=SECTION Select just one section -s, --full-contents Print raw section contents @@ -16,5 +18,4 @@ options: --debug Print extra debug information -x, --details Show section details -r, --reloc Show relocations inline with disassembly - --help Print this help message ;;; STDOUT ;;) diff --git a/test/help/wasm-opcodecnt.txt b/test/help/wasm-opcodecnt.txt index eab38eec..f3802fa2 100644 --- a/test/help/wasm-opcodecnt.txt +++ b/test/help/wasm-opcodecnt.txt @@ -11,8 +11,9 @@ examples: $ wasm-opcodecnt test.wasm -o test.dist options: - -v, --verbose Use multiple times for more info --help Print this help message + --version Print version information + -v, --verbose Use multiple times for more info --enable-exceptions Enable Experimental exception handling --disable-mutable-globals Disable Import/export mutable globals --enable-saturating-float-to-int Enable Saturating float-to-int operators diff --git a/test/help/wasm-validate.txt b/test/help/wasm-validate.txt index e21815bc..5791b014 100644 --- a/test/help/wasm-validate.txt +++ b/test/help/wasm-validate.txt @@ -10,8 +10,9 @@ examples: $ wasm-validate test.wasm options: - -v, --verbose Use multiple times for more info --help Print this help message + --version Print version information + -v, --verbose Use multiple times for more info --enable-exceptions Enable Experimental exception handling --disable-mutable-globals Disable Import/export mutable globals --enable-saturating-float-to-int Enable Saturating float-to-int operators diff --git a/test/help/wasm2wat.txt b/test/help/wasm2wat.txt index 228ed995..9468167a 100644 --- a/test/help/wasm2wat.txt +++ b/test/help/wasm2wat.txt @@ -14,8 +14,9 @@ examples: $ wasm2wat test.wasm --no-debug-names -o test.wat options: - -v, --verbose Use multiple times for more info --help Print this help message + --version Print version information + -v, --verbose Use multiple times for more info -o, --output=FILENAME Output file for the generated wast file, by default use stdout -f, --fold-exprs Write folded expressions where possible --enable-exceptions Enable Experimental exception handling diff --git a/test/help/wast2json.txt b/test/help/wast2json.txt index a08b8a60..b3902ea8 100644 --- a/test/help/wast2json.txt +++ b/test/help/wast2json.txt @@ -12,8 +12,9 @@ examples: $ wast2json spec-test.wast -o spec-test.json options: - -v, --verbose Use multiple times for more info --help Print this help message + --version Print version information + -v, --verbose Use multiple times for more info --debug-parser Turn on debugging the parser of wast files --enable-exceptions Enable Experimental exception handling --disable-mutable-globals Disable Import/export mutable globals diff --git a/test/help/wat-desugar.txt b/test/help/wat-desugar.txt index 09fd9165..2560efc8 100644 --- a/test/help/wat-desugar.txt +++ b/test/help/wat-desugar.txt @@ -17,6 +17,7 @@ examples: options: --help Print this help message + --version Print version information -o, --output=FILE Output file for the formatted file --debug-parser Turn on debugging the parser of wat files -f, --fold-exprs Write folded expressions where possible diff --git a/test/help/wat2wasm.txt b/test/help/wat2wasm.txt index fac4fd4d..5bae1ff1 100644 --- a/test/help/wat2wasm.txt +++ b/test/help/wat2wasm.txt @@ -18,8 +18,9 @@ examples: $ wat2wasm spec-test.wast -v options: - -v, --verbose Use multiple times for more info --help Print this help message + --version Print version information + -v, --verbose Use multiple times for more info --debug-parser Turn on debugging the parser of wat files -d, --dump-module Print a hexdump of the module to stdout --enable-exceptions Enable Experimental exception handling |