diff options
-rw-r--r-- | CMakeLists.txt | 19 | ||||
-rwxr-xr-x | check.py | 30 | ||||
-rw-r--r-- | config.h.in | 1 | ||||
-rw-r--r-- | src/support/command-line.cpp | 9 |
4 files changed, 52 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ae4238a97..696b48b7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,22 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Release") ENDIF() +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(BINARYEN_VERSION_INFO "(unable to determine version)") +ELSE() + SET(BINARYEN_VERSION_INFO "${GIT_HASH}") +ENDIF() +CONFIGURE_FILE(config.h.in config.h) + OPTION(BUILD_STATIC_LIB "Build as a static library" OFF) # Support functionality. @@ -52,6 +68,9 @@ ENDFUNCTION() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) +# Add output directory to include path so config.h can be found +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + # Force output to bin/ and lib/. This is to suppress CMake multigenerator output paths and avoid bin/Debug, bin/Release/ and so on, which is CMake default. FOREACH(SUFFIX "_DEBUG" "_RELEASE" "_RELWITHDEBINFO" "_MINSIZEREL" "") SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY${SUFFIX} "${PROJECT_BINARY_DIR}/bin") @@ -49,17 +49,33 @@ def run_help_tests(): print('[ checking --help is useful... ]\n') not_executable_suffix = ['.txt', '.js', '.ilk', '.pdb', '.dll', '.wasm'] - executables = sorted(filter(lambda x: not any(x.endswith(s) for s in - not_executable_suffix) and os.path.isfile(x), - os.listdir(options.binaryen_bin))) + bin_files = [os.path.join(options.binaryen_bin, f) for f in os.listdir(options.binaryen_bin)] + executables = [f for f in bin_files if os.path.isfile(f) and not any(f.endswith(s) for s in not_executable_suffix)] + executables = sorted(executables) + assert len(executables) + for e in executables: print('.. %s --help' % e) - out, err = subprocess.Popen([os.path.join(options.binaryen_bin, e), '--help'], + out, err = subprocess.Popen([e, '--help'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate() + out = out.decode('utf-8') + err = err.decode('utf-8') + assert len(err) == 0, 'Expected no stderr, got:\n%s' % err + assert os.path.basename(e).replace('.exe', '') in out, 'Expected help to contain program name, got:\n%s' % out + assert len(out.split('\n')) > 8, 'Expected some help, got:\n%s' % out + + print('[ checking --version ... ]\n') + for e in executables: + print('.. %s --version' % e) + out, err = subprocess.Popen([e, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - assert len(out) == 0, 'Expected no stdout, got:\n%s' % out - assert e.replace('.exe', '') in err, 'Expected help to contain program name, got:\n%s' % err - assert len(err.split('\n')) > 8, 'Expected some help, got:\n%s' % err + out = out.decode('utf-8') + err = err.decode('utf-8') + assert len(err) == 0, 'Expected no stderr, got:\n%s' % err + assert os.path.basename(e).replace('.exe', '') in out, 'Expected version to contain program name, got:\n%s' % out + assert len(out.strip().splitlines()) == 1, 'Expected only version info, got:\n%s' % out def run_wasm_opt_tests(): diff --git a/config.h.in b/config.h.in new file mode 100644 index 000000000..17f2018e2 --- /dev/null +++ b/config.h.in @@ -0,0 +1 @@ +#cmakedefine BINARYEN_VERSION_INFO "${BINARYEN_VERSION_INFO}" diff --git a/src/support/command-line.cpp b/src/support/command-line.cpp index f1b4fca4d..be5098677 100644 --- a/src/support/command-line.cpp +++ b/src/support/command-line.cpp @@ -15,6 +15,7 @@ */ #include "support/command-line.h" +#include "config.h" using namespace wasm; @@ -51,6 +52,14 @@ void printWrap(std::ostream& os, int leftPad, const std::string& content) { Options::Options(const std::string& command, const std::string& description) : debug(false), positional(Arguments::Zero) { + add("--version", + "", + "Output version information and exit", + Arguments::Zero, + [command](Options*, const std::string&) { + std::cout << command << " " << BINARYEN_VERSION_INFO << "\n"; + exit(0); + }); add("--help", "-h", "Show this help message and exit", |