From 42afbeef7f99793dcb8be00b0d0ef65359cd9f0c Mon Sep 17 00:00:00 2001 From: Tristan Keen Date: Fri, 12 Jul 2024 20:38:59 +0100 Subject: [PATCH] Extend LIBRARY_PATH as well as LD_LIBRARY_PATH on Linux --- dist/setup/index.js | 17 +++++++++++------ src/find-python.ts | 21 ++++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index e28c3be0e..6e068d287 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91070,13 +91070,9 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest core.exportVariable('Python3_ROOT_DIR', installDir); core.exportVariable('PKG_CONFIG_PATH', installDir + '/lib/pkgconfig'); if (utils_1.IS_LINUX) { - const libPath = process.env.LD_LIBRARY_PATH - ? `:${process.env.LD_LIBRARY_PATH}` - : ''; const pyLibPath = path.join(installDir, 'lib'); - if (!libPath.split(':').includes(pyLibPath)) { - core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath); - } + ensurePathInEnvVar('LIBRARY_PATH', pyLibPath); + ensurePathInEnvVar('LD_LIBRARY_PATH', pyLibPath); } core.addPath(installDir); core.addPath(_binDir); @@ -91099,6 +91095,15 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest }); } exports.useCpythonVersion = useCpythonVersion; +/** Ensure a folder is present in a colon-separated env-var */ +function ensurePathInEnvVar(envVarName, extraPath) { + const currentPath = process.env[envVarName] + ? `:${process.env[envVarName]}` + : ''; + if (!currentPath.split(':').includes(extraPath)) { + core.exportVariable(envVarName, extraPath + currentPath); + } +} /** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */ function desugarDevVersion(versionSpec) { const devVersion = /^(\d+)\.(\d+)-dev$/; diff --git a/src/find-python.ts b/src/find-python.ts index 77278770a..e5bc72659 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -121,15 +121,11 @@ export async function useCpythonVersion( core.exportVariable('PKG_CONFIG_PATH', installDir + '/lib/pkgconfig'); if (IS_LINUX) { - const libPath = process.env.LD_LIBRARY_PATH - ? `:${process.env.LD_LIBRARY_PATH}` - : ''; const pyLibPath = path.join(installDir, 'lib'); - - if (!libPath.split(':').includes(pyLibPath)) { - core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath); - } + ensurePathInEnvVar('LIBRARY_PATH', pyLibPath); + ensurePathInEnvVar('LD_LIBRARY_PATH', pyLibPath); } + core.addPath(installDir); core.addPath(_binDir); @@ -159,6 +155,17 @@ export async function useCpythonVersion( return {impl: 'CPython', version: installed}; } +/** Ensure a folder is present in a colon-separated env-var */ +function ensurePathInEnvVar(envVarName: string, extraPath: string) { + const currentPath = process.env[envVarName] + ? `:${process.env[envVarName]}` + : ''; + + if (!currentPath.split(':').includes(extraPath)) { + core.exportVariable(envVarName, extraPath + currentPath); + } +} + /** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */ function desugarDevVersion(versionSpec: string) { const devVersion = /^(\d+)\.(\d+)-dev$/;