|
12 | 12 | from sqlalchemy.orm import Session |
13 | 13 |
|
14 | 14 | from macaron.build_spec_generator.build_command_patcher import PatchCommandBuildTool, PatchValueType |
15 | | -from macaron.build_spec_generator.internal_build_info import InternalBuildInfo |
16 | | -from macaron.build_spec_generator.macaron_db_extractor import ( |
17 | | - lookup_any_build_command, |
18 | | - lookup_build_tools_check, |
19 | | - lookup_latest_component_id, |
20 | | - lookup_repository, |
21 | | -) |
22 | | -from macaron.build_spec_generator.reproducible_central import gen_reproducible_central_build_spec |
23 | | -from macaron.errors import QueryMacaronDatabaseError |
24 | | -from macaron.slsa_analyzer.checks.build_tool_check import BuildToolFacts |
| 15 | +from macaron.build_spec_generator.reproducible_central.reproducible_central import gen_reproducible_central_build_spec |
25 | 16 |
|
26 | 17 | logger: logging.Logger = logging.getLogger(__name__) |
27 | 18 |
|
@@ -96,119 +87,10 @@ def gen_build_spec_str( |
96 | 87 | db_engine = create_engine(f"sqlite+pysqlite:///{database_path}", echo=False) |
97 | 88 |
|
98 | 89 | with Session(db_engine) as session, session.begin(): |
99 | | - internal_build_info = get_internal_build_info( |
100 | | - purl=purl, |
101 | | - session=session, |
102 | | - ) |
103 | | - |
104 | | - if not internal_build_info: |
105 | | - logger.error( |
106 | | - "Failed to obtain necessary data for purl %s from the database %s", |
107 | | - purl, |
108 | | - database_path, |
109 | | - ) |
110 | | - return None |
111 | | - |
112 | 90 | match build_spec_format: |
113 | 91 | case BuildSpecFormat.REPRODUCIBLE_CENTRAL: |
114 | | - build_spec_content = gen_reproducible_central_build_spec( |
115 | | - build_info=internal_build_info, |
116 | | - # TODO: update this later |
| 92 | + return gen_reproducible_central_build_spec( |
| 93 | + purl=purl, |
| 94 | + session=session, |
117 | 95 | patches=CLI_COMMAND_PATCHES, |
118 | 96 | ) |
119 | | - |
120 | | - return build_spec_content |
121 | | - |
122 | | - |
123 | | -def get_internal_build_info( |
124 | | - purl: PackageURL, |
125 | | - session: Session, |
126 | | -) -> InternalBuildInfo | None: |
127 | | - """Return an ``InternalBuildInfo`` instance that captures the build related information for a PackageURL. |
128 | | -
|
129 | | - Parameters |
130 | | - ---------- |
131 | | - purl: PackageURL |
132 | | - The PackageURL to extract information about. |
133 | | - session: Session |
134 | | - The SQLAlchemy Session for the Macaron database. |
135 | | -
|
136 | | - Returns |
137 | | - ------- |
138 | | - InternalBuildInfo | None |
139 | | - An instance of ``InternalBuildInfo`` or None if there was an error. |
140 | | - """ |
141 | | - try: |
142 | | - latest_component_id = lookup_latest_component_id( |
143 | | - purl=purl, |
144 | | - session=session, |
145 | | - ) |
146 | | - except QueryMacaronDatabaseError as lookup_component_error: |
147 | | - logger.error( |
148 | | - "Unexpected result from querying latest component id for %s. Error: %s", |
149 | | - purl.to_string(), |
150 | | - lookup_component_error, |
151 | | - ) |
152 | | - return None |
153 | | - if not latest_component_id: |
154 | | - logger.error( |
155 | | - "Cannot find an analysis result for PackageURL %s in the database. " |
156 | | - + "Please check if an analysis for it exists in the database.", |
157 | | - purl.to_string(), |
158 | | - ) |
159 | | - return None |
160 | | - logger.debug("Latest component ID: %d", latest_component_id) |
161 | | - |
162 | | - try: |
163 | | - build_tool_facts = lookup_build_tools_check( |
164 | | - component_id=latest_component_id, |
165 | | - session=session, |
166 | | - ) |
167 | | - except QueryMacaronDatabaseError as lookup_build_tools_error: |
168 | | - logger.error( |
169 | | - "Unexpected result from querying build tools for %s. Error: %s", |
170 | | - purl.to_string(), |
171 | | - lookup_build_tools_error, |
172 | | - ) |
173 | | - return None |
174 | | - if not build_tool_facts: |
175 | | - logger.error( |
176 | | - "Cannot find any build tool for PackageURL %s in the database.", |
177 | | - purl.to_string(), |
178 | | - ) |
179 | | - return None |
180 | | - logger.debug("Build tools discovered from the %s table: %s", BuildToolFacts.__tablename__, build_tool_facts) |
181 | | - |
182 | | - try: |
183 | | - lookup_component_repository = lookup_repository(latest_component_id, session) |
184 | | - except QueryMacaronDatabaseError as lookup_repository_error: |
185 | | - logger.error( |
186 | | - "Unexpected result from querying repository information for %s. Error: %s", |
187 | | - purl.to_string(), |
188 | | - lookup_repository_error, |
189 | | - ) |
190 | | - return None |
191 | | - if not lookup_component_repository: |
192 | | - logger.error( |
193 | | - "Cannot find any repository information for %s in the database.", |
194 | | - purl.to_string(), |
195 | | - ) |
196 | | - return None |
197 | | - |
198 | | - try: |
199 | | - lookup_build_facts = lookup_any_build_command(latest_component_id, session) |
200 | | - except QueryMacaronDatabaseError as lookup_build_command_error: |
201 | | - logger.error( |
202 | | - "Unexpected result from querying all build command information for %s. Error: %s", |
203 | | - purl.to_string(), |
204 | | - lookup_build_command_error, |
205 | | - ) |
206 | | - return None |
207 | | - |
208 | | - return InternalBuildInfo( |
209 | | - purl=purl, |
210 | | - repository=lookup_component_repository, |
211 | | - latest_component_id=latest_component_id, |
212 | | - build_tool_facts=build_tool_facts, |
213 | | - generic_build_command_facts=lookup_build_facts, |
214 | | - ) |
0 commit comments