mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-19 11:39:23 +02:00
IDE: check build macro names with IDE built-in macros
git-svn-id: trunk@27466 -
This commit is contained in:
parent
5e87400d8c
commit
aaa7d1a0c6
@ -70,6 +70,7 @@
|
||||
- conditionals editor for project
|
||||
- warn for macro name conflicts
|
||||
- on renaming
|
||||
- IDE macros like CompPath
|
||||
- keywords
|
||||
- with standard macros
|
||||
- prefix with package name
|
||||
@ -80,8 +81,6 @@
|
||||
- when package is renamed, rename macros too
|
||||
|
||||
ToDo:
|
||||
- warn for macro name conflicts
|
||||
- IDE macros like CompPath
|
||||
- move the project target file to compiler options
|
||||
- discuss captions
|
||||
- resourcestrings
|
||||
|
@ -33,8 +33,9 @@ uses
|
||||
Buttons, ExtCtrls, Dialogs, ComCtrls, Menus, AvgLvlTree, IDEImagesIntf,
|
||||
KeywordFuncLists, CodeToolsCfgScript,
|
||||
SynEdit, SynHighlighterPas, SynEditKeyCmds,
|
||||
ProjectIntf, PackageIntf, CompilerOptions, IDEOptionsIntf, EditorOptions,
|
||||
LazarusIDEStrConsts, CompOptsModes, SourceSynEditor, PackageDefs;
|
||||
ProjectIntf, PackageIntf, CompilerOptions, IDEOptionsIntf, MacroIntf,
|
||||
EditorOptions, LazarusIDEStrConsts, CompOptsModes, SourceSynEditor,
|
||||
PackageDefs;
|
||||
|
||||
type
|
||||
TCBMNodeType = (
|
||||
@ -291,6 +292,7 @@ var
|
||||
BetterName: String;
|
||||
DlgResult: TModalResult;
|
||||
Vars: TCTCfgScriptVariables;
|
||||
ok: Boolean;
|
||||
begin
|
||||
NodeType:=GetNodeInfo(Node,BuildMacro);
|
||||
case NodeType of
|
||||
@ -298,73 +300,80 @@ begin
|
||||
cbmntBuildMacro:
|
||||
if S<>BuildMacro.Identifier then begin
|
||||
// rename build macro
|
||||
|
||||
// check syntax
|
||||
if (S='') or (not IsValidIdent(S)) then begin
|
||||
MessageDlg(lisCCOErrorCaption,
|
||||
Format(lisInvalidBuildMacroTheBuildMacroMustBeAPascalIdentifie, ['"',
|
||||
S, '"']),
|
||||
mtError,[mbCancel],0);
|
||||
S:=BuildMacro.Identifier;
|
||||
exit;
|
||||
end;
|
||||
|
||||
// check for prefix
|
||||
Prefix:=GetMacroNamePrefix(cbmpShort);
|
||||
if (Prefix<>'') and (SysUtils.CompareText(Prefix,copy(S,1,length(Prefix)))<>0)
|
||||
then begin
|
||||
BetterName:=GetMacroNamePrefix(cbmpMedium)+S;
|
||||
DlgResult:=QuestionDlg('Warning',
|
||||
'The build macro "'+S+'" does not begin with "'+Prefix+'".',
|
||||
mtWarning,[mrCancel,mrYes,'Rename to '+BetterName,mrIgnore],0);
|
||||
if DlgResult=mrIgnore then begin
|
||||
end else if DlgResult=mrYes then
|
||||
S:=BetterName
|
||||
else begin
|
||||
S:=BuildMacro.Identifier;
|
||||
ok:=false;
|
||||
try
|
||||
// check syntax
|
||||
if (S='') or (not IsValidIdent(S)) then begin
|
||||
MessageDlg(lisCCOErrorCaption,
|
||||
Format(lisInvalidBuildMacroTheBuildMacroMustBeAPascalIdentifie, ['"',
|
||||
S, '"']),
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
// check for keyword
|
||||
if WordIsKeyWord.DoItCaseInsensitive(S) then begin
|
||||
MessageDlg(lisCCOErrorCaption,
|
||||
Format(lisInvalidBuildMacroTheNameIsAKeyword, [S]),
|
||||
mtError,[mbCancel],0);
|
||||
S:=BuildMacro.Identifier;
|
||||
exit;
|
||||
end;
|
||||
|
||||
// check for duplicates
|
||||
ConflictBuildProperty:=BuildMacros.VarWithIdentifier(S);
|
||||
if ((ConflictBuildProperty<>nil) and (ConflictBuildProperty<>BuildMacro))
|
||||
or (SysUtils.CompareText('TargetOS',S)=0)
|
||||
or (SysUtils.CompareText('TargetCPU',S)=0)
|
||||
or (SysUtils.CompareText('LCLWidgetType',S)=0)
|
||||
then begin
|
||||
MessageDlg(lisCCOErrorCaption,
|
||||
Format(lisThereIsAlreadyABuildMacroWithTheName, ['"', S, '"']),
|
||||
mtError,[mbCancel],0);
|
||||
S:=BuildMacro.Identifier;
|
||||
exit;
|
||||
end;
|
||||
|
||||
// check for duplicates with used packages
|
||||
if (BuildMacros<>nil) and (BuildMacros.Owner is TBaseCompilerOptions) then
|
||||
begin
|
||||
Vars:=GetBuildMacroValues(TBaseCompilerOptions(BuildMacros.Owner),false);
|
||||
if (Vars<>nil) and Vars.IsDefined(PChar(S)) then begin
|
||||
DlgResult:=MessageDlg('Warning',
|
||||
Format(lisThereIsAlreadyABuildMacroWithTheName, ['"', S, '"']),
|
||||
mtWarning,[mbCancel,mbIgnore],0);
|
||||
if DlgResult<>mrIgnore then
|
||||
begin
|
||||
S:=BuildMacro.Identifier;
|
||||
// check for prefix
|
||||
Prefix:=GetMacroNamePrefix(cbmpShort);
|
||||
if (Prefix<>'') and (SysUtils.CompareText(Prefix,copy(S,1,length(Prefix)))<>0)
|
||||
then begin
|
||||
BetterName:=GetMacroNamePrefix(cbmpMedium)+S;
|
||||
DlgResult:=QuestionDlg('Warning',
|
||||
'The build macro "'+S+'" does not begin with "'+Prefix+'".',
|
||||
mtWarning,[mrCancel,mrYes,'Rename to '+BetterName,mrIgnore],0);
|
||||
if DlgResult=mrIgnore then begin
|
||||
end else if DlgResult=mrYes then
|
||||
S:=BetterName
|
||||
else begin
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
// check for keyword
|
||||
if WordIsKeyWord.DoItCaseInsensitive(S) then begin
|
||||
MessageDlg(lisCCOErrorCaption,
|
||||
Format(lisInvalidBuildMacroTheNameIsAKeyword, [S]),
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
// check for conflicts with built-in macros
|
||||
if IDEMacros.IsMacro(s) then begin
|
||||
MessageDlg(lisCCOErrorCaption,
|
||||
Format(lisThereIsAlreadyAnIDEMacroWithTheName, [S]),
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
// check for duplicates
|
||||
ConflictBuildProperty:=BuildMacros.VarWithIdentifier(S);
|
||||
if ((ConflictBuildProperty<>nil) and (ConflictBuildProperty<>BuildMacro))
|
||||
or (SysUtils.CompareText('TargetOS',S)=0)
|
||||
or (SysUtils.CompareText('TargetCPU',S)=0)
|
||||
or (SysUtils.CompareText('LCLWidgetType',S)=0)
|
||||
then begin
|
||||
MessageDlg(lisCCOErrorCaption,
|
||||
Format(lisThereIsAlreadyABuildMacroWithTheName, ['"', S, '"']),
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
// check for duplicates with used packages
|
||||
if (BuildMacros<>nil) and (BuildMacros.Owner is TBaseCompilerOptions) then
|
||||
begin
|
||||
Vars:=GetBuildMacroValues(TBaseCompilerOptions(BuildMacros.Owner),false);
|
||||
if (Vars<>nil) and Vars.IsDefined(PChar(S)) then begin
|
||||
DlgResult:=MessageDlg('Warning',
|
||||
Format(lisThereIsAlreadyABuildMacroWithTheName, ['"', S, '"']),
|
||||
mtWarning,[mbCancel,mbIgnore],0);
|
||||
if DlgResult<>mrIgnore then
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
ok:=true;
|
||||
finally
|
||||
if not ok then
|
||||
S:=BuildMacro.Identifier;
|
||||
end;
|
||||
|
||||
// rename build macro
|
||||
BuildMacro.Identifier:=S;
|
||||
|
@ -1897,6 +1897,8 @@ resourcestring
|
||||
dlgCCOTestMissingPPU = 'Test: Checking missing fpc ppu ...';
|
||||
dlgCCOTestCompilerDate = 'Test: Checking compiler date ...';
|
||||
lisCCOErrorCaption = 'Error';
|
||||
lisThereIsAlreadyAnIDEMacroWithTheName = 'There is already an IDE macro '
|
||||
+'with the name "%s"';
|
||||
lisInvalidLineColumnInMessage = 'Invalid line, column in message%s%s';
|
||||
lisUnableToLoadFile = 'Unable to load file:%s%s';
|
||||
lisQuickFixRemoveUnit = 'Quick fix: Remove unit';
|
||||
|
@ -117,6 +117,7 @@ type
|
||||
public
|
||||
function StrHasMacros(const s: string): boolean; override;
|
||||
function SubstituteMacros(var s: string): boolean; override;
|
||||
function IsMacro(const Name: string): boolean; override;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -573,6 +574,11 @@ begin
|
||||
Result:=GlobalMacroList.SubstituteStr(s);
|
||||
end;
|
||||
|
||||
function TLazIDEMacros.IsMacro(const Name: string): boolean;
|
||||
begin
|
||||
Result:=GlobalMacroList.FindByName(Name)<>nil;
|
||||
end;
|
||||
|
||||
procedure InternalInit;
|
||||
var
|
||||
c: char;
|
||||
|
@ -37,6 +37,7 @@ type
|
||||
procedure IncreaseGraphStamp;
|
||||
function StrHasMacros(const s: string): boolean; virtual;
|
||||
function SubstituteMacros(var s: string): boolean; virtual;
|
||||
function IsMacro(const Name: string): boolean; virtual;
|
||||
// file utility functions
|
||||
function CreateAbsoluteSearchPath(var SearchPath: string;
|
||||
const BaseDirectory: string): boolean;
|
||||
@ -117,6 +118,12 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TIDEMacros.IsMacro(const Name: string): boolean;
|
||||
begin
|
||||
if Name='' then ;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TIDEMacros.CreateAbsoluteSearchPath(var SearchPath: string;
|
||||
const BaseDirectory: string): boolean;
|
||||
var
|
||||
|
Loading…
Reference in New Issue
Block a user