Skip to content

Commit 4c53a2d

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

File tree

14 files changed

+133
-126
lines changed

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)

0 commit comments

Comments
 (0)