mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-23 17:29:37 +02:00
Merge branch 'LazBuild/ExpandMacros' into 'main'
LazBuild: Checking macro substitution in the "--get-expand-text" option and setting the return code See merge request freepascal.org/lazarus/lazarus!338
This commit is contained in:
commit
7c77414c06
@ -365,7 +365,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
s:='';
|
s:='';
|
||||||
//IDEMessageDialog('Unknown Macro','Macro not defined: "'+s+'".',mtError,[mbAbort],0);
|
//IDEMessageDialog('Unknown Macro','Macro not defined: "'+s+'".',mtError,[mbAbort],0);
|
||||||
Handled:=true;
|
Handled:=false;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -176,8 +176,10 @@ resourcestring
|
|||||||
'multiple times. If compilation options are also specified in --build-ide, '+
|
'multiple times. If compilation options are also specified in --build-ide, '+
|
||||||
'then the options from --opt will be added after them.';
|
'then the options from --opt will be added after them.';
|
||||||
lisGetExpandText = 'Print the result of substituting macros in the text. '+
|
lisGetExpandText = 'Print the result of substituting macros in the text. '+
|
||||||
'The absence of macros in the text means the name of the macro. '+
|
'The absence of macros means the name of the macro. '+
|
||||||
'By default, active build mode is used.';
|
'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.';
|
lisGetBuildModes = 'Print a list of build modes in the project. Active mode is listed first.';
|
||||||
|
|
||||||
lisLazbuildOptionsSyntax = 'lazbuild [options] <project/package filename or package name>';
|
lisLazbuildOptionsSyntax = 'lazbuild [options] <project/package filename or package name>';
|
||||||
|
@ -206,6 +206,7 @@ const
|
|||||||
ErrorLoadProjectFailed = 5;
|
ErrorLoadProjectFailed = 5;
|
||||||
ErrorInvalidSyntax = 6;
|
ErrorInvalidSyntax = 6;
|
||||||
ErrorInitialization = 7;
|
ErrorInitialization = 7;
|
||||||
|
ErrorExpandMacro = 8;
|
||||||
VersionStr = {$I packages/ideconfig/version.inc};
|
VersionStr = {$I packages/ideconfig/version.inc};
|
||||||
|
|
||||||
procedure FilterConfigFileContent;
|
procedure FilterConfigFileContent;
|
||||||
@ -848,6 +849,13 @@ var
|
|||||||
|
|
||||||
if HasLongOptIgnoreCase('get',S) or
|
if HasLongOptIgnoreCase('get',S) or
|
||||||
HasLongOptIgnoreCase('get-expand-text',S) then begin
|
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
|
// check for macros
|
||||||
HasMacro := false;
|
HasMacro := false;
|
||||||
for i := 1 to length(S) - 1 do // skip last char
|
for i := 1 to length(S) - 1 do // skip last char
|
||||||
@ -859,7 +867,13 @@ var
|
|||||||
if not HasMacro then
|
if not HasMacro then
|
||||||
S := '$(' + S + ')';
|
S := '$(' + S + ')';
|
||||||
// expand
|
// 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);
|
WriteLn(S);
|
||||||
exit(true);
|
exit(true);
|
||||||
end;
|
end;
|
||||||
|
@ -295,7 +295,10 @@ begin
|
|||||||
//debugln(['TTransferMacroList.SubstituteStr FUNC ',MacroName]);
|
//debugln(['TTransferMacroList.SubstituteStr FUNC ',MacroName]);
|
||||||
MacroEnd:=SearchBracketClose(MacroEnd)+1;
|
MacroEnd:=SearchBracketClose(MacroEnd)+1;
|
||||||
if MacroEnd>sLen+1 then
|
if MacroEnd>sLen+1 then
|
||||||
|
begin
|
||||||
|
result := false;
|
||||||
break; // missing closing bracket
|
break; // missing closing bracket
|
||||||
|
end;
|
||||||
OldMacroLen:=MacroEnd-MacroStart;
|
OldMacroLen:=MacroEnd-MacroStart;
|
||||||
MacroStr:=copy(s,MacroStart,OldMacroLen);
|
MacroStr:=copy(s,MacroStart,OldMacroLen);
|
||||||
// Macro found
|
// Macro found
|
||||||
@ -322,6 +325,8 @@ begin
|
|||||||
ExecuteMacro(MacroName,MacroParam,Data,Handled,Abort,Depth+1);
|
ExecuteMacro(MacroName,MacroParam,Data,Handled,Abort,Depth+1);
|
||||||
if Abort then
|
if Abort then
|
||||||
exit(false);
|
exit(false);
|
||||||
|
if not Handled then
|
||||||
|
result := false; // set error, but continue parsing
|
||||||
MacroStr:=MacroParam;
|
MacroStr:=MacroParam;
|
||||||
|
|
||||||
// substitute result
|
// substitute result
|
||||||
|
Loading…
Reference in New Issue
Block a user