Skip to content

Commit 4c53a2d

Browse files
committed
fix: ensure constant initialization order
1 parent 52047bd commit 4c53a2d

14 files changed

+133
-126
lines changed

dist/actions/setup-cpp.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

dist/legacy/setup-cpp.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

dist/modern/setup-cpp.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/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/__tests__/main.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { syncVersions, getVersion } from "../versions/versions"
2-
import { parseArgs, Inputs } from "../cli-options"
2+
import { parseArgs } from "../cli-options"
33
import { getCompilerInfo } from "../compilers"
4+
import { Inputs } from "../tool"
45

56
jest.setTimeout(300000)
67
describe("getCompilerInfo", () => {

src/cli-options.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import { getInput } from "@actions/core"
22
import { info } from "ci-log"
33
import mri from "mri"
44
import { InstallationInfo } from "./utils/setup/setupBin"
5-
import { setups, tools } from "./tool"
6-
7-
/** The possible inputs to the program */
8-
export type Inputs = keyof typeof setups | "compiler" | "architecture" | "timeout"
9-
10-
/** ‌ an array of possible inputs */
11-
export const inputs: Array<Inputs> = ["compiler", "architecture", "timeout", ...tools]
5+
import { Inputs, inputs } from "./tool"
126

137
export function parseArgs(args: string[]): Opts {
148
return mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {

src/installTool.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { endGroup, startGroup } from "@actions/core"
2+
import { error } from "ci-log"
3+
import { join } from "patha"
4+
import { getSuccessMessage } from "./cli-options"
5+
import { InstallationInfo } from "./utils/setup/setupBin"
6+
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
7+
import { getVersion } from "./versions/versions"
8+
import pTimeout from "p-timeout"
9+
import { ToolName, setups } from "./tool"
10+
11+
export const DEFAULT_TIMEOUT = 20 * 60 * 1000 // 20 minutes
12+
13+
export async function installTool(
14+
tool: ToolName,
15+
version: string,
16+
osVersion: number[] | null,
17+
arch: string,
18+
setupCppDir: string,
19+
successMessages: string[],
20+
errorMessages: string[],
21+
timeout: number = DEFAULT_TIMEOUT,
22+
) {
23+
startGroup(`Installing ${tool} ${version}`)
24+
let hasLLVM = false
25+
try {
26+
hasLLVM = await pTimeout(installToolImpl(tool, version, osVersion, arch, hasLLVM, setupCppDir, successMessages), {
27+
milliseconds: timeout * 60 * 1000,
28+
})
29+
} catch (e) {
30+
// push error message to the logger
31+
error(e as string | Error)
32+
errorMessages.push(`${tool} failed to install`)
33+
}
34+
endGroup()
35+
return hasLLVM
36+
}
37+
38+
async function installToolImpl(
39+
tool: ToolName,
40+
version: string,
41+
osVersion: number[] | null,
42+
arch: string,
43+
hasLLVM: boolean,
44+
setupCppDir: string,
45+
successMessages: string[],
46+
) {
47+
let installationInfo: InstallationInfo | undefined | void
48+
if (tool === "vcvarsall") {
49+
// eslint-disable-next-line no-await-in-loop
50+
await setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
51+
} else {
52+
// get the setup function
53+
const setupFunction = setups[tool]
54+
55+
// eslint-disable-next-line no-param-reassign
56+
hasLLVM = ["llvm", "clangformat", "clangtidy"].includes(tool)
57+
58+
// the tool installation directory (for the functions that ue it)
59+
const setupDir = join(setupCppDir, hasLLVM ? "llvm" : tool)
60+
61+
// eslint-disable-next-line no-await-in-loop
62+
installationInfo = await setupFunction(getVersion(tool, version, osVersion), setupDir, arch)
63+
}
64+
// preparing a report string
65+
successMessages.push(getSuccessMessage(tool, installationInfo))
66+
return hasLLVM
67+
}

src/llvm/llvm.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ async function setupLLVMWithoutActivation_raw(version: string, setupDir: string,
3535
const setupLLVMWithoutActivation = memoize(setupLLVMWithoutActivation_raw, { isPromise: true })
3636

3737
/** Setup llvm tools (clang tidy, clang format, etc) without activating llvm and using it as the compiler */
38-
export const setupClangTools = setupLLVMWithoutActivation
38+
export function setupClangTools(version: string, setupDir: string, arch: string) {
39+
return setupLLVMOnly(version, setupDir, arch)
40+
}
3941

4042
async function setupLLVMOnly(version: string, setupDir: string, arch: string) {
4143
const coeredVersion = semverCoerceIfInvalid(version)

src/llvm/llvm_installer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { hasNala, isPackageInstalled, setupAptPack } from "../utils/setup/setupA
55
import { InstallationInfo } from "../utils/setup/setupBin"
66
import { promises } from "fs"
77
import { info } from "console"
8-
import { DEFAULT_TIMEOUT } from "../tool"
8+
import { DEFAULT_TIMEOUT } from "../installTool"
99
const { readFile, writeFile, chmod } = promises
1010

1111
export async function setupLLVMApt(majorVersion: number): Promise<InstallationInfo> {

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import { untildifyUser } from "untildify-user"
1111
import { checkUpdates } from "./check-updates"
1212
import { parseArgs, printHelp } from "./cli-options"
1313
import { installCompiler } from "./compilers"
14-
import { installTool, tools } from "./tool"
1514
import { finalizeCpprc } from "./utils/env/addEnv"
1615
import { isArch } from "./utils/env/isArch"
1716
import { ubuntuVersion } from "./utils/env/ubuntu_version"
1817
import { setupPacmanPack } from "./utils/setup/setupPacmanPack"
1918
import { syncVersions } from "./versions/versions"
19+
import { installTool } from "./installTool"
20+
import { tools } from "./tool"
2021

2122
/** The main entry function */
2223
async function main(args: string[]): Promise<number> {

src/tool.ts

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { endGroup, startGroup } from "@actions/core"
2-
import { error } from "ci-log"
3-
import { join } from "patha"
41
import { setupBazel } from "./bazel/bazel"
52
import { setupBrew } from "./brew/brew"
63
import { setupCcache } from "./ccache/ccache"
74
import { setupChocolatey } from "./chocolatey/chocolatey"
8-
import { getSuccessMessage } from "./cli-options"
95
import { setupCmake } from "./cmake/cmake"
106
import { setupConan } from "./conan/conan"
117
import { setupCppcheck } from "./cppcheck/cppcheck"
@@ -26,11 +22,8 @@ import { setupPython } from "./python/python"
2622
import { setupSccache } from "./sccache/sccache"
2723
import { setupSevenZip } from "./sevenzip/sevenzip"
2824
import { setupTask } from "./task/task"
29-
import { InstallationInfo } from "./utils/setup/setupBin"
3025
import { setupVcpkg } from "./vcpkg/vcpkg"
3126
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
32-
import { getVersion } from "./versions/versions"
33-
import pTimeout from "p-timeout"
3427

3528
/** The setup functions */
3629
export const setups = {
@@ -69,60 +62,8 @@ export type ToolName = keyof typeof setups
6962
/** The tools that can be installed */
7063
export const tools = Object.keys(setups) as Array<ToolName>
7164

72-
export const DEFAULT_TIMEOUT = 20 * 60 * 1000 // 20 minutes
65+
/** The possible inputs to the program */
66+
export type Inputs = keyof typeof setups | "compiler" | "architecture" | "timeout"
7367

74-
export async function installTool(
75-
tool: ToolName,
76-
version: string,
77-
osVersion: number[] | null,
78-
arch: string,
79-
setupCppDir: string,
80-
successMessages: string[],
81-
errorMessages: string[],
82-
timeout: number = DEFAULT_TIMEOUT,
83-
) {
84-
startGroup(`Installing ${tool} ${version}`)
85-
let hasLLVM = false
86-
try {
87-
hasLLVM = await pTimeout(installToolImpl(tool, version, osVersion, arch, hasLLVM, setupCppDir, successMessages), {
88-
milliseconds: timeout * 60 * 1000,
89-
})
90-
} catch (e) {
91-
// push error message to the logger
92-
error(e as string | Error)
93-
errorMessages.push(`${tool} failed to install`)
94-
}
95-
endGroup()
96-
return hasLLVM
97-
}
98-
99-
async function installToolImpl(
100-
tool: ToolName,
101-
version: string,
102-
osVersion: number[] | null,
103-
arch: string,
104-
hasLLVM: boolean,
105-
setupCppDir: string,
106-
successMessages: string[],
107-
) {
108-
let installationInfo: InstallationInfo | undefined | void
109-
if (tool === "vcvarsall") {
110-
// eslint-disable-next-line no-await-in-loop
111-
await setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
112-
} else {
113-
// get the setup function
114-
const setupFunction = setups[tool]
115-
116-
// eslint-disable-next-line no-param-reassign
117-
hasLLVM = ["llvm", "clangformat", "clangtidy"].includes(tool)
118-
119-
// the tool installation directory (for the functions that ue it)
120-
const setupDir = join(setupCppDir, hasLLVM ? "llvm" : tool)
121-
122-
// eslint-disable-next-line no-await-in-loop
123-
installationInfo = await setupFunction(getVersion(tool, version, osVersion), setupDir, arch)
124-
}
125-
// preparing a report string
126-
successMessages.push(getSuccessMessage(tool, installationInfo))
127-
return hasLLVM
128-
}
68+
/** ‌ an array of possible inputs */
69+
export const inputs: Array<Inputs> = ["compiler", "architecture", "timeout", ...tools]

src/versions/versions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Opts, Inputs } from "../cli-options"
1+
import { Opts } from "../cli-options"
2+
import { Inputs } from "../tool"
23
import { DefaultLinuxVersion, DefaultVersions } from "./default_versions"
34

45
/** Get the default version if passed true or undefined, otherwise return the version itself */

0 commit comments

Comments
 (0)