IDE: mode matrix: apply macros

git-svn-id: trunk@41332 -
This commit is contained in:
mattias 2013-05-20 19:51:13 +00:00
parent b759d82dab
commit ae3978f2d2
3 changed files with 105 additions and 66 deletions

View File

@ -2248,15 +2248,34 @@ function TBuildManager.OnGetBuildMacroValues(Options: TBaseCompilerOptions;
procedure SetProjectMacroValues(Vars: TCTCfgScriptVariables);
var
{$IFDEF EnableModeMatrix}
Target: String;
{$ELSE}
Values: TCTCfgScriptVariables;
begin
Values:=GetProjectMacroValues;
if Values=nil then exit;
{$IFDEF VerboseBuildMacros}
Values.WriteDebugReport('OnGetBuildMacroValues project values');
{$ENDIF}
Vars.AddOverrides(Values);
begin
{$IFDEF EnableModeMatrix}
Target:=GetModeMatrixTarget(Options);
if EnvironmentOptions<>nil then
ApplyBuildMatrixMacros(EnvironmentOptions.BuildMatrixOptions,Target,Vars);
if (Project1<>nil) and (Project1.BuildModes<>nil) then
begin
ApplyBuildMatrixMacros(Project1.BuildModes.SharedMatrixOptions,Target,Vars);
ApplyBuildMatrixMacros(Project1.BuildModes.SessionMatrixOptions,Target,Vars);
end;
SetCmdLineOverrides(Vars);
SetDefaults(Vars);
{$IFDEF VerboseBuildMacros}
Vars.WriteDebugReport('OnGetBuildMacroValues after applying project values');
{$ENDIF}
{$ELSE}
Values:=GetProjectMacroValues;
if Values=nil then exit;
{$IFDEF VerboseBuildMacros}
Values.WriteDebugReport('OnGetBuildMacroValues project values');
{$ENDIF}
Vars.AddOverrides(Values);
{$ENDIF}
end;
var

View File

@ -19,7 +19,7 @@
***************************************************************************
ToDo:
- ide macro
- replace new option with the three option types
- load old build macro values into matrix
- save matrix options for old build macro values
- ifdef old frame
@ -127,9 +127,6 @@ type
property LazProject: TProject read FProject;
end;
EMMMacroSyntaxException = class(Exception)
end;
// assign
function IsEqual(Options: TBuildMatrixOptions; StorageGroup: TGroupedMatrixGroup): boolean;
procedure AssignBuildMatrixOptionsToGroup(Options: TBuildMatrixOptions;
@ -148,10 +145,6 @@ function CaptionToBuildMatrixOptionType(s: string): TBuildMatrixOptionType;
function BuildMatrixOptionTypeHint(Typ: TBuildMatrixOptionType): string;
function BuildMatrixDefaultValue(Typ: TBuildMatrixOptionType): string;
// macro
function SplitMatrixMacro(MacroAssignment: string;
out MacroName, MacroValue: string; ExceptionOnError: boolean): boolean;
var
ModeMatrixFrame: TCompOptModeMatrix = nil;
@ -294,6 +287,7 @@ begin
SplitMatrixMacro(ValueRow.Value,MacroName,MacroValue,false);
Option.MacroName:=MacroName;
Option.Value:=MacroValue;
//debugln(['AssignBuildMatrixGroupToOptions Name="',MacroName,'" Value="',MacroValue,'"']);
end else begin
Option.Value:=ValueRow.Value;
end;
@ -383,56 +377,6 @@ begin
Result+=Format(lisMMExcludeAllPackagesMatching, [Excludes])+LineEnding;
end;
function SplitMatrixMacro(MacroAssignment: string; out MacroName,
MacroValue: string; ExceptionOnError: boolean): boolean;
procedure E(Msg: string);
begin
raise EMMMacroSyntaxException.Create(Msg);
end;
var
p: PChar;
StartP: PChar;
begin
Result:=false;
MacroName:='';
MacroValue:='';
if MacroAssignment='' then begin
if ExceptionOnError then
E(lisMMMissingMacroName);
exit;
end;
p:=PChar(MacroAssignment);
if not IsIdentStartChar[p^] then begin
if ExceptionOnError then
E(Format(lisMMExpectedMacroNameButFound, [dbgstr(p^)]));
exit;
end;
StartP:=p;
repeat
inc(p);
until not IsIdentChar[p^];
MacroName:=copy(MacroAssignment,1,p-StartP);
if (p^<>':') or (p[1]<>'=') then begin
if ExceptionOnError then
E(Format(lisMMExpectedAfterMacroNameButFound, [dbgstr(p^)]));
exit;
end;
inc(p,2);
repeat
if (p^=#0) and (p-PChar(MacroAssignment)=length(MacroAssignment)) then break;
if p^ in [#0..#31,#127] then begin
if ExceptionOnError then
E(Format(lisMMInvalidCharacterInMacroValue, [dbgstr(p^)]));
exit;
end;
inc(p);
until false;
MacroValue:=copy(MacroAssignment,StartP-PChar(MacroAssignment)+1,p-StartP);
Result:=true;
end;
{$R *.lfm}
{ TCompOptModeMatrix }

View File

@ -27,7 +27,7 @@ interface
uses
Classes, SysUtils, contnrs, LazConfigStorage, Laz2_XMLCfg, LazLogger,
FileProcs, KeywordFuncLists, LazarusIDEStrConsts;
FileProcs, KeywordFuncLists, CodeToolsCfgScript, LazarusIDEStrConsts;
const
BuildMatrixProjectName = '#project';
@ -137,12 +137,21 @@ type
procedure GetOutputDirectory(Target, ActiveMode: string; var OutDir: string);
end;
EMMMacroSyntaxException = class(Exception)
end;
function BuildMatrixTargetFits(Target, Targets: string): boolean;
function BuildMatrixTargetFitsPattern(Target, Pattern: PChar): boolean;
function CheckBuildMatrixTargetsSyntax(const Targets: String): String;
function BuildMatrixModeFits(Mode, ModesSeparatedByLineBreaks: string): boolean;
function Str2BuildMatrixOptionType(const s: string): TBuildMatrixOptionType;
function SplitMatrixMacro(MacroAssignment: string;
out MacroName, MacroValue: string; ExceptionOnError: boolean): boolean;
procedure ApplyBuildMatrixMacros(Options: TBuildMatrixOptions; Target: string;
CfgVars: TCTCfgScriptVariables);
implementation
function BuildMatrixTargetFits(Target, Targets: string): boolean;
@ -303,6 +312,73 @@ begin
Result:=bmotCustom;
end;
function SplitMatrixMacro(MacroAssignment: string; out MacroName,
MacroValue: string; ExceptionOnError: boolean): boolean;
procedure E(Msg: string);
begin
raise EMMMacroSyntaxException.Create(Msg);
end;
var
p: PChar;
StartP: PChar;
begin
Result:=false;
MacroName:='';
MacroValue:='';
if MacroAssignment='' then begin
if ExceptionOnError then
E(lisMMMissingMacroName);
exit;
end;
p:=PChar(MacroAssignment);
if not IsIdentStartChar[p^] then begin
if ExceptionOnError then
E(Format(lisMMExpectedMacroNameButFound, [dbgstr(p^)]));
exit;
end;
StartP:=p;
repeat
inc(p);
until not IsIdentChar[p^];
MacroName:=copy(MacroAssignment,1,p-StartP);
if (p^<>':') or (p[1]<>'=') then begin
if ExceptionOnError then
E(Format(lisMMExpectedAfterMacroNameButFound, [dbgstr(p^)]));
exit;
end;
inc(p,2);
StartP:=p;
repeat
if (p^=#0) and (p-PChar(MacroAssignment)=length(MacroAssignment)) then break;
if p^ in [#0..#31,#127] then begin
if ExceptionOnError then
E(Format(lisMMInvalidCharacterInMacroValue, [dbgstr(p^)]));
exit;
end;
inc(p);
until false;
MacroValue:=copy(MacroAssignment,StartP-PChar(MacroAssignment)+1,p-StartP);
Result:=true;
end;
procedure ApplyBuildMatrixMacros(Options: TBuildMatrixOptions; Target: string;
CfgVars: TCTCfgScriptVariables);
var
i: Integer;
Option: TBuildMatrixOption;
begin
if (Options=nil) or (CfgVars=nil) then exit;
for i:=0 to Options.Count-1 do begin
Option:=Options[i];
if Option.Typ<>bmotIDEMacro then continue;
if not Option.FitsTarget(Target) then continue;
//debugln(['ApplyBuildMatrixMacros Option.MacroName="',Option.MacroName,'" Value="',Option.Value,'"']);
CfgVars.Values[Option.MacroName]:=Option.Value;
end;
end;
{ TBuildMatrixOptions }
function TBuildMatrixOptions.GetItems(Index: integer): TBuildMatrixOption;