project groups: compile project with build modes

git-svn-id: trunk@50436 -
This commit is contained in:
mattias 2015-11-20 10:46:35 +00:00
parent f941374644
commit 76fdce40ea
4 changed files with 124 additions and 51 deletions

View File

@ -384,12 +384,15 @@ type
{ TProjectBuildModes }
{ TLazProjectBuildModes }
TLazProjectBuildModes = class(TComponent)
protected
FChangeStamp: integer;
function GetLazBuildModes(Index: integer): TLazProjectBuildMode; virtual; abstract;
public
function Count: integer; virtual; abstract;
function IndexOf(anIdentifier: string): integer;
property ChangeStamp: integer read FChangeStamp;
property BuildModes[Index: integer]: TLazProjectBuildMode read GetLazBuildModes;
end;
@ -436,6 +439,7 @@ type
FFlags: TProjectFlags;
FResources: TObject;
FRunParameters: TAbstractRunParamsOptions;
function GetActiveBuildModeID: string; virtual; abstract;
function GetFileCount: integer; virtual; abstract;
function GetFiles(Index: integer): TLazProjectFile; virtual; abstract;
function GetMainFile: TLazProjectFile; virtual; abstract;
@ -444,6 +448,7 @@ type
function GetLazBuildModes: TLazProjectBuildModes; virtual; abstract;
function GetProjectInfoFile: string; virtual; abstract;
function GetUseManifest: boolean; virtual; abstract;
procedure SetActiveBuildModeID(AValue: string); virtual; abstract;
procedure SetExecutableType(const AValue: TProjectExecutableType); virtual;
procedure SetFlags(const AValue: TProjectFlags); virtual;
procedure SetMainFileID(const AValue: Integer); virtual; abstract;
@ -479,6 +484,8 @@ type
function GetDefaultTitle: string; // extract name from lpi file name
function GetTitleOrName: string; // GetTitle, if this is '' then GetDefaultTitle
public
property ActiveBuildModeID: string read GetActiveBuildModeID
write SetActiveBuildModeID;
property ChangeStamp: integer read FChangeStamp;
property Files[Index: integer]: TLazProjectFile read GetFiles;
property FileCount: integer read GetFileCount;
@ -714,6 +721,15 @@ begin
Result:=cetProgram;
end;
{ TLazProjectBuildModes }
function TLazProjectBuildModes.IndexOf(anIdentifier: string): integer;
begin
Result:=Count-1;
while (Result>=0) and (CompareText(BuildModes[Result].Identifier,anIdentifier)<>0)
do dec(Result);
end;
{ TProjectFileDescriptor }
procedure TProjectFileDescriptor.SetResourceClass(

View File

@ -31,7 +31,7 @@ type
FBuildModes: TObjectList;
FFiles: TStringList;
FRequiredPackages: TObjectList; // list of TPGDependency
function CompileUsingLazBuild(const AAction: TPGTargetAction): TPGActionResult;
function CompileUsingLazBuild(const AAction: TPGTargetAction; aBuildMode: string = ''): TPGActionResult;
protected
function GetBuildModeCount: integer; override;
function GetBuildModes(Index: integer): TPGBuildMode; override;
@ -899,8 +899,8 @@ begin
PG.Modified:=true;
end;
function TIDECompileTarget.CompileUsingLazBuild(const AAction: TPGTargetAction
): TPGActionResult;
function TIDECompileTarget.CompileUsingLazBuild(const AAction: TPGTargetAction;
aBuildMode: string): TPGActionResult;
var
FPCParser: TFPCParser;
Params: TStringList;
@ -915,6 +915,8 @@ begin
ttProject:
begin
ToolTitle:='Compile Project '+ExtractFileNameOnly(Filename);
if aBuildMode<>'' then
ToolTitle+=', build mode "'+aBuildMode+'"';
ToolKind:='Other Project';
end;
ttPackage:
@ -939,6 +941,8 @@ begin
Params:=TStringList.Create;
if AAction=taCompileClean then
Params.Add('-B');
if aBuildMode<>'' then
Params.Add('--build-mode='+aBuildMode);
Params.Add(Filename);
Tool:=ExternalToolList.Add(ToolTitle);
@ -1108,7 +1112,7 @@ begin
PkgList.Free;
end;
// ToDo: load buildmodes
// load buildmodes
for i:=0 to AProject.LazBuildModes.Count-1 do begin
LazBuildMode:=AProject.LazBuildModes.BuildModes[i];
FBuildModes.Add(TPGBuildMode.Create(Self,LazBuildMode.Identifier,false));
@ -1150,7 +1154,7 @@ begin
for i:=1 to Cnt do begin
SubPath:=Path+'Item'+IntToStr(i)+'/';
BuildMode:=xml.GetValue(SubPath+'Name','');
// ToDo: load/store compile in lpg
// load/store compile in lpg
if BuildMode<>'' then
FBuildModes.Add(TPGBuildMode.Create(Self,BuildMode,false));
end;
@ -1214,6 +1218,8 @@ end;
function TIDECompileTarget.ProjectAction(AAction: TPGTargetAction): TPGActionResult;
var
F: TProjectBuildFlags;
i: Integer;
aMode: TPGBuildMode;
begin
Result:=arFailed;
@ -1222,28 +1228,57 @@ begin
then begin
// project loaded => use IDE functions
case AAction of
taSettings :
begin
if ExecuteIDECommand(Self,ecProjectOptions) then
Result:=arOK;
taSettings :
begin
if not ExecuteIDECommand(Self,ecProjectOptions) then
Result:=arOK;
end;
taCompile,
taCompileClean,
taCompileFromHere:
begin
// check toolstatus
if LazarusIDE.ToolStatus<>itNone then begin
IDEMessageDialog('Be patient!','There is still another build in progress.',
mtInformation,[mbOk]);
exit;
end;
taCompile,
taCompileClean,
taCompileFromHere:
begin
F:=[];
if (AAction=taCompileClean) then
Include(F,pbfCleanCompile);
if LazarusIDE.DoBuildProject(crCompile,F)=mrOk then
Result:=arOK;
if AAction=taCompileFromHere then
PerformNextTarget(taCompileFromHere);
end;
taRun :
begin
if LazarusIDE.DoRunProject=mrOk then
Result:=arOk;
// save project
if LazarusIDE.DoSaveProject([])<>mrOk then exit;
F:=[];
if (AAction=taCompileClean) then
Include(F,pbfCleanCompile);
if BuildModeCount>0 then begin
for i:=0 to BuildModeCount-1 do begin
aMode:=BuildModes[i];
if not aMode.Compile then continue;
// switch build mode
LazarusIDE.ActiveProject.ActiveBuildModeID:=aMode.Identifier;
if LazarusIDE.ActiveProject.ActiveBuildModeID<>aMode.Identifier
then begin
IDEMessageDialog('Build mode not found','Build mode "'+aMode.Identifier+'" not found.',mtError,[mbOk]);
exit;
end;
// compile project in active buildmode
if LazarusIDE.DoBuildProject(crCompile,F)<>mrOk then
exit;
end;
end else begin
// compile default buildmode
if LazarusIDE.DoBuildProject(crCompile,F)<>mrOk then
exit;
end;
Result:=arOK;
if AAction=taCompileFromHere then
Result:=PerformNextTarget(taCompileFromHere);
end;
taRun :
begin
if LazarusIDE.DoRunProject<>mrOk then exit;
Result:=arOk;
end;
end;
end else begin
// project not loaded => use lazbuild
@ -1252,30 +1287,57 @@ begin
begin
// open project
if LazarusIDE.DoOpenProjectFile(Filename,[ofAddToRecent])<>mrOk then
exit(arFailed);
exit;
if AAction=taSettings then
if not ExecuteIDECommand(Self,ecProjectOptions) then
Result:=arFailed;
exit;
Result:=arOK;
end;
taCompile,
taCompileClean,
taCompileFromHere:
begin
// run lazbuild as external tool
IDEMessagesWindow.Clear;
Result:=CompileUsingLazBuild(AAction);
if Result<>arOK then exit;
// check toolstatus
if LazarusIDE.ToolStatus<>itNone then begin
IDEMessageDialog('Be patient!','There is still another build in progress.',
mtInformation,[mbOk]);
exit;
end;
// save project
if LazarusIDE.DoSaveProject([])<>mrOk then exit;
LazarusIDE.ToolStatus:=itBuilder;
try
if BuildModeCount>0 then begin
for i:=0 to BuildModeCount-1 do begin
aMode:=BuildModes[i];
if not aMode.Compile then continue;
// run lazbuild as external tool
Result:=CompileUsingLazBuild(AAction,aMode.Identifier);
if Result<>arOK then exit;
end;
end else begin
IDEMessagesWindow.Clear;
// run lazbuild as external tool
Result:=CompileUsingLazBuild(AAction);
if Result<>arOK then exit;
end;
finally
LazarusIDE.ToolStatus:=itNone;
end;
Result:=arOK;
if AAction=taCompileFromHere then
PerformNextTarget(taCompileFromHere);
Result:=PerformNextTarget(taCompileFromHere);
end;
taRun:
begin
// open project, then run
if LazarusIDE.DoOpenProjectFile(Filename,[ofAddToRecent])<>mrOk then
exit(arFailed);
if LazarusIDE.DoRunProject=mrOk then
Result:=arOk;
exit;
if LazarusIDE.DoRunProject<>mrOk then
exit;
Result:=arOk;
end;
end;
end;

View File

@ -151,7 +151,6 @@ procedure SwitchBuildMode(aBuildModeID: string);
begin
OnSaveIDEOptionsHook(Nil, Project1.CompilerOptions); // Save changes
Project1.ActiveBuildModeID := aBuildModeID; // Switch
IncreaseBuildMacroChangeStamp;
OnLoadIDEOptionsHook(Nil, Project1.CompilerOptions); // Load options
end;

View File

@ -765,7 +765,6 @@ type
FProjectWriteFlags: TProjectWriteFlags;
FSaveSessionInLPI: Boolean;
procedure ClearBuildModes;
function GetActiveBuildModeID: string;
function GetAllEditorsInfo(Index: Integer): TUnitEditorInfo;
function GetCompilerOptions: TProjectCompilerOptions;
function GetBaseCompilerOptions: TBaseCompilerOptions;
@ -792,7 +791,6 @@ type
const OldUnitName, NewUnitName: string;
CheckIfAllowed: boolean; var Allowed: boolean);
procedure SetActiveBuildMode(const AValue: TProjectBuildMode);
procedure SetActiveBuildModeID(aIdent: string);
procedure SetAutoOpenDesignerFormsDisabled(const AValue: boolean);
procedure SetEnableI18N(const AValue: boolean);
procedure SetEnableI18NForLFM(const AValue: boolean);
@ -836,21 +834,23 @@ type
procedure SaveToSession;
function DoWrite(Filename: String; IsLpi: Boolean): TModalResult;
protected
function GetActiveBuildModeID: string; override;
function GetDefineTemplates: TProjPackDefineTemplates;
function GetFiles(Index: integer): TLazProjectFile; override;
function GetLazBuildModes: TLazProjectBuildModes; override;
function GetMainFile: TLazProjectFile; override;
function GetMainFileID: Integer; override;
procedure SetMainFileID(const AValue: Integer); override;
function GetLazBuildModes: TLazProjectBuildModes; override;
function GetFiles(Index: integer): TLazProjectFile; override;
procedure SetFlags(const AValue: TProjectFlags); override;
function GetModified: boolean; override;
function GetProjectInfoFile: string; override;
procedure SetProjectInfoFile(const NewFilename: string); override;
procedure SetSessionStorage(const AValue: TProjectSessionStorage); override;
procedure SetModified(const AValue: boolean); override;
procedure SetSessionModified(const AValue: boolean); override;
procedure SetExecutableType(const AValue: TProjectExecutableType); override;
function GetUseManifest: boolean; override;
procedure SetActiveBuildModeID(aIdent: string); override;
procedure SetExecutableType(const AValue: TProjectExecutableType); override;
procedure SetFlags(const AValue: TProjectFlags); override;
procedure SetMainFileID(const AValue: Integer); override;
procedure SetModified(const AValue: boolean); override;
procedure SetProjectInfoFile(const NewFilename: string); override;
procedure SetSessionModified(const AValue: boolean); override;
procedure SetSessionStorage(const AValue: TProjectSessionStorage); override;
procedure SetUseManifest(AValue: boolean); override;
protected
// special unit lists
@ -1030,8 +1030,6 @@ type
public
property ActiveBuildMode: TProjectBuildMode read FActiveBuildMode
write SetActiveBuildMode;
property ActiveBuildModeID: string read GetActiveBuildModeID
write SetActiveBuildModeID;
property ActiveWindowIndexAtStart: integer read FActiveWindowIndexAtStart
write FActiveWindowIndexAtStart;
property AutoCreateForms: boolean read FAutoCreateForms write FAutoCreateForms;
@ -5078,8 +5076,6 @@ begin
begin
if BuildModes[i].Identifier=aIdent then
begin
// Force setting active mode. Values may be assigned, looks like active mode
ActiveBuildMode:=Nil; // is already set but it is not
ActiveBuildMode:=BuildModes[i];
Break;
end;