Skip to content

Commit 717803a

Browse files
author
Trong Nhan Mai
committed
chore: move the looking up of repository before the build tool lookup because without repository no build tool is found
This commit also add some useful debug messages for extracting values from the database for Reproducible Central buildspec generation.
1 parent b4ffe6b commit 717803a

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

src/macaron/build_spec_generator/reproducible_central/rc_build_info.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""This module contains the representation of information needed for Reproducible Central Buildspec generation."""
55

66
import logging
7+
import pprint
78
from collections.abc import Sequence
89
from dataclasses import dataclass
910

@@ -38,6 +39,12 @@ class RcInternalBuildInfo:
3839
build_tool_facts: Sequence[BuildToolFacts]
3940

4041

42+
def format_build_command_infos(build_command_infos: list[GenericBuildCommandInfo]) -> str:
43+
"""Return the prettified str format for a list of `GenericBuildCommandInfo` instances."""
44+
pretty_formatted_ouput = [pprint.pformat(build_command_info) for build_command_info in build_command_infos]
45+
return "\n".join(pretty_formatted_ouput)
46+
47+
4148
def get_rc_internal_build_info(
4249
purl: PackageURL,
4350
session: Session,
@@ -78,55 +85,69 @@ def get_rc_internal_build_info(
7885
logger.debug("Latest component ID: %d", latest_component_id)
7986

8087
try:
81-
build_tool_facts = lookup_build_tools_check(
82-
component_id=latest_component_id,
83-
session=session,
84-
)
85-
except QueryMacaronDatabaseError as lookup_build_tools_error:
88+
lookup_component_repository = lookup_repository(latest_component_id, session)
89+
except QueryMacaronDatabaseError as lookup_repository_error:
8690
logger.error(
87-
"Unexpected result from querying build tools for %s. Error: %s",
91+
"Unexpected result from querying repository information for %s. Error: %s",
8892
purl.to_string(),
89-
lookup_build_tools_error,
93+
lookup_repository_error,
9094
)
9195
return None
92-
if not build_tool_facts:
96+
if not lookup_component_repository:
9397
logger.error(
94-
"Cannot find any build tool for PackageURL %s in the database.",
98+
"Cannot find any repository information for %s in the database.",
9599
purl.to_string(),
96100
)
97101
return None
98-
logger.debug("Build tools discovered from the %s table: %s", BuildToolFacts.__tablename__, build_tool_facts)
102+
logger.info(
103+
"Repository information for purl %s: url %s, commit %s",
104+
purl,
105+
lookup_component_repository.remote_path,
106+
lookup_component_repository.commit_sha,
107+
)
99108

100109
try:
101-
lookup_component_repository = lookup_repository(latest_component_id, session)
102-
except QueryMacaronDatabaseError as lookup_repository_error:
110+
build_tool_facts = lookup_build_tools_check(
111+
component_id=latest_component_id,
112+
session=session,
113+
)
114+
except QueryMacaronDatabaseError as lookup_build_tools_error:
103115
logger.error(
104-
"Unexpected result from querying repository information for %s. Error: %s",
116+
"Unexpected result from querying build tools for %s. Error: %s",
105117
purl.to_string(),
106-
lookup_repository_error,
118+
lookup_build_tools_error,
107119
)
108120
return None
109-
if not lookup_component_repository:
121+
if not build_tool_facts:
110122
logger.error(
111-
"Cannot find any repository information for %s in the database.",
123+
"Cannot find any build tool for PackageURL %s in the database.",
112124
purl.to_string(),
113125
)
114126
return None
127+
logger.info(
128+
"Build tools discovered from the %s table: %s",
129+
BuildToolFacts.__tablename__,
130+
[fact.build_tool_name for fact in build_tool_facts],
131+
)
115132

116133
try:
117-
lookup_build_facts = lookup_any_build_command(latest_component_id, session)
134+
lookup_build_command_infos = lookup_any_build_command(latest_component_id, session)
118135
except QueryMacaronDatabaseError as lookup_build_command_error:
119136
logger.error(
120137
"Unexpected result from querying all build command information for %s. Error: %s",
121138
purl.to_string(),
122139
lookup_build_command_error,
123140
)
124141
return None
142+
logger.debug(
143+
"Build command information discovered\n%s",
144+
format_build_command_infos(lookup_build_command_infos),
145+
)
125146

126147
return RcInternalBuildInfo(
127148
purl=purl,
128149
repository=lookup_component_repository,
129150
latest_component_id=latest_component_id,
130151
build_tool_facts=build_tool_facts,
131-
generic_build_command_facts=lookup_build_facts,
152+
generic_build_command_facts=lookup_build_command_infos,
132153
)

0 commit comments

Comments
 (0)