11import * as cp from "child_process"
22import { type PathLike , type StatOptions , type Stats , type StatsBase , stat as rawStat } from "fs-extra"
33import splitargs from "splitargs2"
4- import which from "which"
5- import { logger } from "./logger.js"
64
75export function getEnvVar ( name : string ) {
86 const value = process . env [ name ]
@@ -12,70 +10,6 @@ export function getEnvVar(name: string) {
1210 return undefined
1311}
1412
15- export async function getCmakeGenerator (
16- cmake : string ,
17- arch : string ,
18- ) : Promise < {
19- generator : string | undefined
20- binary : string | undefined
21- } > {
22- // use ninja if available
23- const ninja = await which ( "ninja" , { nothrow : true } )
24- if ( ninja !== null ) {
25- return {
26- generator : "Ninja" ,
27- binary : ninja ,
28- }
29- }
30-
31- const archString = arch === "x64" ? "Win64" : arch === "x86" ? "" : null
32- if ( archString === null ) {
33- logger . error ( "Failed to find valid VS gen, using native. Good Luck." )
34- return {
35- generator : "native" ,
36- binary : undefined ,
37- }
38- }
39-
40- const generators = await execCapture ( `"${ cmake } " -G` )
41- const hasCR = generators . includes ( "\r\n" )
42- const output = hasCR ? generators . split ( "\r\n" ) : generators . split ( "\n" )
43- let found = false
44- let useVSGen = ""
45-
46- for ( const line of output ) {
47- if ( ! found && line . trim ( ) === "Generators" ) {
48- found = true
49- continue
50- }
51- const genParts = line . split ( "=" )
52- if ( genParts . length <= 1 ) {
53- // Some descriptions are multi-line
54- continue
55- }
56- /** Current MSVS compiler selected in Windows generally is prefixed with "* " */
57- genParts [ 0 ] = genParts [ 0 ] . replace ( / ^ ( \* ) / , "" ) . trim ( )
58-
59- // eslint-disable-next-line optimize-regex/optimize-regex
60- if ( genParts [ 0 ] . match ( / V i s u a l \s + S t u d i o \s + \d + \s + \d + ( \s + \[ a r c h \] ) ? / ) ) {
61- logger . debug ( "Found generator: " , genParts [ 0 ] )
62- // The first entry is usually the latest entry
63- useVSGen = genParts [ 0 ]
64- break
65- }
66- }
67- const useSwitch = ! useVSGen . match ( / .* \[ a r c h ] / )
68- if ( useSwitch ) {
69- useVSGen += " -A" // essentially using this as a flag
70- } else {
71- useVSGen = useVSGen . replace ( "[arch]" , archString ) . trim ( )
72- }
73- return {
74- generator : useVSGen ,
75- binary : undefined ,
76- }
77- }
78-
7913export function execCapture ( command : string ) : Promise < string > {
8014 return new Promise ( ( resolve ) => {
8115 cp . exec ( command , ( _ , stdout , stderr ) => {
0 commit comments