mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 09:29:10 +02:00
IDE: preliminary work to react to changed target in GUI when reading all FPC options.
git-svn-id: trunk@43589 -
This commit is contained in:
parent
8109841ef9
commit
a6c7aca804
@ -140,6 +140,7 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(aOwnerGroup: TCompilerOptGroup);
|
constructor Create(aOwnerGroup: TCompilerOptGroup);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure Clear;
|
||||||
function FindOption(aOptStr: string): TCompilerOpt;
|
function FindOption(aOptStr: string): TCompilerOpt;
|
||||||
function FindOptionById(aId: integer): TCompilerOpt;
|
function FindOptionById(aId: integer): TCompilerOpt;
|
||||||
function SelectOption(aOptAndValue: string): Boolean;
|
function SelectOption(aOptAndValue: string): Boolean;
|
||||||
@ -177,6 +178,7 @@ type
|
|||||||
fRootOptGroup: TCompilerOptGroup;
|
fRootOptGroup: TCompilerOptGroup;
|
||||||
fCompilerExecutable: string; // Copiler path must be set by caller.
|
fCompilerExecutable: string; // Copiler path must be set by caller.
|
||||||
fCompilerVersion: string; // Parsed from "fpc -h".
|
fCompilerVersion: string; // Parsed from "fpc -h".
|
||||||
|
fParsedTarget: String;
|
||||||
fErrorMsg: String;
|
fErrorMsg: String;
|
||||||
procedure ReadVersion(s: string);
|
procedure ReadVersion(s: string);
|
||||||
procedure AddGroupItems(aGroup: TCompilerOptGroup; aItems: TStrings);
|
procedure AddGroupItems(aGroup: TCompilerOptGroup; aItems: TStrings);
|
||||||
@ -185,6 +187,8 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure Clear;
|
||||||
|
function UpdateTargetParam: Boolean;
|
||||||
function ReadAndParseOptions: TModalResult;
|
function ReadAndParseOptions: TModalResult;
|
||||||
function FilterOptions(aFilter: string; aOnlySelected: Boolean): Boolean;
|
function FilterOptions(aFilter: string; aOnlySelected: Boolean): Boolean;
|
||||||
function FindOptionById(aId: integer): TCompilerOpt;
|
function FindOptionById(aId: integer): TCompilerOpt;
|
||||||
@ -195,6 +199,7 @@ type
|
|||||||
property SupportedCategories: TStringList read fSupportedCategories;
|
property SupportedCategories: TStringList read fSupportedCategories;
|
||||||
property RootOptGroup: TCompilerOptGroup read fRootOptGroup;
|
property RootOptGroup: TCompilerOptGroup read fRootOptGroup;
|
||||||
property CompilerExecutable: string read fCompilerExecutable write fCompilerExecutable;
|
property CompilerExecutable: string read fCompilerExecutable write fCompilerExecutable;
|
||||||
|
property ParsedTarget: String read fParsedTarget write fParsedTarget;
|
||||||
property ErrorMsg: String read fErrorMsg write fErrorMsg;
|
property ErrorMsg: String read fErrorMsg write fErrorMsg;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -555,6 +560,11 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCompilerOptGroup.Clear;
|
||||||
|
begin
|
||||||
|
fCompilerOpts.Clear;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCompilerOptGroup.FindOption(aOptStr: string): TCompilerOpt;
|
function TCompilerOptGroup.FindOption(aOptStr: string): TCompilerOpt;
|
||||||
|
|
||||||
function FindOptionSub(aRoot: TCompilerOpt): TCompilerOpt;
|
function FindOptionSub(aRoot: TCompilerOpt): TCompilerOpt;
|
||||||
@ -853,17 +863,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCompilerOptReader.Destroy;
|
destructor TCompilerOptReader.Destroy;
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
|
Clear;
|
||||||
fRootOptGroup.Free;
|
fRootOptGroup.Free;
|
||||||
for i := 0 to fSupportedCategories.Count-1 do
|
|
||||||
fSupportedCategories.Objects[i].Free;
|
|
||||||
fSupportedCategories.Free;
|
fSupportedCategories.Free;
|
||||||
fDefines.Free;
|
fDefines.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCompilerOptReader.Clear;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
fRootOptGroup.Clear;
|
||||||
|
for i := 0 to fSupportedCategories.Count-1 do
|
||||||
|
fSupportedCategories.Objects[i].Free;
|
||||||
|
fSupportedCategories.Clear;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCompilerOptReader.ParseI(aLines: TStringList): TModalResult;
|
function TCompilerOptReader.ParseI(aLines: TStringList): TModalResult;
|
||||||
const
|
const
|
||||||
Supported = 'Supported ';
|
Supported = 'Supported ';
|
||||||
@ -1011,23 +1028,33 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCompilerOptReader.UpdateTargetParam: Boolean;
|
||||||
|
// Updates target OS and CPU parameter using global macros.
|
||||||
|
// Returns true if the value has changed since last time.
|
||||||
|
var
|
||||||
|
NewTarget: string;
|
||||||
|
begin
|
||||||
|
NewTarget := '-T$(TargetOS) -P$(TargetCPU)';
|
||||||
|
if not GlobalMacroList.SubstituteStr(NewTarget) then
|
||||||
|
raise Exception.CreateFmt('ReadAndParseOptions: Cannot substitute macros "%s".',
|
||||||
|
[NewTarget]);
|
||||||
|
Result := fParsedTarget <> NewTarget;
|
||||||
|
if Result then
|
||||||
|
fParsedTarget := NewTarget; // fParsedTarget is used as a param for FPC.
|
||||||
|
end;
|
||||||
|
|
||||||
function TCompilerOptReader.ReadAndParseOptions: TModalResult;
|
function TCompilerOptReader.ReadAndParseOptions: TModalResult;
|
||||||
// fpc -Fr$(FPCMsgFile) -h
|
// fpc -Fr$(FPCMsgFile) -h
|
||||||
// fpc -Fr$(FPCMsgFile) -i
|
// fpc -Fr$(FPCMsgFile) -i
|
||||||
var
|
var
|
||||||
Lines: TStringList;
|
Lines: TStringList;
|
||||||
ParsedTarget: String;
|
|
||||||
begin
|
begin
|
||||||
OptionIdCounter := 0;
|
OptionIdCounter := 0;
|
||||||
fErrorMsg := '';
|
fErrorMsg := '';
|
||||||
if fCompilerExecutable = '' then
|
if fCompilerExecutable = '' then
|
||||||
fCompilerExecutable := 'fpc'; // Let's hope "fpc" is found in PATH.
|
fCompilerExecutable := 'fpc'; // Let's hope "fpc" is found in PATH.
|
||||||
ParsedTarget := '-T$(TargetOS) -P$(TargetCPU)';
|
|
||||||
if not GlobalMacroList.SubstituteStr(ParsedTarget) then
|
|
||||||
raise Exception.CreateFmt('ReadAndParseOptions: Cannot substitute macros "%s".',
|
|
||||||
[ParsedTarget]);
|
|
||||||
// FPC with option -i
|
// FPC with option -i
|
||||||
Lines:=RunTool(fCompilerExecutable, ParsedTarget + ' -i');
|
Lines:=RunTool(fCompilerExecutable, fParsedTarget + ' -i');
|
||||||
try
|
try
|
||||||
if Lines = Nil then Exit(mrCancel);
|
if Lines = Nil then Exit(mrCancel);
|
||||||
Result := ParseI(Lines);
|
Result := ParseI(Lines);
|
||||||
@ -1036,7 +1063,7 @@ begin
|
|||||||
Lines.Free;
|
Lines.Free;
|
||||||
end;
|
end;
|
||||||
// FPC with option -h
|
// FPC with option -h
|
||||||
Lines:=RunTool(fCompilerExecutable, ParsedTarget + ' -h');
|
Lines:=RunTool(fCompilerExecutable, fParsedTarget + ' -h');
|
||||||
try
|
try
|
||||||
if Lines = Nil then Exit(mrCancel);
|
if Lines = Nil then Exit(mrCancel);
|
||||||
Result := ParseH(Lines);
|
Result := ParseH(Lines);
|
||||||
@ -1180,6 +1207,7 @@ begin
|
|||||||
inherited Create(True);
|
inherited Create(True);
|
||||||
//FreeOnTerminate:=True;
|
//FreeOnTerminate:=True;
|
||||||
fReader:=aReader;
|
fReader:=aReader;
|
||||||
|
fReader.UpdateTargetParam;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCompilerOptThread.Destroy;
|
destructor TCompilerOptThread.Destroy;
|
||||||
|
@ -358,11 +358,22 @@ procedure TCompilerOtherOptionsFrame.SetVisible(Value: Boolean);
|
|||||||
begin
|
begin
|
||||||
inherited SetVisible(Value);
|
inherited SetVisible(Value);
|
||||||
// Read all compiler options when the page is shown for the first time.
|
// Read all compiler options when the page is shown for the first time.
|
||||||
if Value and (FOptionsReader.RootOptGroup.CompilerOpts.Count = 0)
|
if Value then begin
|
||||||
and not Assigned(fOptionsThread) then
|
if Assigned(fOptionsThread) then
|
||||||
begin
|
begin
|
||||||
fOptionsThread := TCompilerOptThread.Create(FOptionsReader);
|
fOptionsThread.WaitFor; // Make sure the thread has finished running.
|
||||||
fOptionsThread.Start;
|
if FOptionsReader.UpdateTargetParam then begin
|
||||||
|
// Does not happen because UpdateTargetParam uses global macros
|
||||||
|
// which change only after closing the options window.
|
||||||
|
// This code is here for future refactoring, to react to changed target in GUI.
|
||||||
|
FOptionsReader.Clear;
|
||||||
|
fOptionsThread.Start; // Read new options.
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
fOptionsThread := TCompilerOptThread.Create(FOptionsReader);
|
||||||
|
fOptionsThread.Start;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user