IDE: removed buildmodeflagtype

git-svn-id: trunk@25563 -
This commit is contained in:
mattias 2010-05-21 12:25:53 +00:00
parent db7ac79d9e
commit f3e19f4829
4 changed files with 49 additions and 164 deletions

View File

@ -78,21 +78,6 @@ type
procedure SetDefaultValue(const AValue: string); override; procedure SetDefaultValue(const AValue: string); override;
end; end;
type
TBuildModeFlagType = (
bmftNone,
bmftAddUnitPath,
bmftAddIncludePath,
bmftAddLinkerPath,
bmftAddObjectPath,
bmftAddLinkerOption,
bmftAddCustomOption,
bmftSetVariable
);
TBuildModeFlagTypes = set of TBuildModeFlagType;
const
BuildModeFlagPaths = [bmftAddUnitPath,bmftAddIncludePath,bmftAddLinkerPath,bmftAddObjectPath];
type type
TBuildModeGraph = class; TBuildModeGraph = class;
@ -138,7 +123,6 @@ type
TBuildModeFlag = class(TPersistent) TBuildModeFlag = class(TPersistent)
private private
FFlagType: TBuildModeFlagType;
FValue: string; FValue: string;
FVariable: string; FVariable: string;
public public
@ -151,7 +135,6 @@ type
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string; procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string;
UsePathDelim: TPathDelimSwitch); UsePathDelim: TPathDelimSwitch);
public public
property FlagType: TBuildModeFlagType read FFlagType write FFlagType;
property Value: string read FValue write FValue; property Value: string read FValue write FValue;
property Variable: string read FVariable write FVariable; property Variable: string read FVariable write FVariable;
end; end;
@ -188,10 +171,9 @@ type
procedure Include(aMode: TBuildMode); procedure Include(aMode: TBuildMode);
procedure Exclude(aMode: TBuildMode); procedure Exclude(aMode: TBuildMode);
function IsIncludedBy(aMode: TBuildMode): boolean; function IsIncludedBy(aMode: TBuildMode): boolean;
function AddFlag(FlagType: TBuildModeFlagType; Value: string; function AddFlag(Value: string; Variable: string = ''): TBuildModeFlag;
Variable: string = ''): TBuildModeFlag; function InsertFlag(InsertPos: integer;
function InsertFlag(InsertPos: integer; FlagType: TBuildModeFlagType; Value: string; Variable: string = ''): TBuildModeFlag;
Value: string; Variable: string = ''): TBuildModeFlag;
procedure DeleteFlag(Index: integer); procedure DeleteFlag(Index: integer);
procedure Assign(Source: TPersistent); override; // copy without Name procedure Assign(Source: TPersistent); override; // copy without Name
function IsEqual(aMode: TBuildMode): boolean; function IsEqual(aMode: TBuildMode): boolean;
@ -834,18 +816,6 @@ const
symItem = '$Item'; symItem = '$Item';
symLineNo = '$LineNum'; symLineNo = '$LineNum';
const
BuildModeFlagTypeNames: array[TBuildModeFlagType] of string = (
'None',
'AddUnitPath',
'AddIncludePath',
'AddLinkerPath',
'AddObjectPath',
'AddLinkerOption',
'AddCustomOption',
'SetVariable'
);
function StrToBuildModeFlagType(const s: string): TBuildModeFlagType;
var var
TestCompilerOptions: TNotifyEvent = nil; TestCompilerOptions: TNotifyEvent = nil;
@ -1110,13 +1080,6 @@ begin
AConfig.SetDeleteValue(APath+'Run', crRun in AFlags, crRun in DefaultFlags); AConfig.SetDeleteValue(APath+'Run', crRun in AFlags, crRun in DefaultFlags);
end; end;
function StrToBuildModeFlagType(const s: string): TBuildModeFlagType;
begin
for Result:=Low(TBuildModeFlagType) to high(TBuildModeFlagType) do
if SysUtils.CompareText(s,BuildModeFlagTypeNames[Result])=0 then exit;
Result:=bmftNone;
end;
{ TBaseCompilerOptions } { TBaseCompilerOptions }
@ -5080,20 +5043,17 @@ begin
Result:=false; Result:=false;
end; end;
function TBuildMode.AddFlag(FlagType: TBuildModeFlagType; Value: string; function TBuildMode.AddFlag(Value: string; Variable: string): TBuildModeFlag;
Variable: string): TBuildModeFlag;
begin begin
Result:=InsertFlag(FlagCount,FlagType,Value,Variable); Result:=InsertFlag(FlagCount,Value,Variable);
end; end;
function TBuildMode.InsertFlag(InsertPos: integer; function TBuildMode.InsertFlag(InsertPos: integer; Value: string;
FlagType: TBuildModeFlagType; Value: string; Variable: string Variable: string): TBuildModeFlag;
): TBuildModeFlag;
begin begin
if (InsertPos<0) or (InsertPos>FlagCount) then if (InsertPos<0) or (InsertPos>FlagCount) then
RaiseGDBException(''); RaiseGDBException('');
Result:=TBuildModeFlag.Create; Result:=TBuildModeFlag.Create;
Result.FlagType:=FlagType;
Result.Value:=Value; Result.Value:=Value;
Result.Variable:=Variable; Result.Variable:=Variable;
FFlags.Insert(InsertPos,Result); FFlags.Insert(InsertPos,Result);
@ -5213,7 +5173,6 @@ var
begin begin
if Source is TBuildModeFlag then begin if Source is TBuildModeFlag then begin
Src:=TBuildModeFlag(Source); Src:=TBuildModeFlag(Source);
FFlagType:=Src.FFlagType;
FValue:=Src.FValue; FValue:=Src.FValue;
FVariable:=Src.FVariable; FVariable:=Src.FVariable;
end else end else
@ -5223,7 +5182,6 @@ end;
function TBuildModeFlag.IsEqual(aFlag: TBuildModeFlag): boolean; function TBuildModeFlag.IsEqual(aFlag: TBuildModeFlag): boolean;
begin begin
Result:=false; Result:=false;
if FFlagType<>aFlag.FFlagType then exit;
if FValue<>aFlag.FValue then exit; if FValue<>aFlag.FValue then exit;
if FVariable<>aFlag.FVariable then exit; if FVariable<>aFlag.FVariable then exit;
Result:=true; Result:=true;
@ -5232,25 +5190,14 @@ end;
procedure TBuildModeFlag.LoadFromXMLConfig(XMLConfig: TXMLConfig; procedure TBuildModeFlag.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string; DoSwitchPathDelims: boolean); const Path: string; DoSwitchPathDelims: boolean);
begin begin
FFlagType:=StrToBuildModeFlagType(XMLConfig.GetValue(Path+'Type',
BuildModeFlagTypeNames[bmftAddCustomOption]));
FValue:=XMLConfig.GetValue(Path+'Value',''); FValue:=XMLConfig.GetValue(Path+'Value','');
if FFlagType in BuildModeFlagPaths then
FValue:=SwitchPathDelims(FValue,DoSwitchPathDelims);
FVariable:=XMLConfig.GetValue(Path+'Variable',''); FVariable:=XMLConfig.GetValue(Path+'Variable','');
end; end;
procedure TBuildModeFlag.SaveToXMLConfig(XMLConfig: TXMLConfig; procedure TBuildModeFlag.SaveToXMLConfig(XMLConfig: TXMLConfig;
const Path: string; UsePathDelim: TPathDelimSwitch); const Path: string; UsePathDelim: TPathDelimSwitch);
var
s: String;
begin begin
XMLConfig.SetDeleteValue(Path+'Type',BuildModeFlagTypeNames[FFlagType], XMLConfig.SetDeleteValue(Path+'Value',FValue,'');
BuildModeFlagTypeNames[bmftAddCustomOption]);
s:=FValue;
if FFlagType in BuildModeFlagPaths then
SwitchPathDelims(FValue,UsePathDelim);
XMLConfig.SetDeleteValue(Path+'Value',s,'');
XMLConfig.SetDeleteValue(Path+'Variable',FVariable,''); XMLConfig.SetDeleteValue(Path+'Variable',FVariable,'');
end; end;

View File

@ -27,7 +27,8 @@
Author: Mattias Gaertner Author: Mattias Gaertner
Abstract: Abstract:
- compiler options depending on build modes and environment This unit contains the implementation of the conditional compiler options
that depend on build variables/modes and environment.
} }
unit CompOptsModes; unit CompOptsModes;

View File

@ -131,37 +131,10 @@ type
property Grid: TBuildModesGrid read FGrid; property Grid: TBuildModesGrid read FGrid;
end; end;
function BuildModeFlagTypeCaptions(f: TBuildModeFlagType): string;
function CaptionToBuildModeFlagType(s: string): TBuildModeFlagType;
implementation implementation
{$R *.lfm} {$R *.lfm}
function BuildModeFlagTypeCaptions(f: TBuildModeFlagType): string;
begin
case f of
bmftAddUnitPath: Result:='+UnitPath';
bmftAddIncludePath: Result:='+IncludePath';
bmftAddLinkerPath: Result:='+LinkerPath';
bmftAddObjectPath: Result:='+ObjectPath';
bmftAddLinkerOption: Result:='+LinkerOptions';
bmftAddCustomOption: Result:='+CustomOptions';
else Result:='';
end;
end;
function CaptionToBuildModeFlagType(s: string): TBuildModeFlagType;
begin
if s='' then exit(bmftNone);
for Result:=low(Result) to high(Result) do
if SysUtils.CompareText(s,BuildModeFlagTypeCaptions(Result))=0 then exit;
if IsValidIdent(s) then
Result:=bmftSetVariable
else
Result:=bmftNone;
end;
{ TBuildModesGrid } { TBuildModesGrid }
function TBuildModesGrid.GetModeRows(Index: integer): TBuildModeGridRow; function TBuildModesGrid.GetModeRows(Index: integer): TBuildModeGridRow;
@ -223,12 +196,8 @@ begin
TypeStr:=''; TypeStr:='';
ValueStr:=''; ValueStr:='';
if CurFlag<>nil then begin if CurFlag<>nil then begin
if CurFlag.FlagType=bmftSetVariable then TypeStr:=CurFlag.Variable;
begin ValueStr:=CurFlag.Value;
TypeStr:=CurFlag.Variable;
ValueStr:=CurFlag.Value;
end else
TypeStr:=BuildModeFlagTypeCaptions(CurFlag.FlagType);
end; end;
Cells[TypeCol,i]:=TypeStr; Cells[TypeCol,i]:=TypeStr;
Cells[ValueCol,i]:=ValueStr; Cells[ValueCol,i]:=ValueStr;
@ -257,7 +226,6 @@ var
CurModeRow: TBuildModeGridRow; CurModeRow: TBuildModeGridRow;
TypeCol: Integer; TypeCol: Integer;
ValueCol: Integer; ValueCol: Integer;
FlagType: TBuildModeFlagType;
begin begin
Result:=true; Result:=true;
if (aRow>=1) and (aRow<=ModeRowCount) then begin if (aRow>=1) and (aRow<=ModeRowCount) then begin
@ -285,19 +253,12 @@ begin
NewValue:=''; NewValue:='';
end else begin end else begin
NewValue:=SpecialCharsToSpaces(NewValue,true); NewValue:=SpecialCharsToSpaces(NewValue,true);
FlagType:=CaptionToBuildModeFlagType(NewValue); if (CurModeRow.Flag=nil) then begin
if (CurModeRow.Flag=nil) and (FlagType<>bmftNone) then begin
// create flag // create flag
CurModeRow.FFlag:=CurModeRow.Mode.AddFlag(FlagType,'',''); CurModeRow.FFlag:=CurModeRow.Mode.AddFlag('','');
end else if CurModeRow.Flag<>nil then end;
// set new FlagType // set variable name
CurModeRow.Flag.FlagType:=FlagType; CurModeRow.Flag.Variable:=NewValue;
if FlagType=bmftSetVariable then
// set variable name
CurModeRow.Flag.Variable:=NewValue
else
// clean up variable name
CurModeRow.Flag.Variable:='';
UpdateValuePickList; UpdateValuePickList;
end; end;
end else if ACol=ValueCol then begin end else if ACol=ValueCol then begin
@ -306,7 +267,7 @@ begin
NewValue:=''; NewValue:='';
end else begin end else begin
NewValue:=SpecialCharsToSpaces(NewValue,true); NewValue:=SpecialCharsToSpaces(NewValue,true);
if (CurModeRow.Flag=nil) or (CurModeRow.Flag.FlagType=bmftNone) then if (CurModeRow.Flag=nil) then
// no flag => no value // no flag => no value
NewValue:='' NewValue:=''
else else
@ -359,8 +320,6 @@ var
TypeCol: Integer; TypeCol: Integer;
i: Integer; i: Integer;
Node: TAvgLvlTreeNode; Node: TAvgLvlTreeNode;
t: TBuildModeFlagType;
s: String;
sl: TStringList; sl: TStringList;
begin begin
//DebugLn(['TBuildModesGrid.UpdateTypePickList ']); //DebugLn(['TBuildModesGrid.UpdateTypePickList ']);
@ -369,14 +328,6 @@ begin
Identifiers:=TStringToStringTree.Create(false); Identifiers:=TStringToStringTree.Create(false);
sl:=nil; sl:=nil;
try try
// add types
for t:=low(TBuildModeFlagType) to high(TBuildModeFlagType) do
begin
s:=BuildModeFlagTypeCaptions(t);
if s<>'' then
Identifiers[s]:='';
end;
// add standard variable names // add standard variable names
Identifiers['TargetOS']:=''; Identifiers['TargetOS']:='';
Identifiers['TargetCPU']:=''; Identifiers['TargetCPU']:='';
@ -417,26 +368,23 @@ begin
sl:=TStringList.Create; sl:=TStringList.Create;
try try
if (CurModeRow<>nil) and (CurModeRow.Flag<>nil) then begin if (CurModeRow<>nil) and (CurModeRow.Flag<>nil) then begin
if CurModeRow.Flag.FlagType=bmftSetVariable then begin Identifier:=CurModeRow.Flag.Variable;
Identifier:=CurModeRow.Flag.Variable; // check standard variables
// check standard variables if SysUtils.CompareText(Identifier,'TargetOS')=0 then begin
if SysUtils.CompareText(Identifier,'TargetOS')=0 then begin for i:=low(FPCOperatingSystemNames) to high(FPCOperatingSystemNames) do
for i:=low(FPCOperatingSystemNames) to high(FPCOperatingSystemNames) do sl.Add(FPCOperatingSystemNames[i]);
sl.Add(FPCOperatingSystemNames[i]); end
end else if SysUtils.CompareText(Identifier,'TargetCPU')=0 then begin
else if SysUtils.CompareText(Identifier,'TargetCPU')=0 then begin for i:=low(FPCProcessorNames) to high(FPCProcessorNames) do
for i:=low(FPCProcessorNames) to high(FPCProcessorNames) do sl.Add(FPCProcessorNames[i]);
sl.Add(FPCProcessorNames[i]); end
end else begin
else begin // search build variable
// search build variable FindBuildVariable(Identifier,Vars,aVariable);
FindBuildVariable(Identifier,Vars,aVariable); if aVariable<>nil then
if aVariable<>nil then sl.Assign(aVariable.Values);
sl.Assign(aVariable.Values); end;
end; Columns[ValueCol].ButtonStyle:=cbsPickList;
Columns[ValueCol].ButtonStyle:=cbsPickList;
end else if CurModeRow.Flag.FlagType in BuildModeFlagPaths then
Columns[ValueCol].ButtonStyle:=cbsEllipsis;
end; end;
sl.Sort; sl.Sort;
Columns[ValueCol].PickList:=sl; Columns[ValueCol].PickList:=sl;
@ -499,27 +447,10 @@ end;
procedure TBuildModesGrid.BuildModesGridEditButtonClick(Sender: TObject); procedure TBuildModesGrid.BuildModesGridEditButtonClick(Sender: TObject);
var var
CurModeRow: TBuildModeGridRow; CurModeRow: TBuildModeGridRow;
CurPathEditor: TPathEditorDialog;
ValueCol: Integer;
begin begin
CurModeRow:=SelectedModeRow; CurModeRow:=SelectedModeRow;
if CurModeRow=nil then exit; if CurModeRow=nil then exit;
if CurModeRow.Flag=nil then exit; if CurModeRow.Flag=nil then exit;
ValueCol:=GetTypeCol+1;
if CurModeRow.Flag.FlagType in BuildModeFlagPaths then begin
CurPathEditor:=TPathEditorDialog.Create(nil);
try
CurPathEditor.BaseDirectory:=Project1.ProjectDirectory;
CurPathEditor.Path:=CurModeRow.Flag.Value;
CurPathEditor.Templates:='';
if CurPathEditor.ShowModal=mrOk then begin
CurModeRow.Flag.Value:=CurPathEditor.Path;
Cells[ValueCol,Row]:=CurModeRow.Flag.Value;
end;
finally
CurPathEditor.Free;
end;
end;
end; end;
procedure TBuildModesGrid.GetCheckBoxState(const aCol, aRow: Integer; procedure TBuildModesGrid.GetCheckBoxState(const aCol, aRow: Integer;
@ -775,7 +706,7 @@ begin
Columns[InsertCol].ButtonStyle:=cbsCheckboxColumn; Columns[InsertCol].ButtonStyle:=cbsCheckboxColumn;
inc(FGroupModeCount); inc(FGroupModeCount);
end else begin end else begin
CurFlag:=Result.AddFlag(bmftNone,''); CurFlag:=Result.AddFlag('');
InsertPos:=ModeRowCount; InsertPos:=ModeRowCount;
end; end;
InsertRow:=InsertPos+1; InsertRow:=InsertPos+1;
@ -810,7 +741,7 @@ begin
mtError, [mbCancel], 0); mtError, [mbCancel], 0);
exit; exit;
end; end;
Result:=CurModeRow.Mode.InsertFlag(CurModeRow.IndexInGroup+1,bmftNone,'',''); Result:=CurModeRow.Mode.InsertFlag(CurModeRow.IndexInGroup+1,'','');
InsertPos:=Row+1; InsertPos:=Row+1;
GridRow:=TBuildModeGridRow.Create(CurModeRow.Mode,Result); GridRow:=TBuildModeGridRow.Create(CurModeRow.Mode,Result);
FModeRows.Insert(InsertPos-1,GridRow); FModeRows.Insert(InsertPos-1,GridRow);
@ -838,8 +769,7 @@ begin
if (CurModeRow.Flag.Value<>'') or (CurModeRow.Flag.Variable<>'') then if (CurModeRow.Flag.Value<>'') or (CurModeRow.Flag.Variable<>'') then
begin begin
if MessageDlg(lisDeleteSetting2, if MessageDlg(lisDeleteSetting2,
Format(lisDeleteSetting3, ['"', BuildModeFlagTypeCaptions( 'Delete '+CurModeRow.Flag.Variable+'='+CurModeRow.Flag.Value,
CurModeRow.Flag.FlagType), '"']),
mtConfirmation,[mbYes,mbNo],0)<>mrYes mtConfirmation,[mbYes,mbNo],0)<>mrYes
then then
exit; exit;

View File

@ -145,8 +145,7 @@ type
end; end;
{ TLazCompOptConditionals { TLazCompOptConditionals
- conditional compiler options - conditional compiler options }
- additions dependending }
TLazCompOptConditionals = class TLazCompOptConditionals = class
private private
@ -159,7 +158,13 @@ type
property Root: TCompOptCondNode read FRoot write FRoot; property Root: TCompOptCondNode read FRoot write FRoot;
end; end;
{ TLazBuildVariable } { TLazBuildVariable
Build variables are like macros. Every package/project can define build
variables. A variable has a name, a description, a list of possible values
and a default value. The default value can be an expression using other
build variables.
The IDE defines various variables like TargetOS and TargetCPU.
The LCL package defines the variable LCLWidgetType. }
TLazBuildVariable = class TLazBuildVariable = class
protected protected
@ -182,7 +187,9 @@ type
property DefaultValue: TLazCompOptConditionals read FDefaultValue; property DefaultValue: TLazCompOptConditionals read FDefaultValue;
end; end;
{ TLazBuildVariables } { TLazBuildVariables
The list of build variables of a package/project.
They are stored in the compiler options. }
TLazBuildVariables = class TLazBuildVariables = class
private private