mirror of https://github.com/CGAL/cgal
new implementation
This commit is contained in:
parent
8e6670d8ea
commit
281c02690a
|
|
@ -2,179 +2,165 @@ import sys
|
|||
import re
|
||||
import os
|
||||
import collections
|
||||
import logging
|
||||
from itertools import islice
|
||||
|
||||
CONFIG_REGEX = re.compile(
|
||||
r"(.*Configuring (examples|demo|test)*( in )*(test/|examples/|demo/)*)((?!done)\w+)"
|
||||
r"(.*Configuring (examples|demo|test) *in *(test/|examples/|demo/))((?!done)\w+)"
|
||||
)
|
||||
DEMO_REGEX = re.compile(r".*in demo/")
|
||||
EXAMPLES_REGEX = re.compile(r'.*in examples/')
|
||||
SEPARATOR = "------------------------------------------------------------------"
|
||||
|
||||
|
||||
# open the Installation report
|
||||
# For each NAME, check if NAME is a directory. If not, create one, create a
|
||||
# text report, and write everything that is in the report until the next NAME
|
||||
# in it. Then, add 'NAME r' in the global report. This should allow to get all
|
||||
# the NOTICE and other info explaining why the configuration is skipped.
|
||||
|
||||
def find_third_separator(contents):
|
||||
separator_count = 0
|
||||
for j, line in enumerate(contents):
|
||||
if line.strip() == SEPARATOR:
|
||||
separator_count += 1
|
||||
if separator_count == 3:
|
||||
return j
|
||||
return len(contents) + 2
|
||||
"""Find the position of the third separator line in the contents.
|
||||
If there are less than 3 separators, then return the position where the third separator
|
||||
should be inserted.
|
||||
"""
|
||||
separator_positions = (
|
||||
i for i, line in enumerate(contents) if line.strip() == SEPARATOR
|
||||
)
|
||||
return next(islice(separator_positions, 2, None), len(contents) + 2)
|
||||
|
||||
def last(iterator):
|
||||
"""Return the last item of an iterator or None if empty."""
|
||||
return collections.deque(iterator, maxlen=1).pop()
|
||||
|
||||
def find_last_separator(contents):
|
||||
position, _ = last(filter(lambda x: x[1].strip() == SEPARATOR, enumerate(contents)))
|
||||
def find_last(contents, query_string):
|
||||
"""Find the number of the last line matching the query string."""
|
||||
position, _ = last(filter(lambda x: x[1].strip() == query_string, enumerate(contents)))
|
||||
return position
|
||||
|
||||
def process_report(input_report_file_name, report_file_name, global_report_file_name):
|
||||
name = ""
|
||||
is_writing = False
|
||||
is_ignored = False
|
||||
position = 0
|
||||
lines_to_write = []
|
||||
installation_cmake_logs = []
|
||||
|
||||
file_path = f"Installation/{report_file_name}"
|
||||
print(f"Debug: Opening file {file_path}")
|
||||
def read_file_lines(file_path):
|
||||
"""Read the lines of a file and return them as a list."""
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
contents = file.readlines()
|
||||
position = find_last_separator(contents)
|
||||
print(f"Debug: Position is {position}")
|
||||
print(f"Debug: Length of contents is {len(contents)}")
|
||||
for i, line in enumerate(contents):
|
||||
if i > position:
|
||||
if line.strip() == "== Generating build files for tests ==":
|
||||
print(f"Debug: Found the line {line} at position {i}")
|
||||
break
|
||||
installation_cmake_logs.append(line)
|
||||
contents = []
|
||||
print(f"Debug: Length of installation CMake logs is {len(installation_cmake_logs)}")
|
||||
print(f"Debug: Installation CMake logs are {"".join(installation_cmake_logs)}")
|
||||
global_report = open(global_report_file_name, "a+", encoding="utf-8")
|
||||
with open(input_report_file_name, "rt", encoding="utf-8") as input_report_file:
|
||||
for line in input_report_file:
|
||||
match = CONFIG_REGEX.match(line)
|
||||
if is_writing:
|
||||
if match:
|
||||
is_writing = False
|
||||
if is_ignored:
|
||||
return file.readlines()
|
||||
except IOError as e:
|
||||
print(f"Error opening file {file_path}: {e}")
|
||||
return []
|
||||
|
||||
def write_file_lines(file_path, contents):
|
||||
"""Write the contents to a file. The contents should be a list of strings."""
|
||||
try:
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write("".join(contents))
|
||||
except IOError as e:
|
||||
print(f"Error writing to file {file_path}: {e}")
|
||||
|
||||
def mark_package_as_missing_requirements(global_report_file_name, name):
|
||||
"""Mark a package as missing requirements in the global report file."""
|
||||
try:
|
||||
with open(global_report_file_name, "a+", encoding="utf-8") as global_report:
|
||||
print(f"{name} r", file=global_report)
|
||||
is_ignored = False
|
||||
if lines_to_write:
|
||||
file_path = f"{name}/{report_file_name}"
|
||||
if os.path.exists(file_path):
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
contents = file.readlines()
|
||||
else:
|
||||
contents = []
|
||||
except IOError as e:
|
||||
print(f"Error opening global report file {global_report_file_name}: {e}")
|
||||
|
||||
def handle_end_of_package(package_name, report_file_name, lines_to_write):
|
||||
if not lines_to_write:
|
||||
return
|
||||
|
||||
file_path = f"{package_name}/{report_file_name}"
|
||||
contents = read_file_lines(file_path)
|
||||
position = find_third_separator(contents)
|
||||
|
||||
if not any(
|
||||
re.search("- CMake Results .*", content)
|
||||
for content in contents
|
||||
):
|
||||
lines_to_write.insert(
|
||||
0,
|
||||
f"{SEPARATOR}\n- CMake Results for {name}\n{SEPARATOR}\n\n",
|
||||
)
|
||||
if not any(re.search("- CMake Results .*", content) for content in contents):
|
||||
lines_to_write.insert(0, f"""{SEPARATOR}
|
||||
- CMake Results for {package_name}
|
||||
{SEPARATOR}
|
||||
|
||||
""")
|
||||
lines_to_write.insert(0, "\n")
|
||||
contents[position:position] = lines_to_write
|
||||
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write("".join(contents))
|
||||
write_file_lines(file_path, contents)
|
||||
|
||||
lines_to_write = []
|
||||
if is_ignored:
|
||||
is_ignored = False
|
||||
else:
|
||||
if line.strip() != "":
|
||||
lines_to_write.append(line)
|
||||
if not is_writing:
|
||||
if match:
|
||||
name = match.group(0).replace(match.group(1), "")
|
||||
print(f"Debug: Found name {name}")
|
||||
if DEMO_REGEX.match(line):
|
||||
name = f"{name}_Demo"
|
||||
elif EXAMPLES_REGEX.match(line):
|
||||
name = f"{name}_Examples"
|
||||
elif name == "libCGAL":
|
||||
name = "libCGAL_shared"
|
||||
elif name == "libCGAL_Core":
|
||||
name = "libCGALCore_shared"
|
||||
elif name == "libCGAL_ImageIO":
|
||||
name = "libCGALimageIO_shared"
|
||||
elif name == "libCGAL_Qt6":
|
||||
name = "libCGALQt6_shared"
|
||||
if name == "incomplete":
|
||||
is_writing = False
|
||||
is_ignored = False
|
||||
continue
|
||||
else:
|
||||
|
||||
SCM_BRANCH_FILE_CONTENT = read_file_lines(f"{os.getcwd()}/../../../../../.scm-branch")
|
||||
|
||||
def handle_new_package__is_ignored(name, report_file_name, cmake_logs):
|
||||
if not os.path.isdir(name):
|
||||
is_ignored = True
|
||||
os.mkdir(name)
|
||||
with open(
|
||||
f"{os.getcwd()}/../../../../../.scm-branch",
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
) as scm_branch_file:
|
||||
scm_branch_content = scm_branch_file.read()
|
||||
|
||||
with open(
|
||||
f"{name}/{report_file_name}", "w+", encoding="utf-8"
|
||||
) as report_file_handle:
|
||||
report_file_handle.write(scm_branch_content)
|
||||
write_file_lines(f"{name}/{report_file_name}", SCM_BRANCH_FILE_CONTENT)
|
||||
return True
|
||||
else:
|
||||
is_ignored = False
|
||||
file_path = f"{name}/{report_file_name}"
|
||||
if os.path.exists(file_path):
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
contents = file.readlines()
|
||||
else:
|
||||
contents = []
|
||||
|
||||
contents = read_file_lines(file_path)
|
||||
position = find_third_separator(contents)
|
||||
|
||||
if not any(
|
||||
re.search("- CMake Logs .*", content)
|
||||
for content in contents
|
||||
):
|
||||
if not any(re.search("- CMake Logs .*", content) for content in contents):
|
||||
contents.insert(
|
||||
position - 1,
|
||||
SEPARATOR
|
||||
+ "\n- CMake Logs from Installation \n"
|
||||
+ SEPARATOR
|
||||
+ "\n\n",
|
||||
SEPARATOR + "\n- CMake Logs from Installation \n" + SEPARATOR + "\n\n",
|
||||
)
|
||||
for log in installation_cmake_logs:
|
||||
for log in cmake_logs:
|
||||
contents.insert(position, log)
|
||||
position += 1
|
||||
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write("".join(contents))
|
||||
write_file_lines(file_path, contents)
|
||||
return False
|
||||
|
||||
is_writing = True
|
||||
def retrieve_cmake_logs(file_path):
|
||||
logging.debug("Opening file %s", file_path)
|
||||
contents = read_file_lines(file_path)
|
||||
|
||||
if is_writing:
|
||||
is_writing = False
|
||||
if is_ignored:
|
||||
print(f"{name} r", file=global_report)
|
||||
is_ignored = False
|
||||
global_report.close()
|
||||
position_begin = find_last(contents, SEPARATOR)
|
||||
position_end = 1 + find_last(contents, "== Generating build files for tests ==")
|
||||
|
||||
cmake_logs = contents[position_begin:position_end]
|
||||
|
||||
logging.debug("CMake log beginning is at line %d", position_begin)
|
||||
logging.debug("CMake log end is at line %d", position_end)
|
||||
logging.debug("Length of contents is %d", len(contents))
|
||||
logging.debug("Length of installation CMake logs is %d", len(cmake_logs))
|
||||
logging.debug("Installation CMake logs are %s", "".join(cmake_logs))
|
||||
return cmake_logs
|
||||
|
||||
def main():
|
||||
input_report_file_name = sys.argv[1]
|
||||
report_file_name = sys.argv[2]
|
||||
global_report_file_name = sys.argv[3]
|
||||
process_report(input_report_file_name, report_file_name, global_report_file_name)
|
||||
|
||||
cmake_logs = retrieve_cmake_logs(f"Installation/{report_file_name}")
|
||||
|
||||
package_name = ""
|
||||
lines_to_write = []
|
||||
|
||||
for line in read_file_lines(input_report_file_name):
|
||||
|
||||
line_matches_new_package = CONFIG_REGEX.match(line)
|
||||
if line_matches_new_package:
|
||||
logging.debug("Found new package %s", line_matches_new_package.group(0))
|
||||
logging.debug(" group 1 %s", line_matches_new_package.group(1))
|
||||
new_package_name = line_matches_new_package.group(0).replace(
|
||||
line_matches_new_package.group(1), ""
|
||||
)
|
||||
|
||||
if package_name and not line_matches_new_package and line.strip() != "":
|
||||
lines_to_write.append(line)
|
||||
|
||||
if package_name and line_matches_new_package:
|
||||
handle_end_of_package(
|
||||
package_name,
|
||||
report_file_name,
|
||||
lines_to_write,
|
||||
)
|
||||
lines_to_write = []
|
||||
if not package_name:
|
||||
if line_matches_new_package:
|
||||
package_name = new_package_name
|
||||
if DEMO_REGEX.match(line):
|
||||
package_name = f"{package_name}_Demo"
|
||||
elif EXAMPLES_REGEX.match(line):
|
||||
package_name = f"{package_name}_Examples"
|
||||
|
||||
if package_name == "incomplete":
|
||||
package_name = ""
|
||||
continue
|
||||
else:
|
||||
is_ignored = handle_new_package__is_ignored(package_name, report_file_name, cmake_logs)
|
||||
if is_ignored:
|
||||
mark_package_as_missing_requirements(global_report_file_name, package_name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue