mirror of https://github.com/aminya/setup-cpp
Merge pull request #13 from aminya/linux-init [skip ci]
This commit is contained in:
commit
9366f7ab1c
|
@ -6,11 +6,11 @@ WORKDIR "/"
|
||||||
RUN apt-get update -qq
|
RUN apt-get update -qq
|
||||||
RUN apt-get install -y --no-install-recommends apt-utils
|
RUN apt-get install -y --no-install-recommends apt-utils
|
||||||
RUN apt-get install -y --no-install-recommends ca-certificates wget unzip
|
RUN apt-get install -y --no-install-recommends ca-certificates wget unzip
|
||||||
RUN wget --no-verbose "https://github.com/aminya/setup-cpp/releases/download/v0.5.2/setup_cpp_linux"
|
RUN wget --no-verbose "https://github.com/aminya/setup-cpp/releases/download/v0.5.4/setup_cpp_linux"
|
||||||
RUN chmod +x ./setup_cpp_linux
|
RUN chmod +x ./setup_cpp_linux
|
||||||
|
|
||||||
# install llvm, cmake, ninja, and ccache
|
# install llvm, cmake, ninja, and ccache
|
||||||
RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true
|
RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
|
||||||
|
|
||||||
# reload the environment
|
# reload the environment
|
||||||
CMD source ~/.profile
|
CMD source ~/.profile
|
||||||
|
|
|
@ -6,7 +6,7 @@ ADD "./dist/" "/"
|
||||||
WORKDIR "/"
|
WORKDIR "/"
|
||||||
|
|
||||||
# run installation
|
# run installation
|
||||||
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true
|
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
|
||||||
|
|
||||||
# reload the environment
|
# reload the environment
|
||||||
CMD source ~/.profile
|
CMD source ~/.profile
|
||||||
|
|
|
@ -10,7 +10,7 @@ RUN apt-get update -qq
|
||||||
RUN apt-get install -y --no-install-recommends unzip
|
RUN apt-get install -y --no-install-recommends unzip
|
||||||
|
|
||||||
# run installation
|
# run installation
|
||||||
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --conan true
|
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --conan true --vcpkg true
|
||||||
|
|
||||||
# reload the environment
|
# reload the environment
|
||||||
CMD source ~/.profile
|
CMD source ~/.profile
|
||||||
|
|
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 @@
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
// import { join } from "path"
|
// import { join } from "path"
|
||||||
// import untildify from "untildify"
|
// import { untildify_user as untildify } from "./utils/path/untildify"
|
||||||
// import { setupCmake } from "../cmake/cmake"
|
// import { setupCmake } from "../cmake/cmake"
|
||||||
import { execaSudo } from "../utils/env/sudo"
|
import { execaSudo } from "../utils/env/sudo"
|
||||||
import { addBinExtension } from "../utils/extension/extension"
|
import { addBinExtension } from "../utils/extension/extension"
|
||||||
|
@ -33,7 +33,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
|
||||||
extractFunction: async (file: string, dest: string): Promise<string> => {
|
extractFunction: async (file: string, dest: string): Promise<string> => {
|
||||||
const out = await extractTarByExe(file, dest)
|
const out = await extractTarByExe(file, dest)
|
||||||
// build after extraction using CMake
|
// build after extraction using CMake
|
||||||
// await setupCmake("3.22.0", join(untildify("~/"), "cmake"), "")
|
// await setupCmake("3.22.0", join(untildify(""), "cmake"), "")
|
||||||
await setupAptPack("libdw-dev")
|
await setupAptPack("libdw-dev")
|
||||||
await setupAptPack("libcurl4-openssl-dev")
|
await setupAptPack("libcurl4-openssl-dev")
|
||||||
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })
|
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { setupNinja } from "./ninja/ninja"
|
||||||
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
|
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
|
||||||
import { setupPython } from "./python/python"
|
import { setupPython } from "./python/python"
|
||||||
import mri from "mri"
|
import mri from "mri"
|
||||||
import untildify from "untildify"
|
import { untildify_user as untildify } from "./utils/path/untildify"
|
||||||
import { isGitHubCI } from "./utils/env/isci"
|
import { isGitHubCI } from "./utils/env/isci"
|
||||||
|
|
||||||
import semverValid from "semver/functions/valid"
|
import semverValid from "semver/functions/valid"
|
||||||
|
@ -101,7 +101,7 @@ export async function main(args: string[]): Promise<number> {
|
||||||
const arch = opts.architecture ?? process.arch
|
const arch = opts.architecture ?? process.arch
|
||||||
|
|
||||||
// the installation dir for the tools that are downloaded directly
|
// the installation dir for the tools that are downloaded directly
|
||||||
const setupCppDir = process.env.SETUP_CPP_DIR ?? untildify("~/")
|
const setupCppDir = process.env.SETUP_CPP_DIR ?? untildify("")
|
||||||
|
|
||||||
// report messages
|
// report messages
|
||||||
const successMessages: string[] = []
|
const successMessages: string[] = []
|
||||||
|
|
|
@ -2,8 +2,10 @@ import { exportVariable } from "@actions/core"
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
import { isGitHubCI } from "./isci"
|
import { isGitHubCI } from "./isci"
|
||||||
import untildify from "untildify"
|
import { untildify_user as untildify } from "../path/untildify"
|
||||||
import { appendFileSync } from "fs"
|
import { appendFileSync } from "fs"
|
||||||
|
import { join } from "path"
|
||||||
|
import { isRoot } from "./sudo"
|
||||||
|
|
||||||
/** An add path function that works locally or inside GitHub Actions */
|
/** An add path function that works locally or inside GitHub Actions */
|
||||||
export function addEnv(name: string, val: string | undefined) {
|
export function addEnv(name: string, val: string | undefined) {
|
||||||
|
@ -33,8 +35,14 @@ function addEnvSystem(name: string, val: string | undefined) {
|
||||||
}
|
}
|
||||||
case "linux":
|
case "linux":
|
||||||
case "darwin": {
|
case "darwin": {
|
||||||
const profile_path = untildify("~/.profile")
|
// find profile path
|
||||||
appendFileSync(profile_path, `\nexport ${name}="${val}\n`)
|
let profile_path = untildify(".profile")
|
||||||
|
if (isRoot() && typeof process.env.SUDO_USER === "string") {
|
||||||
|
// use the user profile even if root
|
||||||
|
profile_path = join("/home/", process.env.SUDO_USER, ".profile")
|
||||||
|
}
|
||||||
|
|
||||||
|
appendFileSync(profile_path, `\nexport ${name}="${val}"\n`)
|
||||||
core.info(`${name}="${val} was added to "${profile_path}"`)
|
core.info(`${name}="${val} was added to "${profile_path}"`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { delimiter } from "path"
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
import { isGitHubCI } from "../env/isci"
|
import { isGitHubCI } from "../env/isci"
|
||||||
import untildify from "untildify"
|
import { untildify_user as untildify } from "./untildify"
|
||||||
import { appendFileSync } from "fs"
|
import { appendFileSync } from "fs"
|
||||||
|
|
||||||
/** An add path function that works locally or inside GitHub Actions */
|
/** An add path function that works locally or inside GitHub Actions */
|
||||||
|
@ -34,7 +34,7 @@ function addPathSystem(path: string) {
|
||||||
}
|
}
|
||||||
case "linux":
|
case "linux":
|
||||||
case "darwin": {
|
case "darwin": {
|
||||||
const profile_path = untildify("~/.profile")
|
const profile_path = untildify(".profile")
|
||||||
appendFileSync(profile_path, `\nexport PATH=${path}:$PATH\n`)
|
appendFileSync(profile_path, `\nexport PATH=${path}:$PATH\n`)
|
||||||
core.info(`${path} was added to "${profile_path}"`)
|
core.info(`${path} was added to "${profile_path}"`)
|
||||||
return
|
return
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { join } from "path"
|
||||||
|
import untildify from "untildify"
|
||||||
|
import { isRoot } from "../env/sudo"
|
||||||
|
|
||||||
|
export function untildify_user(path: string) {
|
||||||
|
if (isRoot() && typeof process.env.SUDO_USER === "string") {
|
||||||
|
// use the user profile even if root
|
||||||
|
return join("/home/", process.env.SUDO_USER, path)
|
||||||
|
} else {
|
||||||
|
return untildify(`~/${path}`)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import { join } from "path"
|
||||||
import { existsSync } from "fs"
|
import { existsSync } from "fs"
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
import { isGitHubCI } from "../env/isci"
|
import { isGitHubCI } from "../env/isci"
|
||||||
|
import { setupAptPack } from "./setupAptPack"
|
||||||
|
|
||||||
/** A type that describes a package */
|
/** A type that describes a package */
|
||||||
export type PackageInfo = {
|
export type PackageInfo = {
|
||||||
|
@ -76,6 +77,14 @@ export async function setupBin(
|
||||||
// download ane extract the package into the installation directory.
|
// download ane extract the package into the installation directory.
|
||||||
if (!existsSync(binDir) || !existsSync(binFile)) {
|
if (!existsSync(binDir) || !existsSync(binFile)) {
|
||||||
info(`Download and extract ${name} ${version}`)
|
info(`Download and extract ${name} ${version}`)
|
||||||
|
|
||||||
|
if (process.platform === "linux") {
|
||||||
|
// extraction dependencies
|
||||||
|
await setupAptPack("unzip")
|
||||||
|
await setupAptPack("tar")
|
||||||
|
await setupAptPack("xz-utils")
|
||||||
|
}
|
||||||
|
|
||||||
const downloaded = await downloadTool(url)
|
const downloaded = await downloadTool(url)
|
||||||
await extractFunction?.(downloaded, setupDir)
|
await extractFunction?.(downloaded, setupDir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,31 @@ import { existsSync } from "fs"
|
||||||
import { dirname, join } from "path"
|
import { dirname, join } from "path"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { addShellExtension, addShellHere } from "../utils/extension/extension"
|
import { addShellExtension, addShellHere } from "../utils/extension/extension"
|
||||||
|
import { setupAptPack } from "../utils/setup/setupAptPack"
|
||||||
import { InstallationInfo } from "../utils/setup/setupBin"
|
import { InstallationInfo } from "../utils/setup/setupBin"
|
||||||
|
|
||||||
let hasVCPKG = false
|
let hasVCPKG = false
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export function setupVcpkg(_version: string, setupDir: string, _arch: string): InstallationInfo {
|
export async function setupVcpkg(_version: string, setupDir: string, _arch: string): Promise<InstallationInfo> {
|
||||||
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
||||||
if (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) {
|
if (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) {
|
||||||
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
|
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
|
||||||
} else {
|
} else {
|
||||||
warning(`Vcpkg folder already exists at ${setupDir}`)
|
warning(`Vcpkg folder already exists at ${setupDir}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.platform === "linux") {
|
||||||
|
// vcpkg download and extraction dependencies
|
||||||
|
await setupAptPack("curl")
|
||||||
|
await setupAptPack("zip")
|
||||||
|
await setupAptPack("unzip")
|
||||||
|
await setupAptPack("tar")
|
||||||
|
}
|
||||||
|
|
||||||
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true })
|
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true })
|
||||||
addPath(setupDir)
|
addPath(setupDir)
|
||||||
|
// eslint-disable-next-line require-atomic-updates
|
||||||
hasVCPKG = true
|
hasVCPKG = true
|
||||||
return { binDir: setupDir }
|
return { binDir: setupDir }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue