diff --git a/lib/_emerge/EbuildMetadataPhase.py b/lib/_emerge/EbuildMetadataPhase.py index 54177840c7..524a8507b7 100644 --- a/lib/_emerge/EbuildMetadataPhase.py +++ b/lib/_emerge/EbuildMetadataPhase.py @@ -36,6 +36,7 @@ class EbuildMetadataPhase(SubProcess): "repo_path", "settings", "deallocate_config", + "portage_ebuild_extra_source", "write_auxdb", ) + ( "_eapi", @@ -165,6 +166,9 @@ def _async_start_done(self, future): self.cancel() self._was_cancelled() + self.portage_ebuild_extra_source = self.settings.get( + "PORTAGE_EBUILD_EXTRA_SOURCE" + ) if self.deallocate_config is not None and not self.deallocate_config.done(): self.deallocate_config.set_result(self.settings) @@ -191,6 +195,8 @@ def _unregister(self): if self._files is not None: self.scheduler.remove_reader(self._files.ebuild) SubProcess._unregister(self) + if self.portage_ebuild_extra_source: + os.unlink(self.portage_ebuild_extra_source) def _async_waitpid_cb(self, *args, **kwargs): """ diff --git a/lib/portage/package/ebuild/doebuild.py b/lib/portage/package/ebuild/doebuild.py index c4780a6ff8..4486909667 100644 --- a/lib/portage/package/ebuild/doebuild.py +++ b/lib/portage/package/ebuild/doebuild.py @@ -2197,10 +2197,19 @@ def spawn( env = orig_env.copy() t = env["T"] - if not os.path.isdir(t): - os.makedirs(t) + if os.path.isdir(t): + ebuild_extra_source_path = os.path.join(t, ".portage-ebuild-extra-source") + else: + ebuild_extra_source_fd, ebuild_extra_source_path = tempfile.mkstemp( + prefix="portage-ebuild-extra-source-", + ) + os.chmod( + ebuild_extra_source_path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH + ) + os.close(ebuild_extra_source_fd) + # The file will be deleted by EbuildMetadataPhase._unregister() + mysettings["PORTAGE_EBUILD_EXTRA_SOURCE"] = ebuild_extra_source_path - ebuild_extra_source_path = os.path.join(t, ".portage-ebuild-extra-source") with open(ebuild_extra_source_path, mode="w") as f: for var_name in unexported_env_vars: var_value = orig_env.get(var_name)