Skip to content

Commit

Permalink
Bump SiteSpawner
Browse files Browse the repository at this point in the history
  • Loading branch information
kiryk committed Sep 13, 2024
1 parent 6a815a5 commit a01e747
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 41 deletions.
43 changes: 41 additions & 2 deletions tools/SiteSpawner/src/sitespawner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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,
Expand All @@ -211,6 +225,7 @@ def setup_parser():
src_path,
info_report_dir,
src_remove_pattern,
src_project_name,
]
create_subparser(
subparsers=subparsers,
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions tools/SiteSpawner/src/sitespawner/gen_coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
21 changes: 13 additions & 8 deletions tools/SiteSpawner/src/sitespawner/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand All @@ -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)
46 changes: 27 additions & 19 deletions tools/SiteSpawner/src/sitespawner/genhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -136,13 +135,15 @@ def render_page(
logo_src,
logo_href,
template_env,
project_name,
links=True,
):
"""Combines the final report page."""
report_html = template_env.get_template("coverage_report.html")

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),
Expand Down Expand Up @@ -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}")
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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
26 changes: 23 additions & 3 deletions tools/SiteSpawner/src/sitespawner/update_webpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</a>
</td>
<td class="title">
Caliptra RTL
{{ project_name }}
{{ header_token }}
coverage report
</td>
Expand Down
2 changes: 1 addition & 1 deletion tools/SiteSpawner/template/coverage_report/src_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</a>
</td>
<td class="title">
Caliptra RTL
{{ project_name }}
{{ header_token }}
coverage report
</td>
Expand Down
Loading

0 comments on commit a01e747

Please sign in to comment.