diff --git a/scripts/version-patcher.py b/scripts/version-patcher.py index 1be65a59a..7088bb313 100644 --- a/scripts/version-patcher.py +++ b/scripts/version-patcher.py @@ -3,20 +3,25 @@ import subprocess import sys -def replace_version(filename, new_text): +def replace_version(filename, build_info): pattern = r'(Current : constant String := "[^+]+\+)([^"]*)(";)' - with open(filename, 'rb') as file: - content = file.read() # Depending on the context in which this is run, there may be mix-ups with # line terminators between the environment detected, github runner, etc... # So just keep them as they are and that should always work. - content = content.decode() - new_content = re.sub(pattern, r'\g<1>' + new_text + r'\3', content) + with open(filename, 'rb') as file: + content = file.read().decode() + + # The pattern captures the part between '+' and '";', replacing it with our + # new build information + + new_content = re.sub(pattern, r'\g<1>' + build_info + r'\3', content) + + # A few sanity checks and write if needed if new_content == content: - if new_text in content: + if build_info in content: print(f"Note: version in {filename} already up to date") else: print(f"WARNING: failed to update version in {filename}") @@ -32,11 +37,11 @@ def replace_version(filename, new_text): sys.exit(0) # If there is an argument to the script, retrieve it here and use it as the new -# dirty flag +# dirty flag after the commit if len(sys.argv) > 1: dirty = sys.argv[1] else: - # Detect the current directory contains changes + # Detect whether the current directory contains changes if subprocess.call(['git', 'diff-index', '--quiet', 'HEAD', '--']) != 0: dirty = "_dirty" else: @@ -45,6 +50,6 @@ def replace_version(filename, new_text): # Find the short git commit of the repository in the current directory commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip() -# Replace the build version part with the short commit hash +# Replace the build version part with the short commit hash plus any extra info print(f"Updating version in src/alire/alire-version.ads to commit {commit}{dirty}...") replace_version('src/alire/alire-version.ads', commit+dirty) diff --git a/src/alire/alire-version.ads b/src/alire/alire-version.ads index 3da1158a9..e2599bdfa 100644 --- a/src/alire/alire-version.ads +++ b/src/alire/alire-version.ads @@ -6,7 +6,7 @@ package Alire.Version with Preelaborate is -- be replaced by `alr build` with the current commit, and appended with -- "_or_later" after build. - Current : constant String := "2.0-beta2+92896bd3_or_later"; + Current : constant String := "2.0-beta2+99325800_or_later"; -- 2.0.0-b1: first public release on the 2.0 branch -- 1.2.1: build switches fix and other minor assorted fixes -- 1.2.0: rpm speed-up, silence propagation warning, early switch parse