Skip to content

Commit

Permalink
Force CTest testsuite regeneration on generator change [skip appveyor]
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Nov 22, 2024
1 parent 05e4341 commit 76a43e5
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions test/convert_at_to_ctest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import glob
import hashlib
import json
import os
import re
import sys
Expand Down Expand Up @@ -159,16 +161,38 @@ def convert_autotest_to_ctest(autotest_file, cmake_output_file):
cmakef.write('endif()\n')


def generate_ctest_files(file_list, output_dir):
def get_file_hash(file_path, algorithm):
hash_obj = hashlib.new(algorithm)
with open(file_path, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_obj.update(chunk)
return hash_obj.hexdigest()


def generate_ctest_files(file_list, output_dir, force):
os.makedirs(output_dir, exist_ok=True)

for autotest_file in file_list:
base_name = os.path.splitext(os.path.basename(autotest_file))[0]
cmake_output_file = os.path.join(output_dir, f'{base_name}.cmake')
if os.path.isfile(cmake_output_file):
if not force and os.path.isfile(cmake_output_file):
continue
convert_autotest_to_ctest(autotest_file, cmake_output_file)


if __name__ == '__main__':
generate_ctest_files(file_list=glob.glob(os.path.join('tests', '*.at')), output_dir=sys.argv[1])
algorithm = 'sha256'
new_hash = get_file_hash(__file__, algorithm)
output_dir = sys.argv[1]
hash_json_file = os.path.join(output_dir, 'generator.json')
try:
with open(hash_json_file, 'r') as json_file:
old_hash = json.load(json_file).get(algorithm, '');
except OSError:
old_hash = ''
force = new_hash != old_hash

generate_ctest_files(glob.glob(os.path.join('tests', '*.at')), output_dir, force)

with open(hash_json_file, 'w') as json_file:
json.dump({algorithm: new_hash}, json_file)

0 comments on commit 76a43e5

Please sign in to comment.