diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 5f09fac93c..e0efa66663 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -176,8 +176,10 @@ resourcestring 'multiple times. If compilation options are also specified in --build-ide, '+ 'then the options from --opt will be added after them.'; 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.'; + 'The absence of macros means the name of the macro. '+ + 'In case of an error, returns only the text with partially expanded macros '+ + 'and sets the error code (also for an empty string). '+ + 'Takes into account the active build mode (or specified via "--bm").'; lisGetBuildModes = 'Print a list of build modes in the project. Active mode is listed first.'; lisLazbuildOptionsSyntax = 'lazbuild [options] '; diff --git a/ide/lazbuild.lpr b/ide/lazbuild.lpr index 10bb648b08..c4f25b14c1 100644 --- a/ide/lazbuild.lpr +++ b/ide/lazbuild.lpr @@ -206,6 +206,7 @@ const ErrorLoadProjectFailed = 5; ErrorInvalidSyntax = 6; ErrorInitialization = 7; + ErrorExpandMacro = 8; VersionStr = {$I packages/ideconfig/version.inc}; procedure FilterConfigFileContent; @@ -848,6 +849,13 @@ var if HasLongOptIgnoreCase('get',S) or HasLongOptIgnoreCase('get-expand-text',S) then begin + // check for empty text + if S = '' then + begin + writeln(''); // print empty text as well + halt(ErrorExpandMacro); // exit with error + end; + // check for macros HasMacro := false; for i := 1 to length(S) - 1 do // skip last char @@ -859,7 +867,13 @@ var if not HasMacro then S := '$(' + S + ')'; // expand - Project1.MacroEngine.SubstituteStr(S); + Project1.MacroEngine.MarkUnhandledMacros := false; + if not Project1.MacroEngine.SubstituteStr(S) then + begin + writeln(S); // print partially expanded text + halt(ErrorExpandMacro); // exit with error + end; + // print result WriteLn(S); exit(true); end;