diff --git a/tools/SiteSpawner/src/sitespawner/__init__.py b/tools/SiteSpawner/src/sitespawner/__init__.py index d198008ff6f..4c35d47b35c 100644 --- a/tools/SiteSpawner/src/sitespawner/__init__.py +++ b/tools/SiteSpawner/src/sitespawner/__init__.py @@ -56,7 +56,12 @@ def reports_handler(args): def webpage_handler(args): update_webpage( - args.loc_github_ref_name, args.loc_github_event_name, args.pr_number, args.page_url + args.loc_github_ref_name, + args.loc_github_event_name, + args.pr_number, + args.doc_project_name, + args.include_documentation, + args.page_url, ) @@ -203,6 +208,15 @@ def setup_parser(): ), }, } + src_project_name = { + "name": "--src-project-name", + "options": { + "metavar": "src_project_name", + "type": str, + "default": "Project", + "help": ("Name of the project that is displayed in the webpage for sources."), + }, + } reports_args = [ logo_src, logo_href, @@ -211,6 +225,7 @@ def setup_parser(): src_path, info_report_dir, src_remove_pattern, + src_project_name, ] create_subparser( subparsers=subparsers, @@ -256,7 +271,31 @@ def setup_parser(): "help": "Base URL of the website. Otherwise, will apply relative reference for redirect.", }, } - webpage_args = [ref_name, event_name, pr_number, page_url] + doc_project_name = { + "name": "--doc-project-name", + "options": { + "metavar": "doc_project_name", + "type": str, + "default": "Project", + "help": ("Name of the project used in documentation."), + }, + } + include_documentation = { + "name": "--include-documentation", + "options": { + "action": "store_true", + "dest": "include_documentation", + "help": "Whethet to include documentation in the built webpage", + }, + } + webpage_args = [ + ref_name, + event_name, + pr_number, + page_url, + doc_project_name, + include_documentation, + ] create_subparser( subparsers=subparsers, name="webpage", diff --git a/tools/SiteSpawner/src/sitespawner/gen_coverage_report.py b/tools/SiteSpawner/src/sitespawner/gen_coverage_report.py index 4f39537e8e3..5fb088a8924 100644 --- a/tools/SiteSpawner/src/sitespawner/gen_coverage_report.py +++ b/tools/SiteSpawner/src/sitespawner/gen_coverage_report.py @@ -50,7 +50,7 @@ def lcov_genhtml( stdout=obtain_stdout(log_output_path), ) else: - command += ["--prefix", str(path_prefix)] + command += ["--prefix", str(Path(path_prefix).resolve())] subprocess.run( command, stdout=obtain_stdout(log_output_path), @@ -66,6 +66,7 @@ def generate_coverage_reports( logo_src=None, logo_href=None, info_report_dir=None, + project_name="Project", info_pattern="coverage*.info", ): """Iterates over available *.info files, merges them & generates summaries @@ -87,7 +88,7 @@ def generate_coverage_reports( logger.debug(f"Preprocessing {info_file}") lcov_extract_command = ["lcov", "--extract", info_file, src_pattern, "-o", info_file] - data, _ = parse_infos([str(info_file)]) + data = parse_infos([str(info_file)]) if len(data.keys()) == 0: logger.warning(f"No data found in .info file: {info_file}") continue @@ -166,6 +167,8 @@ def generate_coverage_reports( genhtml( input_files=input_files, output_dir=test_output_dir, + src_path=src_path, + project_name=project_name, test_name=test_name, logo_src=logo_src, logo_href=logo_href, @@ -204,6 +207,8 @@ def generate_coverage_reports( genhtml( input_files=merged_input_files, output_dir=final_output_dir, + src_path=src_path, + project_name=project_name, test_name="all", logo_src=logo_src, logo_href=logo_href, @@ -232,4 +237,5 @@ def main(args): logo_src=args.logo_src, logo_href=args.logo_href, info_report_dir=args.info_report_dir, + project_name=args.src_project_name, ) diff --git a/tools/SiteSpawner/src/sitespawner/generate.py b/tools/SiteSpawner/src/sitespawner/generate.py index 438f59ccef6..d7e927d4f4a 100755 --- a/tools/SiteSpawner/src/sitespawner/generate.py +++ b/tools/SiteSpawner/src/sitespawner/generate.py @@ -18,7 +18,7 @@ def render_template(src, dst, **kwargs): @args_on_debug_logger(logger) -def make_coverage_report_index(branch, root, output, templates): +def make_coverage_report_index(branch, root, output, templates, include_documentation): """Prepares coverage report index page.""" # Coverage types individual dashboards accumulate # Coverage dashboard displays coverage types side-by-side @@ -69,20 +69,22 @@ def make_coverage_report_index(branch, root, output, templates): @args_on_debug_logger(logger) -def make_dev_index(branches, output, templates): +def make_dev_index(branches, output, templates, include_documentation): """Prepares the branch/pr index page.""" - params = {"branches": branches} + params = {"branches": branches, "include_documentation": include_documentation} render_template(templates / "dev.md", output / "dev.md", **params) -def generate(template, root, output): +def generate(template, root, output, include_documentation): """Processes webpage *.md templates.""" template = Path(template) root = Path(root) output = Path(output) # Reports for the main branch - make_coverage_report_index("main", root / "main", output / "main", template) + make_coverage_report_index( + "main", root / "main", output / "main", template, include_documentation + ) # Reports for development branches / pull requests branches = [] @@ -97,13 +99,16 @@ def generate(template, root, output): fname = filepath.name branches.append(fname) make_coverage_report_index( - fname, root / "dev" / fname, output / "dev" / fname, template + fname, root / "dev" / fname, output / "dev" / fname, template, include_documentation ) # Prepare the branch/pr index page - make_dev_index(branches, output, template) + make_dev_index(branches, output, template, include_documentation) + render_template( + template / "main.md", output / "main.md", **{"include_documentation": include_documentation} + ) # Copy other files/pages - files = ["conf.py", "main.md", "index.md"] + files = ["conf.py", "index.md"] for file in files: copy(template / file, output / file) diff --git a/tools/SiteSpawner/src/sitespawner/genhtml.py b/tools/SiteSpawner/src/sitespawner/genhtml.py index 4be90dd7732..97f841bfa59 100644 --- a/tools/SiteSpawner/src/sitespawner/genhtml.py +++ b/tools/SiteSpawner/src/sitespawner/genhtml.py @@ -46,7 +46,6 @@ def parse_infos(input_files: List[str]): raise FileNotFoundError(f"Input file '{file}' does not exist.") data = defaultdict(defaultdict) - code_root_path = None for i in input_files: lines_found_sum = 0 @@ -73,7 +72,7 @@ def parse_infos(input_files: List[str]): lines_hit = None data["Total:"][module_name] = [lines_hit_sum, lines_found_sum] - return data, code_root_path + return data # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -136,6 +135,7 @@ def render_page( logo_src, logo_href, template_env, + project_name, links=True, ): """Combines the final report page.""" @@ -143,6 +143,7 @@ def render_page( output = report_html.render( header_token="Full", + project_name=project_name, logo_src=logo_src, logo_href=logo_href, fulltable_token=generate_table(data, template_env, links), @@ -171,21 +172,17 @@ def sub_src_view( html_src_dir, logo_src, logo_href, + project_name, template_env, ): """Generate page for the source file based on the view generated by lcov's genhtml.""" file = Path(file).resolve() - html_name = f"{file.name}.gcov.html" - if file.is_absolute(): - cmn_path = commonpath([file, src_prefix]) - inner_path = file.relative_to(cmn_path).parent - else: - inner_path = file.parent + inner_path = file.relative_to(src_prefix).parent + html_name = f"{file.name}.gcov.html" main_table = None - - src_html_path = Path(html_src_dir) / Path(inner_path) / html_name + src_html_path = Path(html_src_dir) / inner_path / html_name if not src_html_path.exists(): logger.warning(f"Not found: {src_html_path}") @@ -202,6 +199,7 @@ def sub_src_view( output = report_html.render( header_token="Full", + project_name=project_name, logo_src=logo_src, logo_href=logo_href, root_name=root_name, @@ -278,17 +276,26 @@ def unify_dict(data): @main_func_log(logger, "Generate HTML Coverage Report") @args_on_debug_logger(logger) -def genhtml(input_files, output_dir, test_name, html_src_dir, logo_src=None, logo_href=None): +def genhtml( + input_files, + src_path, + output_dir, + test_name, + html_src_dir, + project_name="Project", + logo_src=None, + logo_href=None, +): """Generates coverage dashboard from *.info files.""" if not Path(output_dir).is_dir(): raise FileNotFoundError(f"Output directory '{output_dir}' does not exist.") - data, code_root_path = parse_infos(input_files) + data = parse_infos(input_files) # The LCOV must be ran with '--list-full-path' so that the paths to sources # are not 'simplified' with '...'. - code_root_path = get_common_src_path(data.keys()).parent + code_root_path = Path(src_path).resolve().parent data = unify_dict(data) tld = generate_dir_dict(data, code_root_path) @@ -306,13 +313,14 @@ def genhtml(input_files, output_dir, test_name, html_src_dir, logo_src=None, log data=data[file], file=file, test_name=test_name, - root_name="caliptra-rtl", + root_name=code_root_path.name, path_segments=segments, - src_prefix=code_root_path, + src_prefix=Path(src_path).resolve(), out_dir=f"{output_dir}/index_{Path(file).name}.html", html_src_dir=html_src_dir, logo_src=logo_src, logo_href=logo_href, + project_name=project_name, template_env=template_env, ) @@ -322,12 +330,13 @@ def genhtml(input_files, output_dir, test_name, html_src_dir, logo_src=None, log subdata = generate_file_dict(data, Path(key), code_root_path) render_page( data=subdata, - root_name="caliptra-rtl", + root_name=code_root_path.name, path_segments=key.split("/"), out_dir=f"{output_dir}/index_{key.replace('/','_')}.html", test_name=test_name, logo_src=logo_src, logo_href=logo_href, + project_name=project_name, template_env=template_env, ) @@ -345,14 +354,13 @@ def genhtml(input_files, output_dir, test_name, html_src_dir, logo_src=None, log cov_data[test_type] = [0, 0] render_page( data=tld, - root_name="caliptra-rtl", + root_name=code_root_path.name, path_segments=["src"], out_dir=f"{output_dir}/index.html", test_name=test_name, logo_src=logo_src, logo_href=logo_href, template_env=template_env, + project_name=project_name, links=True, ) - - return code_root_path diff --git a/tools/SiteSpawner/src/sitespawner/update_webpage.py b/tools/SiteSpawner/src/sitespawner/update_webpage.py index c30d82f358b..fcb81cb975d 100644 --- a/tools/SiteSpawner/src/sitespawner/update_webpage.py +++ b/tools/SiteSpawner/src/sitespawner/update_webpage.py @@ -39,7 +39,14 @@ def replace_dir(src_dir, dst_dir): @main_func_log(logger, "Update webpage") @args_on_debug_logger(logger) -def update_webpage(loc_github_ref_name, loc_github_event_name, pr_number, page_url=None): +def update_webpage( + loc_github_ref_name, + loc_github_event_name, + pr_number, + project_name, + include_documentation, + page_url=None, +): """Updates the public part of the gh-pages based on git refs, github events, and PR numbers.""" # Determine the directory based on the GitHub ref and event if loc_github_ref_name == "main": @@ -78,14 +85,27 @@ def update_webpage(loc_github_ref_name, loc_github_event_name, pr_number, page_u dst_file = dst_dir / fname copy2(src_file, dst_file) - generate(webpage_template_dir, str(legacy_page_dir / "html"), str(md_source_dir)) + generate( + webpage_template_dir, + str(legacy_page_dir / "html"), + str(md_source_dir), + include_documentation=include_documentation, + ) SPHINXBUILD = os.getenv("SPHINXBUILD", "sphinx-build") SPHINXOPTS = os.getenv("SPHINXOPTS") logger.info("Building the HTML documentation using Sphinx...") - cmd = [SPHINXBUILD, "-M", "html", str(md_source_dir), str(new_page_dir)] + cmd = [ + SPHINXBUILD, + "-M", + "html", + str(md_source_dir), + str(new_page_dir), + "-D", + f"project={project_name}", + ] if SPHINXOPTS: cmd.append(SPHINXOPTS) diff --git a/tools/SiteSpawner/template/coverage_report/coverage_report.html b/tools/SiteSpawner/template/coverage_report/coverage_report.html index 246f1e803c1..d103e88f482 100644 --- a/tools/SiteSpawner/template/coverage_report/coverage_report.html +++ b/tools/SiteSpawner/template/coverage_report/coverage_report.html @@ -28,7 +28,7 @@