-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,25 +1,39 @@ | ||
import re | ||
import sys | ||
|
||
def extract_version_and_sha(config_file_path, package_name): | ||
|
||
def extract_version(config_file_path, package_name): | ||
with open(config_file_path, 'r') as file: | ||
content = file.read() | ||
|
||
version_pattern = re.compile(r'hunter_config\(\s*' + re.escape(package_name) + r'\s*.*?URL\s+.*?/tags/([^\s/]+)\.zip', re.DOTALL) | ||
sha_pattern = re.compile(r'hunter_config\(\s*' + re.escape(package_name) + r'\s*.*?SHA1\s+(\w+)', re.DOTALL) | ||
|
||
version_pattern = re.compile(r'hunter_config\(\s*' + re.escape(package_name) + r'\s*.*?URL\s+.*?/heads/.*?/([^\s/]+)\.zip', re.DOTALL) | ||
version_match = version_pattern.search(content) | ||
sha_match = sha_pattern.search(content) | ||
|
||
version = version_match.group(1) if version_match else None | ||
return version | ||
|
||
|
||
def extract_sha(cmakelists_file_path): | ||
with open(cmakelists_file_path, 'r') as file: | ||
content = file.read() | ||
|
||
sha_pattern = re.compile(r'set\s*\(\s*WASMEDGE_ID\s*([a-fA-F0-9]+)\s*\)') | ||
sha_match = sha_pattern.search(content) | ||
|
||
sha = sha_match.group(1)[:7] if sha_match else None | ||
return sha | ||
|
||
return version, sha | ||
|
||
if __name__ == "__main__": | ||
config_file_path = '../../../cmake/Hunter/config.cmake' | ||
cmakelists_file_path = '../../../CMakeLists.txt' | ||
package_name = 'WasmEdge' | ||
|
||
version, sha = extract_version_and_sha(config_file_path, package_name) | ||
print(f"{version}-{sha}") | ||
|
||
version = extract_version(config_file_path, package_name) | ||
|
||
sha = extract_sha(cmakelists_file_path) | ||
|
||
if version and sha: | ||
print(f"{version}-{sha}") | ||
else: | ||
print("Failed to extract version and SHA") |