diff --git a/portable-python.yml b/portable-python.yml index 748c541..a3e59fd 100644 --- a/portable-python.yml +++ b/portable-python.yml @@ -46,3 +46,11 @@ cpython-additional-packages: # openssl-configure: # - -v # - --openssldir=/etc/ssl + + +# Uncomment if you need to patch the source code of a module before compiling it +#cpython-modules: zlib +#zlib-patches: +# - file: configure +# regex: "# start off configure.log" +# replacement: "echo starting zlib configure script with patches" diff --git a/src/portable_python/__init__.py b/src/portable_python/__init__.py index 8b9b429..0e105ec 100644 --- a/src/portable_python/__init__.py +++ b/src/portable_python/__init__.py @@ -502,6 +502,9 @@ def cfg_configure(self, deps_lib): configure_template = Template(configure) return configure_template.substitute(deps_lib=deps_lib) + def cfg_patches(self): + return PPG.config.get_value("%s-patches" % self.m_name) + @property def url(self): """Url of source tarball, if any""" @@ -650,6 +653,7 @@ def compile(self): folder = folder / self.m_build_cwd with runez.CurrentFolder(folder): + self._apply_patches() self._prepare() func() self._finalize() @@ -663,6 +667,15 @@ def compile(self): else: os.environ[k] = v + def _apply_patches(self): + if patches := self.cfg_patches(): + for patch in patches: + if runez.DRYRUN: + print(f"Would apply patch: {patch}") + else: + print(f"Applying patch: {patch}") + patch_file(patch["file"], patch["regex"], patch["replacement"]) + def _get_env_vars(self): """Yield all found env vars, first found wins""" result = {}