|
44 | 44 | from albs_common_lib.utils.index_utils import extract_metadata |
45 | 45 | from albs_common_lib.utils.ported import to_unicode |
46 | 46 | from albs_common_lib.utils.rpm_utils import unpack_src_rpm |
47 | | -from albs_common_lib.utils.spec_parser import SpecParser, SpecSource |
| 47 | +from albs_common_lib.utils.spec_parser import SpecParser, SpecPatch, SpecSource |
48 | 48 | from pyrpm.spec import Spec, replace_macros |
49 | 49 |
|
50 | 50 | from build_node.utils.git_sources_utils import ( |
@@ -514,19 +514,39 @@ def prepare_koji_sources( |
514 | 514 | new_spec_path = os.path.join(output_dir, spec_file_name) |
515 | 515 | shutil.copy(spec_path, new_spec_path) |
516 | 516 | try: |
517 | | - parsed_spec = SpecParser( |
518 | | - spec_path, self.task.platform.data.get('definitions') |
519 | | - ) |
| 517 | + self.logger.debug("Trying to use SpecParser") |
| 518 | + defs = self.task.platform.data.get('definitions', {}).copy() |
| 519 | + sources_dir = os.path.join(git_sources_dir, 'SOURCES') |
| 520 | + if os.path.exists(sources_dir): |
| 521 | + defs['_sourcedir'] = sources_dir |
| 522 | + try: |
| 523 | + parsed_spec = SpecParser( |
| 524 | + spec_path, defs |
| 525 | + ) |
| 526 | + except Exception as exc: |
| 527 | + self.logger.debug( |
| 528 | + 'Error: %s. Trying to use SpecParser with different ' |
| 529 | + '_sourcedir: %s', |
| 530 | + str(exc), |
| 531 | + git_sources_dir |
| 532 | + ) |
| 533 | + defs['_sourcedir'] = git_sources_dir |
| 534 | + parsed_spec = SpecParser( |
| 535 | + spec_path, defs |
| 536 | + ) |
520 | 537 | sources = parsed_spec.source_package.sources |
521 | 538 | patches = parsed_spec.source_package.patches |
522 | | - except Exception: |
| 539 | + except Exception as exc: |
| 540 | + self.logger.debug("SpecParser failed: %s", str(exc)) |
523 | 541 | try: |
524 | 542 | parsed_spec = Spec.from_file(spec_path) |
525 | 543 | sources = [ |
526 | | - replace_macros(s, parsed_spec) for s in parsed_spec.sources |
| 544 | + SpecSource(replace_macros(s, parsed_spec), position) |
| 545 | + for position, s in enumerate(parsed_spec.sources) |
527 | 546 | ] |
528 | 547 | patches = [ |
529 | | - replace_macros(p, parsed_spec) for p in parsed_spec.patches |
| 548 | + SpecPatch(replace_macros(p, parsed_spec), position) |
| 549 | + for position, p in enumerate(parsed_spec.patches) |
530 | 550 | ] |
531 | 551 | except Exception: |
532 | 552 | self.logger.exception( |
|
0 commit comments