diff --git a/ide/compileroptions.pp b/ide/compileroptions.pp index 0980f74d6c..8e529f9ae6 100644 --- a/ide/compileroptions.pp +++ b/ide/compileroptions.pp @@ -67,15 +67,17 @@ any conditionals - using conditionals to extend paths: TParsedCompilerOptions.GetUnparsedWithConditionals - using conditionals to extend package usage paths: TParsedCompilerOptions.GetUnparsedWithConditionals + - conditionals editor for project + - warn for macro name conflicts + - on renaming + - keywords + - with standard macros + - prefix with package name + - with macros from other packages/projects ToDo: - - conditionals for project - warn for macro name conflicts - - keywords - - with macros from other packages/projects - - with standard macros - - on renaming - - on loading + - on loading - when package is renamed, rename macros too - show build macros in inherited compiler options - use syntax highlighter settings like the editor previews diff --git a/ide/compileroptionsdlg.pp b/ide/compileroptionsdlg.pp index 138879144a..b05b35cd3a 100644 --- a/ide/compileroptionsdlg.pp +++ b/ide/compileroptionsdlg.pp @@ -781,7 +781,6 @@ begin edtErrorCnt.Text := IntToStr(Options.StopAfterErrCount); // conditionals + build macros - debugln(['TfrmCompilerOptions.LoadOptionsToForm ']); {$IFDEF EnableBuildModes} BuildMacrosFrame.LoadFromOptions(Options); {$ENDIF} diff --git a/ide/frames/compiler_buildmacro_options.pas b/ide/frames/compiler_buildmacro_options.pas index 467f1b5183..c4709c8de8 100644 --- a/ide/frames/compiler_buildmacro_options.pas +++ b/ide/frames/compiler_buildmacro_options.pas @@ -31,6 +31,7 @@ interface uses Classes, SysUtils, LCLProc, FileUtil, Controls, Forms, StdCtrls, Grids, Buttons, ExtCtrls, Dialogs, ComCtrls, Menus, AvgLvlTree, IDEImagesIntf, + KeywordFuncLists, CodeToolsCfgScript, ProjectIntf, PackageIntf, CompilerOptions, IDEOptionsIntf, LazarusIDEStrConsts, CompOptsModes, PackageDefs, SynEdit, SynHighlighterPas; @@ -40,6 +41,11 @@ type cbmntBuildMacro, cbmntValue ); + TCBMPrefixType = ( + cbmpShort, + cbmpMedium, + cbmpLong + ); { TCompOptBuildMacrosFrame } @@ -80,7 +86,7 @@ type function GetSelectedNode(out aBuildMacro: TLazBuildMacro; out NodeType: TCBMNodeType): TTreeNode; function GetBuildMacroTVNode(aBuildMacro: TLazBuildMacro): TTreeNode; - function GetMacroNamePrefix: string; + function GetMacroNamePrefix(PrefixType: TCBMPrefixType): string; procedure UpdateItemPropertyControls; public constructor Create(TheOwner: TComponent); override; @@ -110,7 +116,7 @@ var begin i:=1; repeat - NewIdentifier:=GetMacroNamePrefix+IntToStr(BuildMacros.Count+1); + NewIdentifier:=GetMacroNamePrefix(cbmpLong)+IntToStr(BuildMacros.Count+1); if BuildMacros.IndexOfIdentifier(NewIdentifier)<0 then break; inc(i); until false; @@ -248,6 +254,10 @@ var NodeType: TCBMNodeType; ConflictBuildProperty: TIDEBuildMacro; Index: LongInt; + Prefix: String; + BetterName: String; + DlgResult: TModalResult; + Vars: TCTCfgScriptVariables; begin NodeType:=GetNodeInfo(Node,BuildMacro); case NodeType of @@ -255,6 +265,8 @@ 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, ['"', @@ -263,15 +275,65 @@ begin 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; + 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) then - begin + 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; + exit; + end; + end; + end; + + + // rename build macro BuildMacro.Identifier:=S; end; @@ -387,12 +449,23 @@ begin Result:=Result.GetNextSibling; end; -function TCompOptBuildMacrosFrame.GetMacroNamePrefix: string; +function TCompOptBuildMacrosFrame.GetMacroNamePrefix(PrefixType: TCBMPrefixType + ): string; begin - Result:='BuildMacro'; + if PrefixType=cbmpShort then + Result:='' + else + Result:='BuildMacro'; if (BuildMacros=nil) or (BuildMacros.Owner=nil) then exit; if BuildMacros.Owner is TPkgCompilerOptions then - Result:=TPkgCompilerOptions(BuildMacros.Owner).LazPackage.Name+'_macro'; + begin + Result:=TPkgCompilerOptions(BuildMacros.Owner).LazPackage.Name; + if ord(PrefixType)>=ord(cbmpMedium) then + Result:=Result+'_'; + if PrefixType=cbmpLong then + Result:=Result+'macro'; + end; + end; procedure TCompOptBuildMacrosFrame.UpdateItemPropertyControls; diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index b85dff2cde..e1293d1ef6 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -4872,6 +4872,8 @@ resourcestring lisCustomBuildMacros = 'Custom build macros'; lisCanNotCompileProject = 'Cannot compile project'; lisTheProjectHasNoMainSourceFile = 'The project has no main source file.'; + lisInvalidBuildMacroTheNameIsAKeyword = 'Invalid build macro "%s". The name ' + +'is a keyword.'; implementation