Skip to content

Commit fe6cf54

Browse files
committed
determine rpath for chapel-py shared lib when using --prefix
Signed-off-by: Ahmad Rezaii <ahmad.rezaii@hpe.com>
1 parent c534099 commit fe6cf54

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

tools/chapel-py/setup.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747

4848
host_bin_subdir = str(chpl_variables.get("CHPL_HOST_BIN_SUBDIR"))
4949
chpl_lib_path = os.path.join(chpl_home, "lib", "compiler", host_bin_subdir)
50+
# For installations using --prefix, the build and final lib paths are going to
51+
# differ figure out the install location now and write it to the rpath
52+
chpl_home_utils = os.path.join(
53+
chpl_home, "util", "chplenv", "chpl_home_utils.py"
54+
)
55+
chpl_install_lib_path = (
56+
subprocess.check_output(
57+
["python", chpl_home_utils, "--configured-install-lib-prefix"],
58+
)
59+
.decode(sys.stdout.encoding)
60+
.strip()
61+
.splitlines()
62+
)
5063

5164
CXXFLAGS = []
5265
if have_llvm and have_llvm != "none":
@@ -68,6 +81,12 @@
6881
"-lChplFrontendShared",
6982
]
7083

84+
if chpl_install_lib_path is not None:
85+
LDFLAGS += [
86+
"-L{}".format(chpl_install_lib_path),
87+
"-Wl,-rpath,{}".format(chpl_install_lib_path),
88+
]
89+
7190
if str(chpl_variables.get("CHPL_SANITIZE")) == "address":
7291
if str(chpl_variables.get("CHPL_HOST_PLATFORM")) == "darwin":
7392
sys.exit(

util/chplenv/chpl_home_utils.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,44 @@ def get_chpl_third_party():
5454
os.path.sep,
5555
os.path.sep))
5656

57+
@memoize
58+
def get_chpl_configured_install_lib_prefix():
59+
# gets the path to the lib directory for a prefix install, or None if not
60+
# a prefix install
61+
chpl_home = str(os.getenv("CHPL_HOME"))
62+
if os.path.exists(os.path.join(chpl_home, "configured-prefix")):
63+
with open(os.path.join(chpl_home, "CMakeLists.txt"), "r") as f:
64+
# read CMakeLists.txt to get the CHPL_MAJOR_VERSION and
65+
# CHPL_MINOR_VERSION and then construct the path from that
66+
chpl_major_version = None
67+
chpl_minor_version = None
68+
for line in f:
69+
if "set(CHPL_MAJOR_VERSION" in line:
70+
chpl_major_version = line.split()[1].strip(")")
71+
if "set(CHPL_MINOR_VERSION" in line:
72+
chpl_minor_version = line.split()[1].strip(")")
73+
if (
74+
chpl_major_version is not None
75+
and chpl_minor_version is not None
76+
):
77+
break
78+
assert chpl_major_version is not None and chpl_minor_version is not None
79+
chpl_version_string = "{}.{}".format(
80+
chpl_major_version,
81+
chpl_minor_version,
82+
)
83+
chpl_prefix = None
84+
with open(os.path.join(chpl_home, "configured-prefix"), "r") as f:
85+
chpl_prefix = f.read().strip()
86+
assert chpl_prefix is not None
87+
return os.path.join(
88+
chpl_prefix,
89+
"lib",
90+
"chapel",
91+
chpl_version_string,
92+
"compiler",
93+
)
94+
5795
@memoize
5896
def get_chpl_version_from_install():
5997
if get_prefix_install_prefix():
@@ -189,6 +227,8 @@ def _main():
189227
)
190228
parser.add_option('--using-module', action='store_const',
191229
dest='func', const=using_chapel_module)
230+
parser.add_option('--configured-install-lib-prefix', action='store_const',
231+
dest='func', const=get_chpl_configured_install_lib_prefix)
192232
(options, args) = parser.parse_args()
193233

194234
if options.func:

0 commit comments

Comments
 (0)