Skip to content

Commit

Permalink
Add windows build dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoH2O1999 committed Jan 10, 2023
1 parent 6225835 commit c908663
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/builder/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@

import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import {vsInstallerUrl, windowsBuildDependencies} from '../constants';
import Builder from './builder';
import fs from 'fs';
import os from 'os';
import path from 'path';

export default class WindowsBuilder extends Builder {
private readonly MSBUILD: string = process.env.MSBUILD || '';
private vsInstallationPath: string | undefined;

async build(): Promise<string> {
// Prepare envirnoment
Expand Down Expand Up @@ -91,7 +96,7 @@ export default class WindowsBuilder extends Builder {
}
}
if (candidates.length !== 1) {
throw new Error(`Expected only one candidate, got ${candidates}`);
throw new Error(`Expected one candidate, got ${candidates}`);
}
const installer = path.join(buildPath, candidates[0]);
core.info(`Installer: ${installer}`);
Expand Down Expand Up @@ -163,6 +168,34 @@ export default class WindowsBuilder extends Builder {
core.info('Temporarily adding as environment variable...');
core.exportVariable('MSBUILD', msBuildPath);
core.endGroup();

// Detect Visual Studio
core.startGroup('Searching for Visual Studio');
let vsPath = '';
await exec.exec('vswhere -property installationPath', [], {
listeners: {
stdout: (data: Buffer) => {
vsPath += data.toString();
}
}
});
core.info(`Found Visual Studio at ${vsPath}`);
this.vsInstallationPath = vsPath.trim();
core.endGroup();

// Installing dependencies
core.startGroup('Installing dependencies');
const installer = await tc.downloadTool(
vsInstallerUrl,
path.join(os.tmpdir(), 'vs_installer.exe')
);
for (const dependency of windowsBuildDependencies) {
await exec.exec(
`${installer} modify --installPath "${this.vsInstallationPath}" --add ${dependency} --quiet --norestart --force --wait`
);
}
await io.rmRF(installer);
core.endGroup();
}

async cleanEnvironment(): Promise<void> {
Expand All @@ -171,6 +204,17 @@ export default class WindowsBuilder extends Builder {
core.info('Cleaning temp MSBUILD variable...');
core.exportVariable('MSBUILD', this.MSBUILD);

const installer = await tc.downloadTool(
vsInstallerUrl,
path.join(os.tmpdir(), 'vs_installer.exe')
);
for (const dependency of windowsBuildDependencies) {
await exec.exec(
`${installer} modify --installPath "${this.vsInstallationPath}" --remove ${dependency} --quiet --norestart --force --wait`
);
}
await io.rmRF(installer);

core.endGroup();
}
}
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ export {defaultPyPy2, defaultPyPy3};
const warnRateLimitThreshold = 200;

export {warnRateLimitThreshold};

const windowsBuildDependencies = ['Microsoft.VisualStudio.Component.VC.140'];

const vsInstallerUrl = 'https://aka.ms/vs/17/release/vs_enterprise.exe';

export {windowsBuildDependencies, vsInstallerUrl};

0 comments on commit c908663

Please sign in to comment.