Improve diagnostics for out-of-date VS install (#443)
* Warn if VS has older than minimum required version, and skip local build * Ensure more descriptive warnings and errors go to `rush` summary output * Add escape hatch ADL_SKIP_VS_BUILD env var to force VS build to skip
This commit is contained in:
Родитель
616642b607
Коммит
4d9257d900
|
@ -62,12 +62,14 @@ export function run(command, args, options) {
|
|||
const proc = (options.sync ? spawnSync : spawn)(command, args, options);
|
||||
if (proc.error) {
|
||||
if (options.ignoreCommandNotFound && proc.error.code === "ENOENT") {
|
||||
console.log("Skipped: Command not found.");
|
||||
console.log(`Skipped: Command \`${command}\` not found.`);
|
||||
} else {
|
||||
throw proc.error;
|
||||
}
|
||||
} else if (options.throwOnNonZeroExit && proc.status !== undefined && proc.status !== 0) {
|
||||
throw new Error(`Command failed with exit code ${proc.status}`);
|
||||
throw new Error(
|
||||
`Command \`${command} ${args.join(" ")}\` failed with exit code ${proc.status}`
|
||||
);
|
||||
}
|
||||
|
||||
return proc;
|
||||
|
|
|
@ -7,24 +7,52 @@ if (process.platform !== "win32") {
|
|||
process.exit(0);
|
||||
}
|
||||
|
||||
const ignoreCommandNotFound = !process.env.ADL_REQUIRE_VISUAL_STUDIO_EXTENSION_BUILD;
|
||||
if (process.env.ADL_SKIP_VS_BUILD) {
|
||||
console.log("Skipping adl-vs build: ADL_SKIP_VS_BUILD is set.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const vswhere = join(
|
||||
process.env["ProgramFiles(x86)"],
|
||||
"Microsoft Visual Studio/Installer/vswhere.exe"
|
||||
);
|
||||
|
||||
const proc = run(vswhere, ["-latest", "-prerelease", "-property", "installationPath"], {
|
||||
ignoreCommandNotFound,
|
||||
const vsMinimumVersion = "16.9";
|
||||
const vswhereArgs = [
|
||||
"-latest",
|
||||
"-prerelease",
|
||||
"-version",
|
||||
`[${vsMinimumVersion},`,
|
||||
"-property",
|
||||
"installationPath",
|
||||
];
|
||||
|
||||
let proc = run(vswhere, vswhereArgs, {
|
||||
ignoreCommandNotFound: true,
|
||||
throwOnNonZeroExit: false,
|
||||
encoding: "utf-8",
|
||||
stdio: [null, "pipe", "inherit"],
|
||||
});
|
||||
|
||||
if (ignoreCommandNotFound && proc.error?.code === "ENOENT") {
|
||||
console.log("Skipping adl-vs build: Visual Studio not found.");
|
||||
process.exit(0);
|
||||
if (proc.status != 0 || proc.error || !proc.stdout) {
|
||||
const message = `Visual Studio ${vsMinimumVersion} or later not found`;
|
||||
if (process.env.ADL_REQUIRE_VS_BUILD) {
|
||||
// In official build on Windows, it's an error if VS is not found.
|
||||
console.error(`error: ${message}`);
|
||||
process.exit(1);
|
||||
} else if (proc.error?.code === "ENOENT") {
|
||||
// If developer has no version of VS installed, skip build without warning.
|
||||
console.log(`Skipping adl-vs build: ${message}.`);
|
||||
process.exit(0);
|
||||
} else {
|
||||
// If developer has VS but it's not recent enough, skip build with warning.
|
||||
console.error(`warning: ${message}. Skipping adl-vs build.`);
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
const version = JSON.parse(readFileSync("package.json")).version;
|
||||
const msbuild = join(proc.stdout.trim(), "MSBuild/Current/Bin/MSBuild.exe");
|
||||
run(msbuild, ["/p:Configuration=Release", `/p:Version=${version}`]);
|
||||
const msbuildArgs = ["/p:Configuration=Release", `/p:Version=${version}`];
|
||||
proc = run(msbuild, msbuildArgs, { throwOnNonZeroExit: false });
|
||||
process.exit(proc.status ?? 1);
|
||||
|
|
Загрузка…
Ссылка в новой задаче