Skip to content

Commit

Permalink
Verify --version output matches CHANGELOG (#2580)
Browse files Browse the repository at this point in the history
The new version string looks like this:

  wasm-opt version 90 (version_90-18-g77329439d)

The version reported here is the version from the CMakeLists.txt file
followed by the git version in brackets.  We verify that the main
version here matches the CHANGELOG to prevent people from changing
one without changeing the other.

This will help with emscripten that wants to be able to programaticaly
check the --version of binaryen tools.

See emscripten-core/emscripten#10175
  • Loading branch information
sbc100 committed Jan 10, 2020
1 parent cb10396 commit 4953bcc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
13 changes: 6 additions & 7 deletions CMakeLists.txt
Expand Up @@ -15,17 +15,16 @@ option(BYN_ENABLE_ASSERTIONS "Enable assertions" ON)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
find_package(Git QUIET REQUIRED)
execute_process(COMMAND
"${GIT_EXECUTABLE}" --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git describe --tags
"${GIT_EXECUTABLE}" --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git describe --tags --match version_*
RESULT_VARIABLE
GIT_HASH_RESULT
GIT_VERSION_RESULT
OUTPUT_VARIABLE
GIT_HASH
GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${GIT_HASH_RESULT})
message(WARNING "Error running git describe to determine version")
set(CMAKE_PROJECT_VERSION "(unable to determine version)")
if(${GIT_VERSION_RESULT})
message(FATAL_ERROR "Error running git describe to determine version")
else()
set(CMAKE_PROJECT_VERSION "${GIT_HASH}")
set(CMAKE_PROJECT_VERSION "${CMAKE_PROJECT_VERSION} (${GIT_VERSION})")
endif()
endif()

Expand Down
15 changes: 15 additions & 0 deletions check.py
Expand Up @@ -35,6 +35,16 @@
assert os.path.exists(shared.options.interpreter), 'interpreter not found'


def get_changelog_version():
with open(os.path.join(shared.options.binaryen_root, 'CHANGELOG.md')) as f:
lines = f.readlines()
lines = [l for l in lines if len(l.split()) == 1]
lines = [l for l in lines if l.startswith('v')]
version = lines[0][1:]
print("Parsed CHANGELOG.md version: %s" % version)
return int(version)


def run_help_tests():
print('[ checking --help is useful... ]\n')

Expand All @@ -56,6 +66,7 @@ def run_help_tests():
assert len(out.split('\n')) > 8, 'Expected some help, got:\n%s' % out

print('[ checking --version ... ]\n')
changelog_version = get_changelog_version()
for e in executables:
print('.. %s --version' % e)
out, err = subprocess.Popen([e, '--version'],
Expand All @@ -66,6 +77,10 @@ def run_help_tests():
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
parts = out.split()
assert parts[1] == 'version'
version = int(parts[2])
assert version == changelog_version


def run_wasm_opt_tests():
Expand Down
2 changes: 1 addition & 1 deletion src/support/command-line.cpp
Expand Up @@ -58,7 +58,7 @@ Options::Options(const std::string& command, const std::string& description)
"Output version information and exit",
Arguments::Zero,
[command](Options*, const std::string&) {
std::cout << command << " " << CMAKE_PROJECT_VERSION << "\n";
std::cout << command << " version " << CMAKE_PROJECT_VERSION << "\n";
exit(0);
});
add("--help",
Expand Down

0 comments on commit 4953bcc

Please sign in to comment.