Skip to content

Commit

Permalink
perf: skip visual studio components installation if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyamahunt committed Sep 7, 2023
1 parent a01e266 commit 32576cd
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 202 deletions.
232 changes: 144 additions & 88 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions src/utils/visual_studio/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as os from 'os'
import * as path from 'path'
import {getExecOutput} from '@actions/exec'

export class VisualStudio {
private constructor(
readonly installationPath: string,
readonly installationVersion: string,
readonly catalog: VisualStudioCatalog,
readonly properties: VisualStudioProperties
) {}

// eslint-disable-next-line no-explicit-any
static createFromJSON(json: any) {
return new VisualStudio(
json.installationPath,
json.installationVersion,
json.catalog,
json.properties
)
}

async env() {
/// https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170
const nativeToolsScriptx86 = path.join(
this.installationPath,
'Common7',
'Tools',
'VsDevCmd.bat'
)
const {stdout} = await getExecOutput(
'cmd',
[
'/k',
nativeToolsScriptx86,
`-arch=${os.arch()}`,
'&&',
'set',
'&&',
'exit'
],
{failOnStdErr: true}
)
return Object.fromEntries(
stdout
.split(os.EOL)
.filter(s => s.indexOf('='))
.map(s => s.trim())
.map(s => s.split('=', 2))
.filter(s => s.length === 2)
.map(s => [s[0].trim(), s[1].trim()] as const)
) as VisualStudioEnv
}
}

export interface VisualStudioCatalog {
productDisplayVersion: string
}

export interface VisualStudioProperties {
setupEngineFilePath: string
}

export interface VisualStudioRequirement {
version: string
components: string[]
}

export interface VisualStudioEnv {
readonly UniversalCRTSdkDir?: string
readonly UCRTVersion?: string
readonly VCToolsInstallDir?: string
readonly [name: string]: string | undefined
}
1 change: 1 addition & 0 deletions src/utils/visual_studio/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './base'
export * from './setup'
export * from './update'
Loading

0 comments on commit 32576cd

Please sign in to comment.