Skip to content

Commit dff4fe8

Browse files
authored
Merge pull request #12 from aminya/exportVariable-System [skip ci]
2 parents 67d09d6 + aa55c63 commit dff4fe8

File tree

13 files changed

+106
-32
lines changed

13 files changed

+106
-32
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,33 @@ An example that installs llvm, cmake, ninja, ccache, and vcpkg:
5151
# windows example (open shell as admin)
5252
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.5.3/setup_cpp_windows.exe"
5353
./setup_cpp_windows --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
54+
55+
RefreshEnv.cmd # reload the environment
5456
```
5557

5658
```ps1
5759
# linux example
5860
wget "https://github.com/aminya/setup-cpp/releases/download/v0.5.3/setup_cpp_linux"
5961
chmod +x setup_cpp_linux
6062
sudo ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
63+
64+
source ~/.profile # reload the environment
6165
```
6266

6367
```ps1
6468
# mac example
6569
wget "https://github.com/aminya/setup-cpp/releases/download/v0.5.3/setup_cpp_mac"
6670
chmod +x setup_cpp_mac
6771
sudo ./setup_cpp_mac --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
72+
73+
source ~/.profile # reload the environment
6874
```
6975

7076
NOTE: In the `compiler` entry, you can specify the version after `-` like `llvm-11.0.0`.
7177
For the tools, instead of `true` that chooses the default version, you can pass a specific version.
7278

79+
NOTE: you will not need `sudo` if you are already a root user (e.g., in a GitLab runner).
80+
7381
### With Nodejs
7482

7583
Download the `setup_cpp.js` file form [here](https://github.com/aminya/setup-cpp/releases/download/v0.5.3/setup_cpp.js), and run it with the available options.
@@ -82,13 +90,17 @@ Open the shell as admin, download via `curl`, then install
8290
# open shell as admin
8391
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.5.3/setup_cpp.js"
8492
node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
93+
94+
RefreshEnv.cmd # reload the environment
8595
```
8696

8797
On Linux or Mac:
8898

8999
```ps1
90100
wget "https://github.com/aminya/setup-cpp/releases/download/v0.5.3/setup_cpp.js"
91101
sudo node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
102+
103+
source ~/.profile # reload the environment
92104
```
93105

94106
# Inside GitHub Actions
@@ -168,6 +180,9 @@ RUN chmod +x ./setup_cpp_linux
168180
# install llvm, cmake, ninja, and ccache
169181
RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true
170182

183+
# reload the environment
184+
RUN source ~/.profile
185+
171186
ENTRYPOINT [ "/bin/sh" ]
172187
```
173188

building/docker/debian.dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ RUN chmod +x ./setup_cpp_linux
1212
# install llvm, cmake, ninja, and ccache
1313
RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true
1414

15+
# reload the environment
16+
CMD source ~/.profile
17+
1518
ENTRYPOINT [ "/bin/sh" ]

building/docker/debian_node.dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ WORKDIR "/"
88
# run installation
99
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true
1010

11+
# reload the environment
12+
CMD source ~/.profile
13+
1114
ENTRYPOINT [ "/bin/sh" ]

building/docker/debian_node_slim.dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ RUN apt-get install -y --no-install-recommends unzip
1212
# run installation
1313
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --conan true
1414

15+
# reload the environment
16+
CMD source ~/.profile
17+
1518
ENTRYPOINT [ "/bin/sh" ]

dist/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/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.

src/gcc/gcc.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exportVariable, info } from "@actions/core"
1+
import { info } from "@actions/core"
22
import { addPath } from "../utils/path/addPath"
33
import { existsSync } from "fs"
44
import { setupAptPack } from "../utils/setup/setupAptPack"
@@ -7,6 +7,7 @@ import { setupChocoPack } from "../utils/setup/setupChocoPack"
77
import semverMajor from "semver/functions/major"
88
import semverCoerce from "semver/functions/coerce"
99
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
10+
import { addEnv } from "../utils/env/addEnv"
1011

1112
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1213
export async function setupGcc(version: string, _setupDir: string, arch: string) {
@@ -92,22 +93,22 @@ async function activateGcc(version: string, binDir: string) {
9293
// const ld = process.env.LD_LIBRARY_PATH ?? ""
9394
// const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
9495
// // Setup gcc as the compiler
95-
// exportVariable("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`)
96-
// exportVariable("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`)
97-
// exportVariable("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`)
98-
// exportVariable("LDFLAGS", `-L${installDir}/lib`)
99-
// exportVariable("CPPFLAGS", `-I${installDir}/include`)
96+
// addEnv("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`)
97+
// addEnv("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`)
98+
// addEnv("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`)
99+
// addEnv("LDFLAGS", `-L${installDir}/lib`)
100+
// addEnv("CPPFLAGS", `-I${installDir}/include`)
100101
if (process.platform === "win32") {
101-
exportVariable("CC", `${binDir}/gcc`)
102-
exportVariable("CXX", `${binDir}/g++`)
102+
addEnv("CC", `${binDir}/gcc`)
103+
addEnv("CXX", `${binDir}/g++`)
103104
} else {
104105
const majorVersion = semverMajor(semverCoerce(version) ?? version)
105106
if (majorVersion >= 5) {
106-
exportVariable("CC", `${binDir}/gcc-${majorVersion}`)
107-
exportVariable("CXX", `${binDir}/g++-${majorVersion}`)
107+
addEnv("CC", `${binDir}/gcc-${majorVersion}`)
108+
addEnv("CXX", `${binDir}/g++-${majorVersion}`)
108109
} else {
109-
exportVariable("CC", `${binDir}/gcc-${version}`)
110-
exportVariable("CXX", `${binDir}/g++-${version}`)
110+
addEnv("CC", `${binDir}/gcc-${version}`)
111+
addEnv("CXX", `${binDir}/g++-${version}`)
111112
}
112113
}
113114

src/llvm/llvm.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as core from "@actions/core"
21
import * as path from "path"
32
import semverLte from "semver/functions/lte"
43
import semverMajor from "semver/functions/major"
@@ -8,6 +7,8 @@ import { extractExe, extractTarByExe } from "../utils/setup/extract"
87
import { getSpecificVersionAndUrl, getVersions, semverCoerceIfInvalid } from "../utils/setup/version"
98
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
109
import { addBinExtension } from "../utils/extension/extension"
10+
import { addEnv } from "../utils/env/addEnv"
11+
import { setOutput } from "@actions/core"
1112

1213
//================================================
1314
// Version
@@ -223,7 +224,7 @@ export function getUrl(platform: string, version: string): string | null | Promi
223224

224225
async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): Promise<PackageInfo> {
225226
const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, platform, version, getUrl)
226-
core.setOutput("version", specificVersion)
227+
setOutput("version", specificVersion)
227228
return {
228229
url,
229230
extractedFolderName: "",
@@ -252,26 +253,26 @@ export async function activateLLVM(directory: string, versionGiven: string) {
252253
const ld = process.env.LD_LIBRARY_PATH ?? ""
253254
const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
254255

255-
core.exportVariable("LLVM_PATH", directory) // the output of this action
256+
addEnv("LLVM_PATH", directory) // the output of this action
256257

257258
const llvmMajor = semverMajor(version)
258259

259260
// Setup LLVM as the compiler
260-
core.exportVariable("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`)
261-
core.exportVariable("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`)
261+
addEnv("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`)
262+
addEnv("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`)
262263

263264
if (process.platform !== "win32") {
264265
// https://github.com/aminya/setup-cpp/issues/6
265-
core.exportVariable("CPATH", `${directory}/lib/clang/${llvmMajor}/include`)
266+
addEnv("CPATH", `${directory}/lib/clang/${llvmMajor}/include`)
266267
}
267268

268-
core.exportVariable("LDFLAGS", `-L${directory}/lib`)
269-
core.exportVariable("CPPFLAGS", `-I${directory}/include`)
269+
addEnv("LDFLAGS", `-L${directory}/lib`)
270+
addEnv("CPPFLAGS", `-I${directory}/include`)
270271

271-
core.exportVariable("CC", `${directory}/bin/clang`)
272-
core.exportVariable("CXX", `${directory}/bin/clang++`)
272+
addEnv("CC", `${directory}/bin/clang`)
273+
addEnv("CXX", `${directory}/bin/clang++`)
273274

274-
core.exportVariable("LIBRARY_PATH", `${directory}/lib`)
275+
addEnv("LIBRARY_PATH", `${directory}/lib`)
275276

276277
await setupMacOSSDK()
277278
}

src/macos-sdk/macos-sdk.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { getExecOutput } from "@actions/exec"
22
import * as core from "@actions/core"
3+
import { addEnv } from "../utils/env/addEnv"
34

45
export async function setupMacOSSDK() {
56
if (process.platform === "darwin") {
67
try {
78
const xcrun = await getExecOutput("xcrun --sdk macosx --show-sdk-path")
89
const sdkroot = xcrun.stdout || xcrun.stderr
910
if (sdkroot) {
10-
core.exportVariable("SDKROOT", sdkroot.trim())
11+
addEnv("SDKROOT", sdkroot.trim())
1112
} else {
1213
core.error(`SDKROOT not set`)
1314
}

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { setupVcpkg } from "./vcpkg/vcpkg"
2626
import { join } from "path"
2727
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
2828
import { setupKcov } from "./kcov/kcov"
29+
import { addEnv } from "./utils/env/addEnv"
2930

3031
/** The setup functions */
3132
const setups = {
@@ -176,8 +177,8 @@ export async function main(args: string[]): Promise<number> {
176177
case "appleclang":
177178
case "applellvm": {
178179
core.info("Assuming apple-clang is already installed")
179-
core.exportVariable("CC", "clang")
180-
core.exportVariable("CXX", "clang++")
180+
addEnv("CC", "clang")
181+
addEnv("CXX", "clang++")
181182
break
182183
}
183184
default: {

0 commit comments

Comments
 (0)