Skip to content

Commit 5ea110a

Browse files
authored
Merge pull request #397 from aminya/bashrc-loop [skip ci]
fix: avoid rc sourcing loops + fix: always add guards for sourcing rc files
2 parents 05bd2b5 + 9bc8921 commit 5ea110a

File tree

9 files changed

+31
-18
lines changed

9 files changed

+31
-18
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
matrix:
8787
os:
8888
- windows-2019
89-
- ubuntu-20.04
89+
- ubuntu-22.04
9090
- ubuntu-22.04-arm
9191
- macos-13 # x64
9292
- macos-14 # arm64
@@ -163,7 +163,7 @@ jobs:
163163
- ubuntu-24.04
164164
- ubuntu-22.04-arm
165165
- ubuntu-22.04
166-
- ubuntu-20.04
166+
# - ubuntu-20.04
167167
- macos-15 # arm64
168168
# - macos-15-large # x64
169169
- macos-14 # arm64

cspell.config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ words:
3030
- choco
3131
- clangd
3232
- cmake
33+
- cmakeformat
3334
- cmakelang
3435
- cmakelint
35-
- llvmorg
36-
- cmakeformat
3736
- cobertura
3837
- copr
3938
- CPATH
@@ -51,6 +50,7 @@ words:
5150
- dyld
5251
- eabi
5352
- envosman
53+
- envosmanrc
5454
- esac
5555
- esbuild
5656
- esmodule
@@ -75,6 +75,7 @@ words:
7575
- libstdc
7676
- libtinfo
7777
- liuli
78+
- llvmorg
7879
- mdimporterdir
7980
- memoizee
8081
- mkdirp

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/envosman/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "envosman",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Manage environment variables, PATH, and rc files",
55
"repository": "https://github.com/aminya/setup-cpp",
66
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/envosman",

packages/envosman/src/rc-file.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
import { promises } from "fs"
2+
import { resolve } from "path"
23
import { grantUserWriteAccess } from "admina"
34
import { info, warning } from "ci-log"
45
import memoize from "memoizee"
56
import { pathExists } from "path-exists"
67
import { untildifyUser } from "untildify-user"
78
const { appendFile, readFile, writeFile } = promises
89

9-
export const defaultRcPath = untildifyUser("~/.bashrc")
10+
export const defaultGuard = "envosman"
11+
export const defaultRcPath = untildifyUser("~/.envosmanrc")
1012

1113
/**
1214
* Options for adding an rc file
1315
*/
1416
export type RcOptions = {
15-
/** The path to the RC file that the env variables should be added to. */
17+
/** The path to the RC file that the env variables should be added to. (Default to "~/.envosmanrc") */
1618
rcPath: string
1719

18-
/** Provide a name (your tool) to add a variable guard for sourcing your rc file */
20+
/** Provide a name (your tool) to add a variable guard for sourcing your rc file (Default to "envosman") */
1921
guard?: string
2022
}
2123

2224
async function sourceRCInRc_(options: RcOptions) {
23-
const sourceRcString = options.guard === undefined
24-
? `\nsource "${options.rcPath}"\n`
25-
: `\n# ${options.guard}\nif [[ "$SOURCE_${options.guard.toUpperCase()}RC" != 0 && -f "${options.rcPath}" ]]; then source "${options.rcPath}"; fi\n`
25+
const bashrc = untildifyUser("~/.bashrc")
26+
const profile = untildifyUser("~/.profile")
27+
28+
const rcPath = resolve(options.rcPath)
29+
30+
// avoid source loops
31+
if (rcPath === bashrc || rcPath === profile) {
32+
return
33+
}
34+
35+
const guard = options.guard ?? defaultGuard
36+
const sourceRcString =
37+
`\n# ${guard}\nif [[ "$SOURCE_${guard.toUpperCase()}RC" != 0 && -f "${rcPath}" ]]; then source "${rcPath}"; fi\n`
2638

2739
try {
2840
await Promise.all([
2941
addRCHeader(options),
30-
addSourceToTargetRc(sourceRcString, untildifyUser("~/.bashrc")),
31-
addSourceToTargetRc(sourceRcString, untildifyUser("~/.profile")),
42+
addSourceToTargetRc(sourceRcString, bashrc),
43+
addSourceToTargetRc(sourceRcString, profile),
3244
])
3345
} catch (err) {
3446
warning(`Failed to add ${sourceRcString} to .profile or .bashrc. You should add it manually: ${err}`)

src/vcpkg/vcpkg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function setupVcpkg(version: string, setupDir: string, arch: string
8888

8989
// Add VCPKG_FORCE_SYSTEM_BINARIES=1 for Linux arm64
9090
if (process.platform === "linux" && arm64.includes(arch)) {
91-
await addEnv("VCPKG_FORCE_SYSTEM_BINARIES", "1")
91+
await addEnv("VCPKG_FORCE_SYSTEM_BINARIES", "1", rcOptions)
9292
}
9393

9494
// bootstrap vcpkg

0 commit comments

Comments
 (0)