Skip to content

Commit 32576cd

Browse files
committed
perf: skip visual studio components installation if not needed
1 parent a01e266 commit 32576cd

File tree

5 files changed

+287
-202
lines changed

5 files changed

+287
-202
lines changed

dist/index.js

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

src/utils/visual_studio/base.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as os from 'os'
2+
import * as path from 'path'
3+
import {getExecOutput} from '@actions/exec'
4+
5+
export class VisualStudio {
6+
private constructor(
7+
readonly installationPath: string,
8+
readonly installationVersion: string,
9+
readonly catalog: VisualStudioCatalog,
10+
readonly properties: VisualStudioProperties
11+
) {}
12+
13+
// eslint-disable-next-line no-explicit-any
14+
static createFromJSON(json: any) {
15+
return new VisualStudio(
16+
json.installationPath,
17+
json.installationVersion,
18+
json.catalog,
19+
json.properties
20+
)
21+
}
22+
23+
async env() {
24+
/// https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170
25+
const nativeToolsScriptx86 = path.join(
26+
this.installationPath,
27+
'Common7',
28+
'Tools',
29+
'VsDevCmd.bat'
30+
)
31+
const {stdout} = await getExecOutput(
32+
'cmd',
33+
[
34+
'/k',
35+
nativeToolsScriptx86,
36+
`-arch=${os.arch()}`,
37+
'&&',
38+
'set',
39+
'&&',
40+
'exit'
41+
],
42+
{failOnStdErr: true}
43+
)
44+
return Object.fromEntries(
45+
stdout
46+
.split(os.EOL)
47+
.filter(s => s.indexOf('='))
48+
.map(s => s.trim())
49+
.map(s => s.split('=', 2))
50+
.filter(s => s.length === 2)
51+
.map(s => [s[0].trim(), s[1].trim()] as const)
52+
) as VisualStudioEnv
53+
}
54+
}
55+
56+
export interface VisualStudioCatalog {
57+
productDisplayVersion: string
58+
}
59+
60+
export interface VisualStudioProperties {
61+
setupEngineFilePath: string
62+
}
63+
64+
export interface VisualStudioRequirement {
65+
version: string
66+
components: string[]
67+
}
68+
69+
export interface VisualStudioEnv {
70+
readonly UniversalCRTSdkDir?: string
71+
readonly UCRTVersion?: string
72+
readonly VCToolsInstallDir?: string
73+
readonly [name: string]: string | undefined
74+
}

src/utils/visual_studio/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './base'
12
export * from './setup'
23
export * from './update'

0 commit comments

Comments
 (0)