@@ -9,10 +9,12 @@ import numerousLocale from "numerous/locales/en.js"
99import timeDelta from "time-delta"
1010import timeDeltaLocale from "time-delta/locales/en.js"
1111import { untildifyUser } from "untildify-user"
12+ import packageJson from "../package-version.json"
1213import { checkUpdates } from "./check-updates.js"
1314import { parseArgs , printHelp , rcOptions } from "./cli-options.js"
1415import { getCompilerInfo , installCompiler } from "./compilers.js"
1516import { installTool } from "./installTool.js"
17+ import { installSetupCpp } from "./setup-cpp-installer.js"
1618import { type Inputs , llvmTools , tools } from "./tool.js"
1719import { isArch } from "./utils/env/isArch.js"
1820import { ubuntuVersion } from "./utils/env/ubuntu_version.js"
@@ -21,11 +23,7 @@ import { syncVersions } from "./versions/versions.js"
2123
2224/** The main entry function */
2325async function main ( args : string [ ] ) : Promise < number > {
24- let checkUpdatePromise = Promise . resolve ( )
25- if ( ! GITHUB_ACTIONS ) {
26- checkUpdatePromise = checkUpdates ( )
27- process . env . ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
28- }
26+ const checkUpdatePromise = GITHUB_ACTIONS ? Promise . resolve ( ) : checkUpdates ( )
2927
3028 // parse options using mri or github actions
3129 const opts = parseArgs ( args )
@@ -35,6 +33,11 @@ async function main(args: string[]): Promise<number> {
3533 printHelp ( )
3634 }
3735
36+ // print version
37+ if ( opts . version ) {
38+ info ( `${ packageJson . version } ` )
39+ }
40+
3841 // cpu architecture
3942 const arch = opts . architecture ?? process . arch
4043
@@ -122,11 +125,20 @@ async function main(args: string[]): Promise<number> {
122125
123126 await finalizeRC ( rcOptions )
124127
125- if ( successMessages . length === 0 && errorMessages . length === 0 ) {
126- warning ( "setup-cpp was called without any arguments. Nothing to do." )
127- return 0
128+ const noTool = successMessages . length === 0 && errorMessages . length === 0
129+
130+ // if setup-cpp option is not passed, install setup-cpp by default unless only help or version is passed
131+ // So that --help and --version are immutable
132+ if ( opts [ "setup-cpp" ] === undefined ) {
133+ opts [ "setup-cpp" ] = ! ( noTool && ( opts . version || opts . help ) )
128134 }
129135
136+ const installSetupCppPromise = opts [ "setup-cpp" ]
137+ ? installSetupCpp ( packageJson . version , opts [ "node-package-manager" ] )
138+ : Promise . resolve ( )
139+
140+ await Promise . all ( [ checkUpdatePromise , installSetupCppPromise ] )
141+
130142 // report the messages in the end
131143 for ( const tool of successMessages ) {
132144 success ( tool )
@@ -135,27 +147,26 @@ async function main(args: string[]): Promise<number> {
135147 error ( tool )
136148 }
137149
138- info ( "setup-cpp finished" )
139-
140- if ( ! GITHUB_ACTIONS ) {
141- switch ( process . platform ) {
142- case "win32" : {
143- warning ( "Run `RefreshEnv.cmd` or restart your shell to update the environment." )
144- break
145- }
146- case "linux" :
147- case "darwin" : {
148- warning ( "Run `source ~/.cpprc` or restart your shell to update the environment." )
149- break
150- }
151- default : {
152- // nothing
150+ if ( successMessages . length !== 0 || errorMessages . length !== 0 ) {
151+ info ( "setup-cpp finished" )
152+
153+ if ( ! GITHUB_ACTIONS ) {
154+ switch ( process . platform ) {
155+ case "win32" : {
156+ warning ( "Run `RefreshEnv.cmd` or restart your shell to update the environment." )
157+ break
158+ }
159+ case "linux" :
160+ case "darwin" : {
161+ warning ( "Run `source ~/.cpprc` or restart your shell to update the environment." )
162+ break
163+ }
164+ default : {
165+ // nothing
166+ }
153167 }
154168 }
155169 }
156-
157- await checkUpdatePromise
158-
159170 return errorMessages . length === 0 ? 0 : 1 // exit with non-zero if any error message
160171}
161172
0 commit comments