mirror of https://github.com/aminya/setup-cpp
feat: de-duplicate cpprc
This commit is contained in:
parent
ea23ed92ca
commit
d20e347c91
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
|
@ -39,7 +39,7 @@ import { setupVcpkg } from "./vcpkg/vcpkg"
|
||||||
import { join } from "patha"
|
import { join } from "patha"
|
||||||
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
|
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
|
||||||
import { setupKcov } from "./kcov/kcov"
|
import { setupKcov } from "./kcov/kcov"
|
||||||
import { addEnv } from "./utils/env/addEnv"
|
import { addEnv, finalizeCpprc } from "./utils/env/addEnv"
|
||||||
import { setupSevenZip } from "./sevenzip/sevenzip"
|
import { setupSevenZip } from "./sevenzip/sevenzip"
|
||||||
import { setupGraphviz } from "./graphviz/graphviz"
|
import { setupGraphviz } from "./graphviz/graphviz"
|
||||||
import { setupNala } from "./nala/nala"
|
import { setupNala } from "./nala/nala"
|
||||||
|
@ -270,6 +270,8 @@ export async function main(args: string[]): Promise<number> {
|
||||||
info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
|
info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finalizeCpprc()
|
||||||
|
|
||||||
if (successMessages.length === 0 && errorMessages.length === 0) {
|
if (successMessages.length === 0 && errorMessages.length === 0) {
|
||||||
warning("setup_cpp was called without any arguments. Nothing to do.")
|
warning("setup_cpp was called without any arguments. Nothing to do.")
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { exportVariable, addPath as ghAddPath, info, setFailed } from "@actions/core"
|
import { exportVariable, addPath as ghAddPath, info, setFailed } from "@actions/core"
|
||||||
import ciDetect from "@npmcli/ci-detect"
|
import ciDetect from "@npmcli/ci-detect"
|
||||||
import { untildifyUser } from "untildify-user"
|
import { untildifyUser } from "untildify-user"
|
||||||
import { appendFileSync, existsSync, readFileSync } from "fs"
|
import { appendFileSync, existsSync, readFileSync, writeFileSync } from "fs"
|
||||||
import { error, warning } from "ci-log"
|
import { error, warning } from "ci-log"
|
||||||
import { execPowershell } from "exec-powershell"
|
import { execPowershell } from "exec-powershell"
|
||||||
import { delimiter } from "path"
|
import { delimiter } from "path"
|
||||||
|
@ -119,7 +119,7 @@ export function setupCppInProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// a variable that prevents source_cpprc from being called from .bashrc and .profile
|
// a variable that prevents source_cpprc from being called from .bashrc and .profile
|
||||||
const source_cpprc_str = "export SOURCE_CPPRC=0"
|
const source_cpprc_str = "# Automatically Generated by setup-cpp\nexport SOURCE_CPPRC=0"
|
||||||
|
|
||||||
if (existsSync(cpprc_path)) {
|
if (existsSync(cpprc_path)) {
|
||||||
const cpprc_content = readFileSync(cpprc_path, "utf8")
|
const cpprc_content = readFileSync(cpprc_path, "utf8")
|
||||||
|
@ -132,8 +132,6 @@ export function setupCppInProfile() {
|
||||||
appendFileSync(cpprc_path, `\n${source_cpprc_str}\n`)
|
appendFileSync(cpprc_path, `\n${source_cpprc_str}\n`)
|
||||||
info(`Added ${source_cpprc_str} to ${cpprc_path}`)
|
info(`Added ${source_cpprc_str} to ${cpprc_path}`)
|
||||||
|
|
||||||
giveUserAccess(cpprc_path)
|
|
||||||
|
|
||||||
// source cpprc in bashrc/profile
|
// source cpprc in bashrc/profile
|
||||||
|
|
||||||
const source_cpprc_string = `\n# source .cpprc if SOURCE_CPPRC is not set to 0\nif [[ "$SOURCE_CPPRC" != 0 && -f "${cpprc_path}" ]]; then source "${cpprc_path}"; fi\n`
|
const source_cpprc_string = `\n# source .cpprc if SOURCE_CPPRC is not set to 0\nif [[ "$SOURCE_CPPRC" != 0 && -f "${cpprc_path}" ]]; then source "${cpprc_path}"; fi\n`
|
||||||
|
@ -154,3 +152,19 @@ export function setupCppInProfile() {
|
||||||
|
|
||||||
setupCppInProfile_called = true
|
setupCppInProfile_called = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function finalizeCpprc() {
|
||||||
|
if (existsSync(cpprc_path)) {
|
||||||
|
const entries = readFileSync(cpprc_path, "utf-8").split("\n")
|
||||||
|
|
||||||
|
const unique_entries = [...new Set(entries.reverse())].reverse() // remove duplicates, keeping the latest entry
|
||||||
|
|
||||||
|
writeFileSync(cpprc_path, unique_entries.join("\n"))
|
||||||
|
|
||||||
|
try {
|
||||||
|
giveUserAccess(cpprc_path)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue