-
Notifications
You must be signed in to change notification settings - Fork 2.1k
github: add scripts to store size of android release artifact #9705
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Copyright (C) 2026 The Android Open Source Project | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| #!/usr/bin/env python3 | ||
|
|
||
| import os | ||
| import sys | ||
| import zipfile | ||
| import tarfile | ||
| import json | ||
| import argparse | ||
|
|
||
| # Hardcoded list of library extensions to track | ||
| LIB_EXTENSIONS = ('.a', '.jar', '.so') | ||
|
|
||
| def get_archive_content(path): | ||
| """ | ||
| Extracts metadata for library files within a compressed archive. | ||
| Returns a list of dicts with 'name' and 'size' (uncompressed). | ||
| """ | ||
| content = [] | ||
|
|
||
| # .aar and .zip are both handled by zipfile | ||
| if path.endswith(('.zip', '.aar')): | ||
| with zipfile.ZipFile(path, 'r') as z: | ||
| for info in z.infolist(): | ||
| # info.is_dir() is available in Python 3.6+ | ||
| if not info.is_dir() and info.filename.endswith(LIB_EXTENSIONS): | ||
| content.append({ | ||
| "name": info.filename, | ||
| "size": info.file_size | ||
| }) | ||
|
|
||
| # .tgz or .tar.gz handled by tarfile | ||
| elif path.endswith(('.tgz', '.tar.gz')): | ||
| with tarfile.open(path, 'r:gz') as t: | ||
| for member in t.getmembers(): | ||
| if member.isfile() and member.name.endswith(LIB_EXTENSIONS): | ||
| content.append({ | ||
| "name": member.name, | ||
| "size": member.size | ||
| }) | ||
| else: | ||
| raise ValueError(f"Unsupported archive format: {path}") | ||
|
|
||
| return content | ||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Dump sizes of library files inside archives as JSON.") | ||
| parser.add_argument('archives', nargs='+', help='List of compressed archives (.aar, .tgz, .zip)') | ||
| args = parser.parse_args() | ||
|
|
||
| results = [] | ||
|
|
||
| for archive_path in args.archives: | ||
| if not os.path.exists(archive_path): | ||
| print(f"Error: File not found: {archive_path}", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| try: | ||
| archive_full_size = os.path.getsize(archive_path) | ||
| inner_content = get_archive_content(archive_path) | ||
|
|
||
| # Sort the content list alphabetically by name | ||
| inner_content.sort(key=lambda x: x['name']) | ||
|
|
||
| results.append({ | ||
| "name": os.path.basename(archive_path), | ||
| "size": archive_full_size, | ||
| "content": inner_content | ||
| }) | ||
| except Exception as e: | ||
| print(f"Error processing {archive_path}: {e}", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| # Sort the top-level results by archive name | ||
| results.sort(key=lambda x: x['name']) | ||
|
|
||
| # Output JSON to stdout | ||
| print(json.dumps(results, indent=2)) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium