Skip to content

Commit

Permalink
Merge pull request #13 from aminya/linux-init [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Jan 19, 2022
2 parents ba55ef6 + f83c7d7 commit 9366f7a
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 16 deletions.
4 changes: 2 additions & 2 deletions building/docker/debian.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ WORKDIR "/"
RUN apt-get update -qq
RUN apt-get install -y --no-install-recommends apt-utils
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

# 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
CMD source ~/.profile
Expand Down
2 changes: 1 addition & 1 deletion building/docker/debian_node.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ADD "./dist/" "/"
WORKDIR "/"

# 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
CMD source ~/.profile
Expand Down
2 changes: 1 addition & 1 deletion building/docker/debian_node_slim.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apt-get update -qq
RUN apt-get install -y --no-install-recommends unzip

# 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
CMD source ~/.profile
Expand Down
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/kcov/kcov.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import execa from "execa"
// import { join } from "path"
// import untildify from "untildify"
// import { untildify_user as untildify } from "./utils/path/untildify"
// import { setupCmake } from "../cmake/cmake"
import { execaSudo } from "../utils/env/sudo"
import { addBinExtension } from "../utils/extension/extension"
Expand Down Expand Up @@ -33,7 +33,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
extractFunction: async (file: string, dest: string): Promise<string> => {
const out = await extractTarByExe(file, dest)
// 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("libcurl4-openssl-dev")
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { setupNinja } from "./ninja/ninja"
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
import { setupPython } from "./python/python"
import mri from "mri"
import untildify from "untildify"
import { untildify_user as untildify } from "./utils/path/untildify"
import { isGitHubCI } from "./utils/env/isci"

import semverValid from "semver/functions/valid"
Expand Down Expand Up @@ -101,7 +101,7 @@ export async function main(args: string[]): Promise<number> {
const arch = opts.architecture ?? process.arch

// 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
const successMessages: string[] = []
Expand Down
14 changes: 11 additions & 3 deletions src/utils/env/addEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { exportVariable } from "@actions/core"
import * as core from "@actions/core"
import execa from "execa"
import { isGitHubCI } from "./isci"
import untildify from "untildify"
import { untildify_user as untildify } from "../path/untildify"
import { appendFileSync } from "fs"
import { join } from "path"
import { isRoot } from "./sudo"

/** An add path function that works locally or inside GitHub Actions */
export function addEnv(name: string, val: string | undefined) {
Expand Down Expand Up @@ -33,8 +35,14 @@ function addEnvSystem(name: string, val: string | undefined) {
}
case "linux":
case "darwin": {
const profile_path = untildify("~/.profile")
appendFileSync(profile_path, `\nexport ${name}="${val}\n`)
// find profile path
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}"`)
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/path/addPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { delimiter } from "path"
import * as core from "@actions/core"
import execa from "execa"
import { isGitHubCI } from "../env/isci"
import untildify from "untildify"
import { untildify_user as untildify } from "./untildify"
import { appendFileSync } from "fs"

/** An add path function that works locally or inside GitHub Actions */
Expand Down Expand Up @@ -34,7 +34,7 @@ function addPathSystem(path: string) {
}
case "linux":
case "darwin": {
const profile_path = untildify("~/.profile")
const profile_path = untildify(".profile")
appendFileSync(profile_path, `\nexport PATH=${path}:$PATH\n`)
core.info(`${path} was added to "${profile_path}"`)
return
Expand Down
12 changes: 12 additions & 0 deletions src/utils/path/untildify.ts
Original file line number Diff line number Diff line change
@@ -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}`)
}
}
9 changes: 9 additions & 0 deletions src/utils/setup/setupBin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { join } from "path"
import { existsSync } from "fs"
import { tmpdir } from "os"
import { isGitHubCI } from "../env/isci"
import { setupAptPack } from "./setupAptPack"

/** A type that describes a package */
export type PackageInfo = {
Expand Down Expand Up @@ -76,6 +77,14 @@ export async function setupBin(
// download ane extract the package into the installation directory.
if (!existsSync(binDir) || !existsSync(binFile)) {
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)
await extractFunction?.(downloaded, setupDir)
}
Expand Down
13 changes: 12 additions & 1 deletion src/vcpkg/vcpkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ import { existsSync } from "fs"
import { dirname, join } from "path"
import which from "which"
import { addShellExtension, addShellHere } from "../utils/extension/extension"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { InstallationInfo } from "../utils/setup/setupBin"

let hasVCPKG = false

// 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 (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) {
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
} else {
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 })
addPath(setupDir)
// eslint-disable-next-line require-atomic-updates
hasVCPKG = true
return { binDir: setupDir }
}
Expand Down

0 comments on commit 9366f7a

Please sign in to comment.