mirror of https://github.com/aminya/setup-cpp
fix: use which if the pip package executable was not found
This commit is contained in:
parent
e376f26cd2
commit
04867b97c5
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -18,6 +18,7 @@ import { isBinUptoDate } from "../utils/setup/version"
|
||||||
import { getVersion } from "../versions/versions"
|
import { getVersion } from "../versions/versions"
|
||||||
import assert from "assert"
|
import assert from "assert"
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
|
import { unique } from "../utils/std"
|
||||||
|
|
||||||
export async function setupPython(version: string, setupDir: string, arch: string) {
|
export async function setupPython(version: string, setupDir: string, arch: string) {
|
||||||
if (ciDetect() !== "github-actions") {
|
if (ciDetect() !== "github-actions") {
|
||||||
|
@ -129,7 +130,7 @@ export async function setupPythonAndPip(): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addPythonBaseExecPrefix(python: string) {
|
export async function addPythonBaseExecPrefix(python: string) {
|
||||||
let dirs: string[] = []
|
const dirs: string[] = []
|
||||||
|
|
||||||
// detection based on the platform
|
// detection based on the platform
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
|
@ -143,11 +144,6 @@ export async function addPythonBaseExecPrefix(python: string) {
|
||||||
// any of these are possible depending on the operating system!
|
// any of these are possible depending on the operating system!
|
||||||
dirs.push(join(base_exec_prefix, "Scripts"), join(base_exec_prefix, "Scripts", "bin"), join(base_exec_prefix, "bin"))
|
dirs.push(join(base_exec_prefix, "Scripts"), join(base_exec_prefix, "Scripts", "bin"), join(base_exec_prefix, "bin"))
|
||||||
|
|
||||||
// exclude the non existing ones
|
// remove duplicates
|
||||||
dirs = dirs.filter((dir) => existsSync(dir))
|
return unique(dirs)
|
||||||
|
|
||||||
// add the directories to the path
|
|
||||||
await Promise.all(dirs.map((dir) => addPath(dir)))
|
|
||||||
|
|
||||||
return dirs
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ import { info } from "@actions/core"
|
||||||
import { addPythonBaseExecPrefix, setupPythonAndPip } from "../../python/python"
|
import { addPythonBaseExecPrefix, setupPythonAndPip } from "../../python/python"
|
||||||
import { InstallationInfo } from "./setupBin"
|
import { InstallationInfo } from "./setupBin"
|
||||||
import { existsSync } from "fs"
|
import { existsSync } from "fs"
|
||||||
import { addExeExt, join } from "patha"
|
import { addExeExt, dirname, join } from "patha"
|
||||||
|
import { addPath } from "../env/addEnv"
|
||||||
|
import which from "which"
|
||||||
|
|
||||||
let python: string | undefined
|
let python: string | undefined
|
||||||
let binDirs: string[] | undefined
|
let binDirs: string[] | undefined
|
||||||
|
@ -25,7 +27,23 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
|
||||||
binDirs = await addPythonBaseExecPrefix(python)
|
binDirs = await addPythonBaseExecPrefix(python)
|
||||||
}
|
}
|
||||||
|
|
||||||
const binDir = binDirs.find((dir) => existsSync(join(dir, addExeExt(name)))) ?? binDirs.pop()!
|
const binDir = findBinDir(binDirs, name)
|
||||||
|
|
||||||
|
await addPath(binDir)
|
||||||
|
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findBinDir(dirs: string[], name: string) {
|
||||||
|
const foundDir = dirs.find((dir) => existsSync(join(dir, addExeExt(name))))
|
||||||
|
if (foundDir !== undefined) {
|
||||||
|
return foundDir
|
||||||
|
}
|
||||||
|
|
||||||
|
const whichDir = which.sync(addExeExt(name), { nothrow: true })
|
||||||
|
if (whichDir !== null) {
|
||||||
|
return dirname(whichDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dirs[dirs.length - 1]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export function unique(dirs: string[]) {
|
||||||
|
return [...new Set(dirs)]
|
||||||
|
}
|
Loading…
Reference in New Issue