Skip to content

Commit 652e219

Browse files
Merge pull request #211 from javihernandez/bs-482
Provide _sourcedir to SpecParser when parsing the spec file
2 parents 032bc1b + 55c1f42 commit 652e219

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

build_node/builders/base_rpm_builder.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from albs_common_lib.utils.index_utils import extract_metadata
4545
from albs_common_lib.utils.ported import to_unicode
4646
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
4848
from pyrpm.spec import Spec, replace_macros
4949

5050
from build_node.utils.git_sources_utils import (
@@ -514,19 +514,39 @@ def prepare_koji_sources(
514514
new_spec_path = os.path.join(output_dir, spec_file_name)
515515
shutil.copy(spec_path, new_spec_path)
516516
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+
)
520537
sources = parsed_spec.source_package.sources
521538
patches = parsed_spec.source_package.patches
522-
except Exception:
539+
except Exception as exc:
540+
self.logger.debug("SpecParser failed: %s", str(exc))
523541
try:
524542
parsed_spec = Spec.from_file(spec_path)
525543
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)
527546
]
528547
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)
530550
]
531551
except Exception:
532552
self.logger.exception(

0 commit comments

Comments
 (0)