|
4 | 4 | """This module contains the representation of information needed for Reproducible Central Buildspec generation.""" |
5 | 5 |
|
6 | 6 | import logging |
| 7 | +import pprint |
7 | 8 | from collections.abc import Sequence |
8 | 9 | from dataclasses import dataclass |
9 | 10 |
|
@@ -38,6 +39,12 @@ class RcInternalBuildInfo: |
38 | 39 | build_tool_facts: Sequence[BuildToolFacts] |
39 | 40 |
|
40 | 41 |
|
| 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 | + |
41 | 48 | def get_rc_internal_build_info( |
42 | 49 | purl: PackageURL, |
43 | 50 | session: Session, |
@@ -78,55 +85,69 @@ def get_rc_internal_build_info( |
78 | 85 | logger.debug("Latest component ID: %d", latest_component_id) |
79 | 86 |
|
80 | 87 | 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: |
86 | 90 | logger.error( |
87 | | - "Unexpected result from querying build tools for %s. Error: %s", |
| 91 | + "Unexpected result from querying repository information for %s. Error: %s", |
88 | 92 | purl.to_string(), |
89 | | - lookup_build_tools_error, |
| 93 | + lookup_repository_error, |
90 | 94 | ) |
91 | 95 | return None |
92 | | - if not build_tool_facts: |
| 96 | + if not lookup_component_repository: |
93 | 97 | 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.", |
95 | 99 | purl.to_string(), |
96 | 100 | ) |
97 | 101 | 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 | + ) |
99 | 108 |
|
100 | 109 | 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: |
103 | 115 | logger.error( |
104 | | - "Unexpected result from querying repository information for %s. Error: %s", |
| 116 | + "Unexpected result from querying build tools for %s. Error: %s", |
105 | 117 | purl.to_string(), |
106 | | - lookup_repository_error, |
| 118 | + lookup_build_tools_error, |
107 | 119 | ) |
108 | 120 | return None |
109 | | - if not lookup_component_repository: |
| 121 | + if not build_tool_facts: |
110 | 122 | 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.", |
112 | 124 | purl.to_string(), |
113 | 125 | ) |
114 | 126 | 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 | + ) |
115 | 132 |
|
116 | 133 | 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) |
118 | 135 | except QueryMacaronDatabaseError as lookup_build_command_error: |
119 | 136 | logger.error( |
120 | 137 | "Unexpected result from querying all build command information for %s. Error: %s", |
121 | 138 | purl.to_string(), |
122 | 139 | lookup_build_command_error, |
123 | 140 | ) |
124 | 141 | return None |
| 142 | + logger.debug( |
| 143 | + "Build command information discovered\n%s", |
| 144 | + format_build_command_infos(lookup_build_command_infos), |
| 145 | + ) |
125 | 146 |
|
126 | 147 | return RcInternalBuildInfo( |
127 | 148 | purl=purl, |
128 | 149 | repository=lookup_component_repository, |
129 | 150 | latest_component_id=latest_component_id, |
130 | 151 | build_tool_facts=build_tool_facts, |
131 | | - generic_build_command_facts=lookup_build_facts, |
| 152 | + generic_build_command_facts=lookup_build_command_infos, |
132 | 153 | ) |
0 commit comments