mirror of https://github.com/aminya/setup-cpp.git
Merge pull request #397 from aminya/bashrc-loop [skip ci]
fix: avoid rc sourcing loops + fix: always add guards for sourcing rc files
This commit is contained in:
commit
5ea110ae8d
|
|
@ -86,7 +86,7 @@ jobs:
|
|||
matrix:
|
||||
os:
|
||||
- windows-2019
|
||||
- ubuntu-20.04
|
||||
- ubuntu-22.04
|
||||
- ubuntu-22.04-arm
|
||||
- macos-13 # x64
|
||||
- macos-14 # arm64
|
||||
|
|
@ -163,7 +163,7 @@ jobs:
|
|||
- ubuntu-24.04
|
||||
- ubuntu-22.04-arm
|
||||
- ubuntu-22.04
|
||||
- ubuntu-20.04
|
||||
# - ubuntu-20.04
|
||||
- macos-15 # arm64
|
||||
# - macos-15-large # x64
|
||||
- macos-14 # arm64
|
||||
|
|
|
|||
|
|
@ -30,10 +30,9 @@ words:
|
|||
- choco
|
||||
- clangd
|
||||
- cmake
|
||||
- cmakeformat
|
||||
- cmakelang
|
||||
- cmakelint
|
||||
- llvmorg
|
||||
- cmakeformat
|
||||
- cobertura
|
||||
- copr
|
||||
- CPATH
|
||||
|
|
@ -51,6 +50,7 @@ words:
|
|||
- dyld
|
||||
- eabi
|
||||
- envosman
|
||||
- envosmanrc
|
||||
- esac
|
||||
- esbuild
|
||||
- esmodule
|
||||
|
|
@ -75,6 +75,7 @@ words:
|
|||
- libstdc
|
||||
- libtinfo
|
||||
- liuli
|
||||
- llvmorg
|
||||
- mdimporterdir
|
||||
- memoizee
|
||||
- mkdirp
|
||||
|
|
|
|||
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
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "envosman",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"description": "Manage environment variables, PATH, and rc files",
|
||||
"repository": "https://github.com/aminya/setup-cpp",
|
||||
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/envosman",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { promises } from "fs"
|
||||
import { resolve } from "path"
|
||||
import { grantUserWriteAccess } from "admina"
|
||||
import { info, warning } from "ci-log"
|
||||
import memoize from "memoizee"
|
||||
|
|
@ -6,29 +7,40 @@ import { pathExists } from "path-exists"
|
|||
import { untildifyUser } from "untildify-user"
|
||||
const { appendFile, readFile, writeFile } = promises
|
||||
|
||||
export const defaultRcPath = untildifyUser("~/.bashrc")
|
||||
export const defaultGuard = "envosman"
|
||||
export const defaultRcPath = untildifyUser("~/.envosmanrc")
|
||||
|
||||
/**
|
||||
* Options for adding an rc file
|
||||
*/
|
||||
export type RcOptions = {
|
||||
/** The path to the RC file that the env variables should be added to. */
|
||||
/** The path to the RC file that the env variables should be added to. (Default to "~/.envosmanrc") */
|
||||
rcPath: string
|
||||
|
||||
/** Provide a name (your tool) to add a variable guard for sourcing your rc file */
|
||||
/** Provide a name (your tool) to add a variable guard for sourcing your rc file (Default to "envosman") */
|
||||
guard?: string
|
||||
}
|
||||
|
||||
async function sourceRCInRc_(options: RcOptions) {
|
||||
const sourceRcString = options.guard === undefined
|
||||
? `\nsource "${options.rcPath}"\n`
|
||||
: `\n# ${options.guard}\nif [[ "$SOURCE_${options.guard.toUpperCase()}RC" != 0 && -f "${options.rcPath}" ]]; then source "${options.rcPath}"; fi\n`
|
||||
const bashrc = untildifyUser("~/.bashrc")
|
||||
const profile = untildifyUser("~/.profile")
|
||||
|
||||
const rcPath = resolve(options.rcPath)
|
||||
|
||||
// avoid source loops
|
||||
if (rcPath === bashrc || rcPath === profile) {
|
||||
return
|
||||
}
|
||||
|
||||
const guard = options.guard ?? defaultGuard
|
||||
const sourceRcString =
|
||||
`\n# ${guard}\nif [[ "$SOURCE_${guard.toUpperCase()}RC" != 0 && -f "${rcPath}" ]]; then source "${rcPath}"; fi\n`
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
addRCHeader(options),
|
||||
addSourceToTargetRc(sourceRcString, untildifyUser("~/.bashrc")),
|
||||
addSourceToTargetRc(sourceRcString, untildifyUser("~/.profile")),
|
||||
addSourceToTargetRc(sourceRcString, bashrc),
|
||||
addSourceToTargetRc(sourceRcString, profile),
|
||||
])
|
||||
} catch (err) {
|
||||
warning(`Failed to add ${sourceRcString} to .profile or .bashrc. You should add it manually: ${err}`)
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ export async function setupVcpkg(version: string, setupDir: string, arch: string
|
|||
|
||||
// Add VCPKG_FORCE_SYSTEM_BINARIES=1 for Linux arm64
|
||||
if (process.platform === "linux" && arm64.includes(arch)) {
|
||||
await addEnv("VCPKG_FORCE_SYSTEM_BINARIES", "1")
|
||||
await addEnv("VCPKG_FORCE_SYSTEM_BINARIES", "1", rcOptions)
|
||||
}
|
||||
|
||||
// bootstrap vcpkg
|
||||
|
|
|
|||
Loading…
Reference in New Issue