mirror of https://github.com/aminya/setup-cpp
Merge pull request #148 from aminya/flags-quote [skip ci]
This commit is contained in:
commit
7220394b68
|
@ -19,7 +19,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
|
|||
| compiler and analyzer | llvm, gcc, msvc, vcvarsall, cppcheck, clangtidy, clangformat |
|
||||
| build system | cmake, ninja, meson, make, task, bazel |
|
||||
| package manager | vcpkg, conan, choco, brew, nala |
|
||||
| cache | cppcache |
|
||||
| cache | cppcache, sccache |
|
||||
| documentation | doxygen, graphviz |
|
||||
| coverage | gcovr, opencppcoverage, kcov |
|
||||
| other | python, powershell, sevenzip |
|
||||
|
|
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
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
|
@ -58,6 +58,7 @@
|
|||
"admina": "^0.1.3",
|
||||
"ci-log": "workspace:1.0.0",
|
||||
"escape-path-with-spaces": "github:aminya/escape-path-with-spaces#d9f81ee649203ddc55783a2f96ada59df06118e3",
|
||||
"escape-quotes": "^1.0.2",
|
||||
"exec-powershell": "workspace:1.0.0",
|
||||
"execa": "^5.1.1",
|
||||
"is-url-online": "^1.5.0",
|
||||
|
@ -65,6 +66,7 @@
|
|||
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
|
||||
"numerous": "1.0.3",
|
||||
"patha": "^0.4.1",
|
||||
"quote-unquote": "^1.0.0",
|
||||
"semver": "7.3.8",
|
||||
"setup-python": "github:actions/setup-python#v4.3.0",
|
||||
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { isSudo, execRootSync } from "admina"
|
||||
import { statSync } from "fs"
|
||||
|
||||
/**
|
||||
* Give the user access to the given path and its sub-directories. It changes the owner to the SUDO_USER. This allows
|
||||
* the user to use the folder without sudo
|
||||
* Give the user access to the given path (and its sub-directories if a directory). It changes the owner to the
|
||||
* SUDO_USER. This allows the user to use the folder without sudo
|
||||
*
|
||||
* @param path The path to give the user access to
|
||||
*/
|
||||
|
@ -12,6 +13,11 @@ export function giveUserAccess(path: string) {
|
|||
isSudo() &&
|
||||
process.env.SUDO_USER !== undefined
|
||||
) {
|
||||
execRootSync("chown", ["-R", process.env.SUDO_USER, path], { cwd: path, stdio: "inherit", shell: true })
|
||||
const isDirectory = statSync(path).isDirectory()
|
||||
execRootSync("chown", [...(isDirectory ? ["-R"] : []), process.env.SUDO_USER, path], {
|
||||
cwd: path,
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ importers:
|
|||
cross-spawn: ^7.0.3
|
||||
cspell: ^6.14.3
|
||||
escape-path-with-spaces: github:aminya/escape-path-with-spaces#d9f81ee649203ddc55783a2f96ada59df06118e3
|
||||
escape-quotes: ^1.0.2
|
||||
eslint: ^8.28.0
|
||||
eslint-config-atomic: ^1.18.1
|
||||
exec-powershell: workspace:1.0.0
|
||||
|
@ -46,6 +47,7 @@ importers:
|
|||
patha: ^0.4.1
|
||||
prettier: 2.7.1
|
||||
prettier-config-atomic: ^3.1.0
|
||||
quote-unquote: ^1.0.0
|
||||
readme-md-generator: ^1.0.0
|
||||
semver: 7.3.8
|
||||
setup-python: github:actions/setup-python#v4.3.0
|
||||
|
@ -69,6 +71,7 @@ importers:
|
|||
admina: 0.1.3
|
||||
ci-log: link:packages/ci-log
|
||||
escape-path-with-spaces: github.com/aminya/escape-path-with-spaces/d9f81ee649203ddc55783a2f96ada59df06118e3
|
||||
escape-quotes: 1.0.2
|
||||
exec-powershell: link:packages/exec-powershell
|
||||
execa: 5.1.1
|
||||
is-url-online: 1.5.0
|
||||
|
@ -76,6 +79,7 @@ importers:
|
|||
msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1
|
||||
numerous: 1.0.3
|
||||
patha: 0.4.1
|
||||
quote-unquote: 1.0.0
|
||||
semver: 7.3.8
|
||||
setup-python: github.com/actions/setup-python/13ae5bb136fac2878aff31522b9efb785519f984
|
||||
time-delta: github.com/aminya/time-delta/69d91a41cef28e569be9a2991129f5f7d1f0d00e
|
||||
|
@ -4202,10 +4206,15 @@ packages:
|
|||
engines: {node: '>=12'}
|
||||
dev: true
|
||||
|
||||
/escape-quotes/1.0.2:
|
||||
resolution: {integrity: sha512-JpLFzklNReeakCpyj59s78P5F72q0ZUpDnp2BuIk9TtTjj2HMsgiWBChw17BlZT8dRhMtmSb1jE2+pTP1iFYyw==}
|
||||
dependencies:
|
||||
escape-string-regexp: 1.0.5
|
||||
dev: false
|
||||
|
||||
/escape-string-regexp/1.0.5:
|
||||
resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==}
|
||||
engines: {node: '>=0.8.0'}
|
||||
dev: true
|
||||
|
||||
/escape-string-regexp/2.0.0:
|
||||
resolution: {integrity: sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==}
|
||||
|
@ -8100,6 +8109,10 @@ packages:
|
|||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/quote-unquote/1.0.0:
|
||||
resolution: {integrity: sha512-twwRO/ilhlG/FIgYeKGFqyHhoEhqgnKVkcmqMKi2r524gz3ZbDTcyFt38E9xjJI2vT+KbRNHVbnJ/e0I25Azwg==}
|
||||
dev: false
|
||||
|
||||
/rc-config-loader/4.1.1:
|
||||
resolution: {integrity: sha512-S10o85x/szboh7FOxUyU+KuED+gr9V7SEnUBOzSn+vd1K8J2MtkP1RCPWg8Sw5kkuZKr7976bFzacCM6QtAApQ==}
|
||||
dependencies:
|
||||
|
|
|
@ -60,7 +60,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
}
|
||||
case "linux": {
|
||||
let installationInfo: InstallationInfo
|
||||
if (version === "" || version === undefined || isArch() || hasDnf()) {
|
||||
if (version === "" || isArch() || hasDnf()) {
|
||||
if (isArch()) {
|
||||
installationInfo = setupPacmanPack("doxygen", version)
|
||||
} else if (hasDnf()) {
|
||||
|
|
|
@ -39,7 +39,7 @@ import { setupVcpkg } from "./vcpkg/vcpkg"
|
|||
import { join } from "patha"
|
||||
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
|
||||
import { setupKcov } from "./kcov/kcov"
|
||||
import { addEnv } from "./utils/env/addEnv"
|
||||
import { addEnv, finalizeCpprc } from "./utils/env/addEnv"
|
||||
import { setupSevenZip } from "./sevenzip/sevenzip"
|
||||
import { setupGraphviz } from "./graphviz/graphviz"
|
||||
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"}`)
|
||||
}
|
||||
|
||||
finalizeCpprc()
|
||||
|
||||
if (successMessages.length === 0 && errorMessages.length === 0) {
|
||||
warning("setup_cpp was called without any arguments. Nothing to do.")
|
||||
return 0
|
||||
|
|
|
@ -6,7 +6,7 @@ import ciDetect from "@npmcli/ci-detect"
|
|||
jest.setTimeout(300000)
|
||||
describe("setup-powershell", () => {
|
||||
it("should setup powershell", async () => {
|
||||
if (process.platform === "win32" && ciDetect() == "github-actions") {
|
||||
if (process.platform === "win32" && ciDetect() === "github-actions") {
|
||||
// results in errors
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { exportVariable, addPath as ghAddPath, info, setFailed } from "@actions/core"
|
||||
import ciDetect from "@npmcli/ci-detect"
|
||||
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 { execPowershell } from "exec-powershell"
|
||||
import { delimiter } from "path"
|
||||
import escapeSpace from "escape-path-with-spaces"
|
||||
import { giveUserAccess } from "user-access"
|
||||
import escapeQuote from "escape-quotes"
|
||||
|
||||
/**
|
||||
* Add an environment variable.
|
||||
|
@ -14,7 +15,7 @@ import { giveUserAccess } from "user-access"
|
|||
* This function is cross-platforms and works in all the local or CI systems.
|
||||
*/
|
||||
export async function addEnv(name: string, valGiven: string | undefined, shouldEscapeSpace: boolean = false) {
|
||||
const val = shouldEscapeSpace ? escapeSpace(valGiven ?? "") : valGiven
|
||||
const val = escapeString(valGiven ?? "", shouldEscapeSpace)
|
||||
try {
|
||||
if (ciDetect() === "github-actions") {
|
||||
try {
|
||||
|
@ -32,6 +33,11 @@ export async function addEnv(name: string, valGiven: string | undefined, shouldE
|
|||
}
|
||||
}
|
||||
|
||||
function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
|
||||
const spaceEscaped = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
|
||||
return escapeQuote(spaceEscaped, '"', "\\")
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path to the PATH environment variable.
|
||||
*
|
||||
|
@ -113,7 +119,7 @@ export function setupCppInProfile() {
|
|||
}
|
||||
|
||||
// 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)) {
|
||||
const cpprc_content = readFileSync(cpprc_path, "utf8")
|
||||
|
@ -126,8 +132,6 @@ export function setupCppInProfile() {
|
|||
appendFileSync(cpprc_path, `\n${source_cpprc_str}\n`)
|
||||
info(`Added ${source_cpprc_str} to ${cpprc_path}`)
|
||||
|
||||
giveUserAccess(cpprc_path)
|
||||
|
||||
// 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`
|
||||
|
@ -148,3 +152,19 @@ export function setupCppInProfile() {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
/** Escape `'` with `\\` */
|
||||
declare function escapeQuote(input: string): string
|
||||
/** Escape the given character with the given escape character */
|
||||
declare function escapeQuote(input: string, character: string, escape_character: string): string
|
||||
|
||||
declare module "escape-quotes" {
|
||||
export = escapeQuote
|
||||
}
|
Loading…
Reference in New Issue