From a82d8be15b8488256187196e9402be1c12573029 Mon Sep 17 00:00:00 2001 From: Juha Date: Fri, 29 Mar 2024 17:05:06 +0200 Subject: [PATCH] LazBuild: Allow just the macro name to be specified in "get-expand-text" parameter. By n7800. --- ide/lazarusidestrconsts.pas | 5 +++-- ide/lazbuild.lpr | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 3bb57620e1..66cca941e6 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -174,8 +174,9 @@ resourcestring 'info file after build. If not specified, build number will be incremented '+ 'if configured.'; - lisGetExpandText = 'Print the result of substituting macros in the text for the specified build mode.' - +' By default, active build mode is used.'; + lisGetExpandText = 'Print the result of substituting macros in the text. '+ + 'The absence of macros in the text means the name of the macro. '+ + 'By default, active build mode is used.'; lisGetBuildModes = 'Print a list of build modes in the project. Active mode is listed first.'; lisGetTargetPath = 'Print the full path to the executable file in the specified build mode.' +' By default, active build mode is used.'; diff --git a/ide/lazbuild.lpr b/ide/lazbuild.lpr index 4e79669534..8d15c86b2d 100644 --- a/ide/lazbuild.lpr +++ b/ide/lazbuild.lpr @@ -770,6 +770,8 @@ var function StartBuilding : boolean; var + i: integer; + HasMacro: boolean; NeedBuildAllFlag: Boolean; CfgCode: TCodeBuffer; CfgFilename: String; @@ -799,6 +801,17 @@ var MainBuildBoss.SetBuildTargetProject1(true,smsfsSkip); if HasLongOptIgnoreCase('get-expand-text',S) then begin + // check for macros + HasMacro := false; + for i := 1 to length(S) - 1 do // skip last char + if (S[i] = '$') and (S[i + 1] <> '$') then begin // skip escaped '$' + HasMacro := true; + break; + end; + // if a macro is not specified, its name is assumed + if not HasMacro then + S := '$(' + S + ')'; + // expand Project1.MacroEngine.SubstituteStr(S); WriteLn(S); exit(true);