From 3547bcb51714872e4fc735a657b38ecc6eeae30c Mon Sep 17 00:00:00 2001 From: Alberto Invernizzi <9337627+albestro@users.noreply.github.com> Date: Tue, 5 Dec 2023 12:37:57 +0100 Subject: openfoam-org: fix for being able to build manually checked out repository (#41000) * grep WM_PROJECT_VERSION from etc/bashrc This fixes the problem when building from a manually checked out repo which might have a different version wrt the one defined in the spack package (e.g. anything later than 5.0 is known as 5.x by the build system) * patch applies to just 5.0, in newer versions it is already addressed In `5.20171030` there's a commit https://github.com/OpenFOAM/OpenFOAM-5.x/commit/c66fba323c348012c2d4a75b9091406e1b3bcc31 very similar (almost identical) to what the patch `50-etc.patch` does. So the patch should not be applied to other than `5.0` otherwise it errors. References: - https://github.com/OpenFOAM/OpenFOAM-5.x/commits/20171030/etc/bashrc - https://github.com/OpenFOAM/OpenFOAM-5.x/blob/197d9d3bf20ac0641a8fe4f57be6a6325ca834b1/etc/bashrc#L45-L47 --- .../repos/builtin/packages/openfoam-org/package.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/var/spack/repos/builtin/packages/openfoam-org/package.py b/var/spack/repos/builtin/packages/openfoam-org/package.py index 01d57489ac..e3bf0bfb28 100644 --- a/var/spack/repos/builtin/packages/openfoam-org/package.py +++ b/var/spack/repos/builtin/packages/openfoam-org/package.py @@ -120,7 +120,7 @@ class OpenfoamOrg(Package): sha256="05d17e17f94e6fe8188a9c0b91ed34c9b62259414589d908c152a4c40fe6b7e2", when="@7", ) - patch("50-etc.patch", when="@5.0:5.9") + patch("50-etc.patch", when="@5.0") patch("41-etc.patch", when="@4.1") patch("41-site.patch", when="@4.1:") patch("240-etc.patch", when="@:2.4.0") @@ -236,8 +236,24 @@ class OpenfoamOrg(Package): # to build correctly! parent = os.path.dirname(self.stage.source_path) original = os.path.basename(self.stage.source_path) - target = "OpenFOAM-{0}".format(self.version) - # Could also grep through etc/bashrc for WM_PROJECT_VERSION + + # Grep for WM_PROJECT_VERSION in etc/bashrc + # e.g. "export WM_PROJECT_VERSION=5.x" + # + # note: WM_PROJECT is assumed to be OpenFOAM and the project folder is assumed to + # be "OpenFOAM-${WM_PROJECT_VERSION}" + target = None + with open(join_path(self.stage.source_path, "etc/bashrc"), "r") as bashrc_file: + import re + + for line in bashrc_file.readlines(): + m = re.match("export WM_PROJECT_VERSION=(.*)", line) + if m: + target = f"OpenFOAM-{m.group(1)}" + break + if target is None: + raise InstallError("Failed to infer projet directory name from build script.") + with working_dir(parent): if original != target and not os.path.lexists(target): os.rename(original, target) -- cgit v1.2.3-60-g2f50