1515import os
1616import pathlib
1717import re
18+ from string import Template
1819from typing import ClassVar , List
1920
2021import runez
@@ -491,6 +492,19 @@ def is_usable_module(self, name):
491492 def cfg_version (self , default ):
492493 return PPG .config .get_value ("%s-version" % self .m_name ) or default
493494
495+ def cfg_url (self , version ):
496+ if config_url := PPG .config .get_value ("%s-url" % self .m_name ):
497+ url_template = Template (config_url )
498+ return url_template .substitute (version = version )
499+
500+ def cfg_configure (self , deps_lib ):
501+ if configure := PPG .config .get_value ("%s-configure" % self .m_name ):
502+ configure_template = Template (configure )
503+ return configure_template .substitute (deps_lib = deps_lib )
504+
505+ def cfg_patches (self ):
506+ return PPG .config .get_value ("%s-patches" % self .m_name )
507+
494508 @property
495509 def url (self ):
496510 """Url of source tarball, if any"""
@@ -650,6 +664,7 @@ def compile(self):
650664 folder = folder / self .m_build_cwd
651665
652666 with runez .CurrentFolder (folder ):
667+ self ._apply_patches ()
653668 self ._prepare ()
654669 func ()
655670 self ._finalize ()
@@ -663,6 +678,15 @@ def compile(self):
663678 else :
664679 os .environ [k ] = v
665680
681+ def _apply_patches (self ):
682+ if patches := self .cfg_patches ():
683+ for patch in patches :
684+ if runez .DRYRUN :
685+ print (f"Would apply patch: { patch } " )
686+ else :
687+ print (f"Applying patch: { patch } " )
688+ patch_file (patch ["file" ], patch ["regex" ], patch ["replacement" ])
689+
666690 def _get_env_vars (self ):
667691 """Yield all found env vars, first found wins"""
668692 result = {}
0 commit comments