-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Improve rebaseline_tests.py --update-emsdk to enable llvm and binaryen version bumps
#27352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+74
−10
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import argparse | ||
| import json | ||
| import os | ||
| import re | ||
| import statistics | ||
| import subprocess | ||
| import sys | ||
|
|
@@ -22,7 +23,7 @@ | |
| root_dir = os.path.dirname(os.path.dirname(script_dir)) | ||
|
|
||
| sys.path.insert(0, root_dir) | ||
| from tools import utils | ||
| from tools import building, shared, utils | ||
|
|
||
|
|
||
| def run(cmd, **args): | ||
|
|
@@ -43,9 +44,7 @@ def read_size_from_json(content): | |
|
|
||
|
|
||
| def get_installed_emsdk_sha(): | ||
| emsdk = os.environ.get('EMSDK') | ||
| if not emsdk: | ||
| return None | ||
| emsdk = os.environ.get('EMSDK', os.path.join(os.path.dirname(root_dir), 'emsdk')) | ||
| version_file = os.path.join(emsdk, 'upstream', '.emsdk_version') | ||
| if not os.path.exists(version_file): | ||
| return None | ||
|
|
@@ -107,20 +106,60 @@ def process_changed_file(filename): | |
| return f'{filename}: {old_size} => {size} [{delta:+} bytes / {percent_delta:+.2f}%]\n' | ||
|
|
||
|
|
||
| def patch_file(file_path, pattern, replacement): | ||
| """Patch a file using regular expressions.""" | ||
| content = utils.read_file(file_path) | ||
| new_content, count = re.subn(pattern, replacement, content, flags=re.MULTILINE) | ||
| if count != 1: | ||
| utils.exit_with_error(f'failed to patch {file_path} (pattern: `{pattern}`, got {count} matches, expected 1)') | ||
| utils.write_file(file_path, new_content) | ||
|
|
||
|
|
||
| def update_expected_llvm_version(): | ||
| clang_version_str = shared.get_clang_version() | ||
| if not clang_version_str: | ||
| utils.exit_with_error('--update-emsdk specified but could not detect clang version') | ||
| new_version = int(clang_version_str.split('.')[0]) | ||
| if new_version == shared.EXPECTED_LLVM_VERSION: | ||
| return None | ||
| print(f'update EXPECTED_LLVM_VERSION: {shared.EXPECTED_LLVM_VERSION} => {new_version}') | ||
| shared_py_file = os.path.join(root_dir, 'tools', 'shared.py') | ||
| patch_file(shared_py_file, r'^EXPECTED_LLVM_VERSION = \d+$', f'EXPECTED_LLVM_VERSION = {new_version}') | ||
| return f'Expected LLVM version updated: {shared.EXPECTED_LLVM_VERSION} => {new_version}' | ||
|
|
||
|
|
||
| def update_expected_binaryen_version(): | ||
| bindir = building.get_binaryen_bin() | ||
| binaryen_version_str = building.get_binaryen_version(bindir) | ||
| if not binaryen_version_str: | ||
| utils.exit_with_error('--update-emsdk specified but could not detect binaryen version') | ||
| try: | ||
| new_version = int(binaryen_version_str.splitlines()[0].split()[2]) | ||
| except (IndexError, ValueError): | ||
| utils.exit_with_error(f'error parsing binaryen version ({binaryen_version_str})') | ||
| if new_version == building.EXPECTED_BINARYEN_VERSION: | ||
| return None | ||
| print(f'update EXPECTED_BINARYEN_VERSION: {building.EXPECTED_BINARYEN_VERSION} => {new_version}') | ||
| building_py_file = os.path.join(root_dir, 'tools', 'building.py') | ||
| patch_file(building_py_file, r'^EXPECTED_BINARYEN_VERSION = \d+$', f'EXPECTED_BINARYEN_VERSION = {new_version}') | ||
| return f'Expected Binaryen version updated: {building.EXPECTED_BINARYEN_VERSION} => {new_version}' | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('-s', '--skip-tests', action='store_true', help="Don't actually run the tests, just analyze the existing results") | ||
| parser.add_argument('-b', '--new-branch', action='store_true', help='Create a new branch containing the updates') | ||
| parser.add_argument('-c', '--clear-cache', action='store_true', help='Clear the cache before rebaselining (useful when working with llvm changes)') | ||
| parser.add_argument('-n', '--check-only', dest='check_only', action='store_true', help='Return non-zero if test expectations are out of date, and skip creating a git commit') | ||
| parser.add_argument('--update-emsdk', action='store_true', help='Update test/emsdk_version.txt to match the currently installed emsdk version') | ||
| parser.add_argument('--update-emsdk', action='store_true', help='Update test/emsdk_version.txt and expected tool versions to match the currently installed emsdk version') | ||
| args = parser.parse_args() | ||
|
|
||
| if args.clear_cache: | ||
| run(['./emcc', '--clear-cache']) | ||
|
|
||
| current_sha = None | ||
| installed_sha = None | ||
| tool_updates = [] | ||
| if not args.skip_tests: | ||
| if not args.check_only and run(['git', 'status', '-uno', '--porcelain']).strip(): | ||
| print('tree is not clean') | ||
|
|
@@ -137,6 +176,10 @@ def main(): | |
| return 0 | ||
| print(f'update emsdk: {current_sha} => {installed_sha}') | ||
| utils.write_file(emsdk_version_file, installed_sha + '\n') | ||
| if update := update_expected_llvm_version(): | ||
| tool_updates.append(update) | ||
| if update := update_expected_binaryen_version(): | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First time using the walrus operator! |
||
| tool_updates.append(update) | ||
| elif installed_sha and installed_sha != current_sha: | ||
| utils.exit_with_error(f'installed emsdk version ({installed_sha}) does not match test/emsdk_version.txt ({current_sha}). Pass --update-emsdk to update it.') | ||
|
|
||
|
|
@@ -165,6 +208,8 @@ def main(): | |
| This is an automatic change generated by tools/maint/rebaseline_tests.py --update-emsdk. | ||
|
|
||
| ''' | ||
| if tool_updates: | ||
| message += '\n'.join(tool_updates) + '\n\n' | ||
| message += format_emsdk_version_update(current_sha, installed_sha) + '\n' | ||
| else: | ||
| message = '''Automatic rebaseline of codesize expectations. NFC | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment, this looks quite odd at first glance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. And the I added on for the existing usage withing this file for the LLVM version