IDE: Load and save all compiler options.

git-svn-id: trunk@42144 -
This commit is contained in:
juha 2013-07-20 07:03:50 +00:00
parent e5edeb10ad
commit 3b6537c967
4 changed files with 126 additions and 29 deletions

View File

@ -253,6 +253,7 @@ type
fCustomConfigFile: Boolean;
fConfigFilePath: String;
protected
function GetAllOptions: TStrings; virtual; abstract;
function GetCustomOptions: string; virtual; abstract;
function GetDebugPath: string; virtual; abstract;
function GetIncludePaths: String; virtual; abstract;
@ -265,6 +266,7 @@ type
procedure SetCompilerPath(const AValue: String); virtual; abstract;
procedure SetConditionals(const AValue: string); virtual; abstract;
procedure SetCustomOptions(const AValue: string); virtual; abstract;
//procedure SetAllOptions(const AValue: TStrings); virtual; abstract;
procedure SetDebugPath(const AValue: string); virtual; abstract;
procedure SetIncludePaths(const AValue: String); virtual; abstract;
procedure SetLibraryPaths(const AValue: String); virtual; abstract;
@ -409,16 +411,14 @@ type
property ShowHintsForSenderNotUsed: Boolean
read fShowHintsForSenderNotUsed write SetShowHintsForSenderNotUsed;
property WriteFPCLogo: Boolean read fWriteFPCLogo write SetWriteFPCLogo;
property StopAfterErrCount: integer
read fStopAfterErrCount write SetStopAfterErrCount;
property StopAfterErrCount: integer read fStopAfterErrCount write SetStopAfterErrCount;
// other
property DontUseConfigFile: Boolean read fDontUseConfigFile
write SetDontUseConfigFile;
property CustomConfigFile: Boolean read fCustomConfigFile
write SetCustomConfigFile;
property DontUseConfigFile: Boolean read fDontUseConfigFile write SetDontUseConfigFile;
property CustomConfigFile: Boolean read fCustomConfigFile write SetCustomConfigFile;
property ConfigFilePath: String read fConfigFilePath write SetConfigFilePath;
property CustomOptions: string read GetCustomOptions write SetCustomOptions;
property AllOptions: TStrings read GetAllOptions; // write SetAllOptions;
// execute other
procedure SetAlternativeCompile(const Command: string; ScanFPCMsgs: boolean); virtual; abstract; // disable normal compile and call this instead

View File

@ -183,6 +183,7 @@ type
destructor Destroy; override;
function ReadAndParseOptions: TModalResult;
function FilterOptions(aFilter: string): Boolean;
function CopyNonDefaultOptions(aStrings: TStrings): integer;
public
property SupportedCategories: TStringList read fSupportedCategories;
property RootOptGroup: TCompilerOptGroup read fRootOptGroup;
@ -761,5 +762,38 @@ begin
Result := FilterOptionsSub(fRootOptGroup);
end;
function TCompilerOptReader.CopyNonDefaultOptions(aStrings: TStrings): integer;
// Copy options to a list if they have a non-default value (True for boolean).
function CopyOptionsSub(aRoot: TCompilerOpt): integer;
var
Children: TCompilerOptList;
i, Res: Integer;
s: string;
begin
if aRoot is TCompilerOptGroup then
begin
Children := TCompilerOptGroup(aRoot).CompilerOpts;
if aRoot is TCompilerOptSet then
begin // TCompilerOptSet
for i := 0 to Children.Count-1 do // Collect subitems of a set to one option.
s := s + TCompilerOpt(Children[i]).Option;
aStrings.Add(s);
end
else begin // TCompilerOptGroup
for i := 0 to Children.Count-1 do // Recursive call for children.
Res := CopyOptionsSub(TCompilerOpt(Children[i]));
end;
end
else begin // TCompilerOpt
aStrings.Add(aRoot.Option);
end;
Result := Res;
end;
begin
Result := CopyOptionsSub(fRootOptGroup);
end;
end.

View File

@ -434,6 +434,21 @@ const
type
TBaseCompilerOptions = class;
{ TAllOptionsList }
TAllOptionsList = class(TStringList)
private
FOwner: TBaseCompilerOptions;
protected
procedure InsertItem(Index: Integer; const S: string); override;
public
constructor Create(AOwner: TBaseCompilerOptions);
destructor Destroy; override;
procedure Delete(Index: Integer); override;
end;
{ TBaseCompilerOptions }
TBaseCompilerOptions = class(TLazCompilerOptions)
@ -443,6 +458,7 @@ type
fInheritedOptParseStamps: integer;
FParsedOpts: TParsedCompilerOptions;
FStorePathDelim: TPathDelimSwitch;
FAllOptions: TAllOptionsList;
// Compilation
fExecuteBefore: TCompilationToolOptions;
@ -458,6 +474,7 @@ type
procedure OnItemChanged(Sender: TObject);
procedure SetCreateMakefileOnBuild(AValue: boolean);
protected
function GetAllOptions: TStrings; override;
function GetCompilerPath: String;
function GetBaseDirectory: string;
function GetCustomOptions: string; override;
@ -1053,6 +1070,32 @@ begin
end;
{ TAllOptionsList }
constructor TAllOptionsList.Create(AOwner: TBaseCompilerOptions);
begin
inherited Create;
FOwner:=AOwner;
end;
destructor TAllOptionsList.Destroy;
begin
inherited Destroy;
end;
procedure TAllOptionsList.InsertItem(Index: Integer; const S: string);
begin
inherited InsertItem(Index, S);
FOwner.IncreaseChangeStamp;
end;
procedure TAllOptionsList.Delete(Index: Integer);
begin
inherited Delete(Index);
FOwner.IncreaseChangeStamp;
end;
{ TBaseCompilerOptions }
{------------------------------------------------------------------------------
@ -1063,13 +1106,14 @@ constructor TBaseCompilerOptions.Create(const AOwner: TObject;
begin
inherited Create(AOwner);
FParsedOpts := TParsedCompilerOptions.Create(Self);
FAllOptions := TAllOptionsList.Create(Self);
FExecuteBefore := AToolClass.Create(Self);
FExecuteBefore.OnChanged:=@OnItemChanged;
FExecuteBefore.OnChanged := @OnItemChanged;
FExecuteAfter := AToolClass.Create(Self);
fExecuteAfter.OnChanged:=@OnItemChanged;
fExecuteAfter.OnChanged := @OnItemChanged;
fBuildMacros := TIDEBuildMacros.Create(Self);
FCompilerMessages:=TCompilerMessagesList.Create;
FCompilerMessages.OnChanged:=@OnItemChanged;
FCompilerMessages.OnChanged := @OnItemChanged;
Clear;
end;
@ -1087,6 +1131,7 @@ begin
FreeAndNil(fBuildMacros);
FreeThenNil(fExecuteBefore);
FreeThenNil(fExecuteAfter);
FreeThenNil(FAllOptions);
FreeThenNil(FParsedOpts);
inherited Destroy;
end;
@ -1238,6 +1283,11 @@ begin
IncreaseChangeStamp;
end;
function TBaseCompilerOptions.GetAllOptions: TStrings;
begin
Result:=FAllOptions;
end;
function TBaseCompilerOptions.GetCompilerPath: String;
begin
Result:=ParsedOpts.Values[pcosCompilerPath].UnparsedValue;
@ -1357,10 +1407,10 @@ end;
procedure TBaseCompilerOptions.LoadFromXMLConfig(AXMLConfig: TXMLConfig;
const Path: string);
var
p: String;
p, s: String;
b, PathDelimChange: boolean;
FileVersion: Integer;
i: LongInt;
i, Cnt: LongInt;
dit: TCompilerDbgSymbolType;
function f(const Filename: string): string;
@ -1571,14 +1621,13 @@ begin
with aXMLConfig do begin
// ErrorNames should be stored, because the Message file is not read (or parsed)
// on project opening. So errors needs to be initialized properly from the CompilerOptions.xml
fCompilerMessages.fErrorNames[etHint]:=GetValue(p+'fCompilerMessages/ErrorNames/Hint', FPCErrorTypeNames[etHint]);
fCompilerMessages.fErrorNames[etNote]:=GetValue(p+'fCompilerMessages/ErrorNames/Note', FPCErrorTypeNames[etNote]);
fCompilerMessages.fErrorNames[etWarning]:=GetValue(p+'fCompilerMessages/ErrorNames/Warning', FPCErrorTypeNames[etWarning]);
fCompilerMessages.fErrorNames[etError]:=GetValue(p+'fCompilerMessages/ErrorNames/Error', FPCErrorTypeNames[etError]);
fCompilerMessages.fErrorNames[etFatal]:=GetValue(p+'fCompilerMessages/ErrorNames/Fatal', FPCErrorTypeNames[etFatal]);
fCompilerMessages.fErrorNames[etHint] :=GetValue(p+'CompilerMessages/ErrorNames/Hint', FPCErrorTypeNames[etHint]);
fCompilerMessages.fErrorNames[etNote] :=GetValue(p+'CompilerMessages/ErrorNames/Note', FPCErrorTypeNames[etNote]);
fCompilerMessages.fErrorNames[etWarning]:=GetValue(p+'CompilerMessages/ErrorNames/Warning', FPCErrorTypeNames[etWarning]);
fCompilerMessages.fErrorNames[etError] :=GetValue(p+'CompilerMessages/ErrorNames/Error', FPCErrorTypeNames[etError]);
fCompilerMessages.fErrorNames[etFatal] :=GetValue(p+'CompilerMessages/ErrorNames/Fatal', FPCErrorTypeNames[etFatal]);
end;
{ Other }
p:=Path+'Other/';
DontUseConfigFile := aXMLConfig.GetValue(p+'ConfigFile/DontUseConfigFile/Value', false);
@ -1588,6 +1637,14 @@ begin
CustomConfigFile := aXMLConfig.GetValue(p+'ConfigFile/CustomConfigFile/Value', false);
ConfigFilePath := f(aXMLConfig.GetValue(p+'ConfigFile/ConfigFilePath/Value', 'extrafpc.cfg'));
CustomOptions := LineBreaksToSystemLineBreaks(aXMLConfig.GetValue(p+'CustomOptions/Value', ''));
// All options
AllOptions.Clear;
Cnt:=aXMLConfig.GetValue(p+'AllOptions/Count', 0);
for i:=0 to Cnt-1 do begin
s:=aXMLConfig.GetValue(p+'AllOptions/Item'+IntToStr(i)+'/', '');
if s<>'' then
AllOptions.Add(s);
end;
{ Compilation }
CompilerPath := f(aXMLConfig.GetValue(p+'CompilerPath/Value','$(CompPath)'));
@ -1772,6 +1829,10 @@ begin
aXMLConfig.SetDeleteValue(p+'ConfigFile/ConfigFilePath/Value', f(ConfigFilePath),'extrafpc.cfg');
aXMLConfig.SetDeleteValue(p+'CustomOptions/Value',
LineBreaksToSystemLineBreaks(CustomOptions),''); // do not touch / \ characters
// All options
aXMLConfig.SetDeleteValue(p+'AllOptions/Count', AllOptions.Count, 0);
for i:=0 to AllOptions.Count-1 do
aXMLConfig.SetDeleteValue(p+'AllOptions/Item'+IntToStr(i)+'/', AllOptions[i], '');
{ Compilation }
aXMLConfig.SetDeleteValue(p+'CompilerPath/Value', f(CompilerPath),'');
@ -1779,7 +1840,6 @@ begin
ExecuteAfter.SaveToXMLConfig(aXMLConfig,p+'ExecuteAfter/',UsePathDelim);
aXMLConfig.SetDeleteValue(p+'CreateMakefileOnBuild/Value',
CreateMakefileOnBuild,false);
// write
Modified := False;
end;
@ -3724,8 +3784,7 @@ begin
end;
end;
function TAdditionalCompilerOptions.
GetBaseCompilerOptions: TBaseCompilerOptions;
function TAdditionalCompilerOptions.GetBaseCompilerOptions: TBaseCompilerOptions;
begin
Result:=nil;
end;

View File

@ -835,14 +835,6 @@ begin
FIsPackage := CompOptions is TPkgCompilerOptions;
//debugln(['TCompilerOtherOptionsFrame.ReadSettings ',dbgs(Pointer(FCompOptions)),' ',FCompOptions=Project1.CompilerOptions]);
edCustomOptions.Text := CompOptions.CustomOptions;
Vars := GetBuildMacroValues(CompOptions,false);
if Vars<>nil then
DefaultVariables.Assign(Vars)
else
DefaultVariables.Clear;
CondSynEdit.Lines.Text := CompOptions.Conditionals;
if FHighlighter=nil then
begin
@ -851,6 +843,18 @@ begin
end;
EditorOpts.ReadHighlighterSettings(FHighlighter, '');
EditorOpts.GetSynEditSettings(CondSynEdit);
Vars := GetBuildMacroValues(CompOptions,false);
if Vars<>nil then
DefaultVariables.Assign(Vars)
else
DefaultVariables.Clear;
// Custom Options
edCustomOptions.Text := CompOptions.CustomOptions;
// All Options
FOptionsReader.CopyNonDefaultOptions(CompOptions.AllOptions);
UpdateStatusBar;
end;
@ -862,8 +866,8 @@ begin
CurOptions := AOptions as TBaseCompilerOptions;
with CurOptions do
begin
CustomOptions := edCustomOptions.Text;
Conditionals := CondSynEdit.Lines.Text;
CustomOptions := edCustomOptions.Text;
end;
end;