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

c66fba323c

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
- 197d9d3bf2/etc/bashrc (L45-L47)
This commit is contained in:
Alberto Invernizzi 2023-12-05 12:37:57 +01:00 committed by GitHub
parent 53b528f649
commit 3547bcb517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 @@ def rename_source(self):
# 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)