Extend PKG_CONFIG path rather than overwriting it

This commit is contained in:
Christoph Hansknecht 2025-11-07 15:31:33 +01:00
parent cfd55ca824
commit 87c35f43f0
5 changed files with 51 additions and 5 deletions

View File

@ -307,6 +307,32 @@ describe('findPyPyVersion', () => {
).rejects.toThrow();
});
it('update PKG_CONFIG_PATH', async () => {
process.env['PKG_CONFIG_PATH'] = '/test/dir';
spyCacheDir = jest.spyOn(tc, 'cacheDir');
spyCacheDir.mockImplementation(() =>
path.join(toolDir, 'PyPy', '3.7.7', architecture)
);
spyChmodSync = jest.spyOn(fs, 'chmodSync');
spyChmodSync.mockImplementation(() => undefined);
await expect(
finder.findPyPyVersion(
'pypy-3.7-v7.3.x',
architecture,
true,
false,
false
)
).resolves.toEqual({
resolvedPythonVersion: '3.7.9',
resolvedPyPyVersion: '7.3.3'
});
expect(spyCoreExportVariable).toHaveBeenCalledWith(
'PKG_CONFIG_PATH',
expect.stringContaining('/test/dir')
);
});
it('found and install successfully', async () => {
spyCacheDir = jest.spyOn(tc, 'cacheDir');
spyCacheDir.mockImplementation(() =>

View File

@ -6,6 +6,8 @@ import * as semver from 'semver';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import {addPkgConfigPathToEnv} from './utils';
export async function findGraalPyVersion(
versionSpec: string,
architecture: string,
@ -67,7 +69,7 @@ export async function findGraalPyVersion(
core.exportVariable('Python2_ROOT_DIR', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
core.exportVariable('Python3_ROOT_DIR', installDir);
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
addPkgConfigPathToEnv(pythonLocation + '/lib/pkgconfig');
core.addPath(pythonLocation);
core.addPath(_binDir);
}

View File

@ -8,7 +8,8 @@ import {
readExactPyPyVersionFile,
validatePythonVersionFormatForPyPy,
IPyPyManifestRelease,
getBinaryDirectory
getBinaryDirectory,
addPkgConfigPathToEnv
} from './utils';
import * as semver from 'semver';
@ -92,7 +93,8 @@ export async function findPyPyVersion(
core.exportVariable('Python2_ROOT_DIR', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
core.exportVariable('Python3_ROOT_DIR', installDir);
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
addPkgConfigPathToEnv(pythonLocation + '/lib/pkgconfig');
core.addPath(pythonLocation);
core.addPath(_binDir);
}

View File

@ -10,6 +10,8 @@ import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as exec from '@actions/exec';
import {addPkgConfigPathToEnv} from './utils';
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
// This is where pip is, along with anything that pip installs.
// There is a separate directory for `pip install --user`.
@ -150,7 +152,6 @@ export async function useCpythonVersion(
);
if (updateEnvironment) {
core.exportVariable('pythonLocation', installDir);
core.exportVariable('PKG_CONFIG_PATH', installDir + '/lib/pkgconfig');
core.exportVariable('pythonLocation', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
core.exportVariable('Python_ROOT_DIR', installDir);
@ -158,7 +159,8 @@ export async function useCpythonVersion(
core.exportVariable('Python2_ROOT_DIR', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
core.exportVariable('Python3_ROOT_DIR', installDir);
core.exportVariable('PKG_CONFIG_PATH', installDir + '/lib/pkgconfig');
addPkgConfigPathToEnv(installDir + '/lib/pkgconfig');
if (IS_LINUX) {
const libPath = process.env.LD_LIBRARY_PATH

View File

@ -422,3 +422,17 @@ export function getDownloadFileName(downloadUrl: string): string | undefined {
? path.join(tempDir, path.basename(downloadUrl))
: undefined;
}
export function addPkgConfigPathToEnv(path: string): undefined {
const pkg_config_path = process.env['PKG_CONFIG_PATH'];
if (pkg_config_path === undefined) {
core.exportVariable('PKG_CONFIG_PATH', path);
} else {
if (IS_WINDOWS) {
core.exportVariable('PKG_CONFIG_PATH', `${path};${pkg_config_path}`);
} else {
core.exportVariable('PKG_CONFIG_PATH', `${path}:${pkg_config_path}`);
}
}
}