View Issue Details

IDProjectCategoryView StatusLast Update
0002223OpenFOAMPatchpublic2016-09-03 16:01
Reporterchris Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Versiondev 
Summary0002223: Problem using relative path when sourcing bashrc
DescriptionIf you use a relative path to source the bashrc file, the main environment variables, starting with FOAM_INST_DIR are set incorrectly.
Steps To ReproduceUnset the environment variables with:
wmUnset

Then source the bashrc file using a relative path, e.g. (from the /home/<user> dir, with a home dir installation):
source OpenFOAM/OpenFOAM-dev/etc/bashrc

It results in FOAM_INST_DIR=OpenFOAM, when is should be /home/<user>/OpenFOAM.
Additional InformationThe behaviour is due to the environment variable being set by:
export FOAM_INST_DIR=${BASH_SOURCE%/*/*/*}

I suggest the following to provide the absolute (full) path:
export FOAM_INST_DIR=$(cd ${BASH_SOURCE%/*/*/*} ; pwd)

If anyone can think of any pitfall with this, or an improvement, or agrees, please report.
TagsNo tags attached.

Relationships

related to 0002204 closedhenry Failed compilation 

Activities

wyldckat

2016-08-30 18:03

updater   ~0006793

The only pitfall I can see is related to what we've witnessed in report #2204, where it really depends on whether it's the real path or the symbolic path that matters...

As for using "pwd", there are two types of "pwd" commands:

  - The internal one in Bash, which uses "pwd -L" by default, which essentially preserves any symbolic links for the path, namely the same as "echo $PWD".

  - The external one, e.g. "/usr/bin/pwd", which uses "pwd -P" by default, which will unravel the path to the real path, therefore dropping any symbolic links.

The expected behaviour from using "pwd" in the context of "etc/bashrc" will be that "pwd -L" will be used and the path should essentially be the same as using "echo $PWD".

This is of course assuming the Bash build being used is the more common one, given that some builds may use "pwd -P" as the default...

chris

2016-08-30 21:30

manager   ~0006795

Is the conclusion of the #2204 issue, that it is OK/safe/better to use "pwd -P" instead of "pwd" or "echo $PWD" in this bashrc and throughout other similar files and scripts?

wyldckat

2016-09-01 15:03

updater   ~0006796

Unfortunately, there wasn't any conclusion reached at the end of #2204, at least not yet. I was waiting for the original reporter there to provide a bit more feedback on the choices made.


Nonetheless, after pondering about this, for the change you are suggestion, namely for "FOAM_INST_DIR", either use "pwd -L" or "echo $PWD". The reason is that the symbolic path is more commonly used as short-cut to the actual source code path, where the symbolic link is the desired path that OpenFOAM will use.

The logic behind this suggestion is as follows:

  1. For example, I frequently use "~/OpenFOAM" as a real path, but "~/OpenFOAM/OpenFOAM-4.x" is a symbolic link to another partition/mount. And I source "bashrc" from the symbolic link path "~/OpenFOAM/OpenFOAM-4.x/etc/bashrc".

  2. If we source "bashrc" from the real path at the partition/mount, this can lead to inconsistencies, such as the real path referring to "OpenFOAM-dev" or even "OpenFOAM-Foundation-dev". And there is no guarantee that the symbolic path is ever discovered, based solely on the real path (given by "pwd -P").

----

Beyond that, issue #2204 has lead me to a few conclusions:

  A. The path enforcement is a must in all "Allwmake" scripts that are part of OpenFOAM's source code. Or at the very least, a warning should be given.

  B. "bashrc" should double-check if the "WM_PROJECT_DIR" definition is pointing to a valid path.

Problem is that after thinking further about these two conclusions... issue #2204 should never have happened with the already existing code in OpenFOAM-dev, given that the description given in #2204 is inconsistent with the checks made by the verifications made in the main "Allwmake" and "src/Allwmake" scripts.

wyldckat

2016-09-01 18:57

updater   ~0006797

My previous comment has a massive flaw, because apparently I hadn't tested yet building OpenFOAM 4.x with the symbolic link paths. It might have worked with older versions of OpenFOAM, but not with 4.x.

The "wmake" infrastructure is relies on "pwd -P" in the file "wmake/scripts/wmakeFunctions", specifically in the function "expandPath()".

Therefore, in order to have a consistent behaviour, "pwd -P" should be used in "etc/bashrc" as well. And probably in any other "wmake" related files as well.

chris

2016-09-02 11:45

manager   ~0006800

Using pwd -P seems better to me. For compiling, FOAM_INST_DIR needs to say where the software is installed on the filing system, rather than give a link is to that location.

henry

2016-09-03 16:00

manager   ~0006804

Resolved in OpenFOAM-4.x by commit a874d8fae19a04b2f562655d4e9ead127c5c2540
Resolved in OpenFOAM-dev by commit 133518f6e4a91f86f01f80c8c4243810f2ecaaeb

Please reopen if there are any issues with this change.

Issue History

Date Modified Username Field Change
2016-08-30 17:06 chris New Issue
2016-08-30 17:56 wyldckat Relationship added related to 0002204
2016-08-30 18:03 wyldckat Note Added: 0006793
2016-08-30 21:30 chris Note Added: 0006795
2016-09-01 15:03 wyldckat Note Added: 0006796
2016-09-01 18:57 wyldckat Note Added: 0006797
2016-09-02 11:45 chris Note Added: 0006800
2016-09-03 16:00 henry Note Added: 0006804
2016-09-03 16:00 henry Status new => resolved
2016-09-03 16:00 henry Fixed in Version => 4.x
2016-09-03 16:00 henry Resolution open => fixed
2016-09-03 16:00 henry Assigned To => henry