Skip to content

Commit

Permalink
fix: fix VS CMake generator finder
Browse files Browse the repository at this point in the history
Co-Authored-By: Dief Bell <107551242+diefbell-grabcad@users.noreply.github.com>
  • Loading branch information
2 people authored and aminya committed Nov 22, 2024
1 parent 2e88344 commit 1f9c204
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/argumentBuilder.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,12 @@ export class ArgumentBuilder {
const defines = await this.buildDefines();
baseCommand += ` ${ defines.map(d => `-D${d[0]}="${d[1]}"`).join(" ")}`;
if (this.options.generatorToUse !== 'native') {
baseCommand += ` -G"${this.options.generatorToUse}"`;
let generatorString = ` -G"${this.options.generatorToUse}"`;
if(generatorString.match(/Visual\s+Studio\s+\d+\s+\d+\s-A/)) {
generatorString = generatorString.replace(/\s-A/, '');
generatorString += ` -A ${this.config.arch}`;
}
baseCommand += generatorString;
}
console.log(baseCommand)
return baseCommand;
2 changes: 1 addition & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
@@ -212,7 +212,7 @@ export async function defaultBuildOptions(configs: BuildOptions, buildmode: Buil
let ninja: string | null;
let make: string | null;
if (configs.generatorToUse === undefined) {
console.log('no generator specified, checking ninja');
console.log('no generator specified in package.json, checking ninja');
ninja = await ninjaP;
if (!ninja) {
console.log('ninja not found, checking make');
21 changes: 13 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,12 @@ import splitargs from 'splitargs2';
import { PathLike, stat as rawStat, StatOptions, Stats } from 'fs-extra';

export const GET_CMAKE_VS_GENERATOR = async (cmake: string, arch: string): Promise<string> => {
const archString = arch === 'x64' ? 'Win64' : arch === "x86" ? '' : null;
if(archString === null) {
console.error('Failed to find valid VS gen, using native. Good Luck.');
return 'native';
}

const generators = await EXEC_CAPTURE(`"${cmake}" -G`);
const hasCR = generators.includes('\r\n');
const output = hasCR ? generators.split('\r\n') : generators.split('\n');
@@ -19,23 +25,22 @@ export const GET_CMAKE_VS_GENERATOR = async (cmake: string, arch: string): Promi
// Some descriptions are multi-line
continue;
}
genParts[0] = genParts[0].trim();
genParts[0] = genParts[0].replace(/^(\* )/, "").trim();

// eslint-disable-next-line optimize-regex/optimize-regex
if (genParts[0].match(/Visual\s+Studio\s+\d+\s+\d+\s+\[arch\]/)) {
if (genParts[0].match(/Visual\s+Studio\s+\d+\s+\d+(\s+\[arch\])?/)) {
console.log('Found generator: ', genParts[0]);
// The first entry is usually the latest entry
useVSGen = genParts[0];
break;
}
}
if (arch === 'x64') {
useVSGen = useVSGen.replace('[arch]', 'Win64').trim();
} else if (arch === 'x86') {
useVSGen = useVSGen.replace('[arch]', '').trim();

const useSwitch = !useVSGen.match(/.*\[arch\]/);
if(useSwitch) {
useVSGen += " -A" // essentially using this as a flag
} else {
console.error('Failed to find valid VS gen, using native. Good Luck.');
return 'native';
useVSGen = useVSGen.replace('[arch]', archString).trim();
}
return useVSGen;
}

0 comments on commit 1f9c204

Please sign in to comment.