fppkg: Implement support for package-variants

git-svn-id: trunk@59712 -
This commit is contained in:
joost 2018-12-01 22:33:45 +00:00
parent 167afa6433
commit 034fdfe9b3
9 changed files with 2154 additions and 51 deletions

1
.gitattributes vendored
View File

@ -1505,6 +1505,7 @@ components/fppkg/src/fppkg_optionsfrm.lfm svneol=native#text/plain
components/fppkg/src/fppkg_optionsfrm.pas svneol=native#text/plain
components/fppkg/src/fppkg_packageoptionsfrm.lfm svneol=native#text/plain
components/fppkg/src/fppkg_packageoptionsfrm.pas svneol=native#text/pascal
components/fppkg/src/fppkg_packagevariant.pas svneol=native#text/pascal
components/fppkg/src/fppkgpackagemanager.lpk svneol=native#text/plain
components/fppkg/src/fppkgpackagemanager.pas svneol=native#text/plain
components/fppkg/src/fppkgworkerthread.pas svneol=native#text/plain

View File

@ -7,23 +7,37 @@ interface
uses
Classes,
SysUtils,
StrUtils,
PackageIntf,
FppkgIntf,
Fppkg_EnvironmentOptions;
Fppkg_EnvironmentOptions,
fppkg_packagevariant;
type
{ TFppkgInterfaceEx }
TFppkgInterfaceEx = class(TFppkgInterface)
private
function GetComponentName(AName: string): String;
protected
function GetInstallFPMakeDependencies: Boolean; override;
function GetUseFPMakeWhenPossible: Boolean; override;
public
function ConstructFpMakeImplementationSection(APackage: TIDEPackage): string; override;
function ConstructFpMakeInterfaceSection(APackage: TIDEPackage): string; override;
function ConstructFpMakeDependenciesFileSection(APackage: TIDEPackage): string; override;
end;
implementation
{ TFppkgInterfaceEx }
function TFppkgInterfaceEx.GetComponentName(AName: string): String;
begin
Result := StringsReplace(AName, ['/',' ', '\', ':', ';', '.', ',','(',')'], ['_','_', '_', '_', '_', '_', '_', '_', '_'], [rfReplaceAll]);
end;
function TFppkgInterfaceEx.GetInstallFPMakeDependencies: Boolean;
begin
Result := TFppkgEnvironmentOptions(TFppkgEnvironmentOptions.GetInstance).InstallFPMakeDependencies;
@ -34,6 +48,174 @@ begin
Result := TFppkgEnvironmentOptions(TFppkgEnvironmentOptions.GetInstance).UseFPMakeWhenPossible;
end;
function TFppkgInterfaceEx.ConstructFpMakeInterfaceSection(APackage: TIDEPackage): string;
var
VariantList: TFppkgPackageVariantList;
Variant: TFppkgPackageVariant;
i, j: Integer;
begin
Result := '';
VariantList := TFppkgPackageVariantList.Create(True);
try
APackage.CustomOptions.AppendBasePath('Fppkg/');
APackage.CustomOptions.AppendBasePath('PackageVariants/');
try
VariantList.Load(APackage.CustomOptions);
for i := 0 to VariantList.Count -1 do
begin
Variant := VariantList.Items[i];
result := Result + ' ' + GetComponentName(Variant.Name) + 'Variant: TPackageVariants;' + LineEnding +' ';
if Variant.Items.Count > 0 then
begin
for j := 0 to Variant.Items.Count -1 do
begin
result := result + GetComponentName(Variant.Items[j].Name) + 'VariantItem, ';
end;
SetLength(Result, length(Result) -2);
Result := Result + ': TPackageVariant;' + LineEnding;
end;
end;
if Result <> '' then
Result := 'var' + LineEnding + Result;
finally
APackage.CustomOptions.UndoAppendBasePath;
APackage.CustomOptions.UndoAppendBasePath;
end;
finally
VariantList.Free;
end;
end;
function TFppkgInterfaceEx.ConstructFpMakeDependenciesFileSection(APackage: TIDEPackage): string;
var
VariantList: TFppkgPackageVariantList;
Variant: TFppkgPackageVariant;
i, j, k: Integer;
Found: Boolean;
begin
Result := '';
VariantList := TFppkgPackageVariantList.Create(True);
try
APackage.CustomOptions.AppendBasePath('Fppkg/');
APackage.CustomOptions.AppendBasePath('PackageVariants/');
try
VariantList.Load(APackage.CustomOptions);
for i := 0 to APackage.FileCount -1 do
if APackage.Files[i].FileType = pftUnit then
begin
Found := False;
for j := 0 to VariantList.Count -1 do
begin
Variant := VariantList.Items[j];
for k := 0 to Variant.Items.Count -1 do
begin
if Variant.Items[k].PackageFiles.IndexOf(APackage.Files[i].GetShortFilename(False)) > -1 then
begin
Found := True;
//Result := Result + ' ' + GetComponentName(Variant.Items[k].Name) +'VariantItem.Targets.AddImplicitUnit('''+APackage.Files[i].GetShortFilename(False)+''');' + LineEnding;
end;
end;
end;
if not Found then
Result := Result + ' t.Dependencies.AddUnit('''+APackage.files[i].Unit_Name+''');' + LineEnding;
end;
for i := 0 to APackage.FileCount-1 do
if (APackage.Files[i].FileType=pftUnit) then
begin
Found := False;
for j := 0 to VariantList.Count -1 do
begin
Variant := VariantList.Items[j];
for k := 0 to Variant.Items.Count -1 do
begin
if Variant.Items[k].PackageFiles.IndexOf(APackage.Files[i].GetShortFilename(False)) > -1 then
begin
Found := True;
//if (pffAddToPkgUsesSection in APackage.Files[i].Flags) then
// Result := Result + ' ' + GetComponentName(Variant.Items[k].Name) +'VariantItem.Targets.AddUnit('''+APackage.Files[i].GetShortFilename(False)+''');' + LineEnding;
//else
Result := Result + ' ' + GetComponentName(Variant.Items[k].Name) +'VariantItem.Targets.AddImplicitUnit('''+APackage.Files[i].GetShortFilename(False)+''');' + LineEnding;
end;
end;
end;
if not found then
begin
//if (pffAddToPkgUsesSection in APackage.Files[i].Flags) then
// Result:=Result+' T:=P.Targets.AddUnit('''+CreateRelativePath(APackage.Files[i].Filename,APackage.Directory)+''');'+LineEnding)
//else
Result:=Result+' P.Targets.AddImplicitUnit('''+APackage.Files[i].GetShortFilename(False)+''');'+LineEnding;
end;
end;
finally
APackage.CustomOptions.UndoAppendBasePath;
APackage.CustomOptions.UndoAppendBasePath;
end;
finally
VariantList.Free;
end;
end;
function TFppkgInterfaceEx.ConstructFpMakeImplementationSection(APackage: TIDEPackage): string;
var
VariantList: TFppkgPackageVariantList;
Variant: TFppkgPackageVariant;
ItemName: string;
i, j, k: Integer;
CustomCode: TStrings;
begin
Result := '';
VariantList := TFppkgPackageVariantList.Create(True);
try
APackage.CustomOptions.AppendBasePath('Fppkg/');
try
APackage.CustomOptions.AppendBasePath('PackageVariants/');
try
VariantList.Load(APackage.CustomOptions);
for i := 0 to VariantList.Count -1 do
begin
Variant := VariantList.Items[i];
result := result + ' ' + GetComponentName(Variant.Name) + 'Variant := AddPackageVariant('''+Variant.Name+''',true);' + LineEnding;
result := result + ' P.AddPackageVariant('+GetComponentName(Variant.Name)+'Variant);' + LineEnding;
if Variant.Items.Count > 0 then
begin
for j := 0 to Variant.Items.Count -1 do
begin
ItemName := GetComponentName(Variant.Items[j].Name) + 'VariantItem';
result := result + ' ' + ItemName + ' := ' + GetComponentName(Variant.Name) + 'Variant.add('''+Variant.Items[j].Name+''');' + LineEnding;
for k := 0 to Variant.Items[j].CompilerOptions.Count -1 do
begin
Result := Result + ' ' + ItemName + '.Options.Add(''' + Variant.Items[j].CompilerOptions[k] + ''');' + LineEnding;
end;
end;
end;
end;
finally
APackage.CustomOptions.UndoAppendBasePath;
end;
CustomCode := TStringList.Create;
try
APackage.CustomOptions.GetValue('CustomCode', CustomCode);
result := result + CustomCode.Text;
finally
CustomCode.Free;
end;
finally
APackage.CustomOptions.UndoAppendBasePath;
end;
finally
VariantList.Free;
end;
end;
initialization
FppkgInterface := TFppkgInterfaceEx.Create;
finalization

File diff suppressed because it is too large Load Diff

View File

@ -7,24 +7,83 @@ interface
uses
Classes,
SysUtils,
Math,
Forms,
Controls,
StdCtrls,
ExtCtrls,
Dialogs,
ActnList, ComboEx,
PackageIntf,
IDEOptEditorIntf,
IDEOptionsIntf;
IDEOptionsIntf, SynEdit,
fppkg_packagevariant;
type
{ TFppkgPackageOptionsFrm }
TFppkgPackageOptionsFrm = class(TAbstractIDEOptionsEditor)
aAddPackageVariant: TAction;
aAddPackageVariantItem: TAction;
aFileRemove: TAction;
aFileAdd: TAction;
aDeletePackageVariantItem: TAction;
aDeletePackageVariant: TAction;
ActionList: TActionList;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
cbBuildMethod: TComboBox;
cbPackageVariants: TComboBox;
cbProjectFiles: TComboBox;
gbBuildMethod: TGroupBox;
gbPackageVariant: TGroupBox;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
lbPackageFiles: TListBox;
lPackageItem: TLabel;
lbPackageVariant: TListBox;
lPackageItem1: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
Panel8: TPanel;
Panel9: TPanel;
pPackageVariantItem: TPanel;
seCompilerOptions: TSynEdit;
seCustomFPMakeCode: TSynEdit;
procedure aAddPackageVariantExecute(Sender: TObject);
procedure aAddPackageVariantItemExecute(Sender: TObject);
procedure aDeletePackageVariantExecute(Sender: TObject);
procedure aDeletePackageVariantItemExecute(Sender: TObject);
procedure aDeletePackageVariantItemUpdate(Sender: TObject);
procedure aDeletePackageVariantUpdate(Sender: TObject);
procedure aFileAddExecute(Sender: TObject);
procedure aFileAddUpdate(Sender: TObject);
procedure aFileRemoveExecute(Sender: TObject);
procedure aFileRemoveUpdate(Sender: TObject);
procedure cbPackageVariantsChange(Sender: TObject);
procedure lbPackageVariantClick(Sender: TObject);
function GetCurrentPackageVariant: TFppkgPackageVariant;
function GetCurrentPackageVariantItem: TFppkgPackageVariantItem;
procedure seCompilerOptionsChange(Sender: TObject);
protected
FModified: Boolean;
FPackageVariantList: TFppkgPackageVariantList;
FPackageList: TStrings;
procedure ShowPackageVariants();
procedure ShowCurrentPackageVariant();
procedure ShowCurrentPackageVariantItem();
public
function GetTitle: String; override;
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
@ -32,6 +91,8 @@ type
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
@ -44,7 +105,7 @@ var
{$R *.lfm}
resourcestring
lisFppkgPckOptsTitle = 'Build method';
lisFppkgPckOptsTitle = 'Fppkg';
lisFppkgPckOptsBuildMethod = 'Supported build methods';
lisFppkgBuildMethodFPMake = 'FPMake';
lisFppkgBuildMethodLazarus = 'Lazbuild';
@ -53,6 +114,238 @@ resourcestring
{ TFppkgPackageOptionsFrm }
procedure TFppkgPackageOptionsFrm.lbPackageVariantClick(Sender: TObject);
begin
ShowCurrentPackageVariantItem();
end;
function TFppkgPackageOptionsFrm.GetCurrentPackageVariant: TFppkgPackageVariant;
begin
if cbPackageVariants.ItemIndex > -1 then
Result := FPackageVariantList.Items[cbPackageVariants.ItemIndex]
else
Result := Nil;
end;
function TFppkgPackageOptionsFrm.GetCurrentPackageVariantItem: TFppkgPackageVariantItem;
begin
if not Assigned(GetCurrentPackageVariant) then
Result := Nil
else if lbPackageVariant.ItemIndex > -1 then
Result := GetCurrentPackageVariant.Items[lbPackageVariant.ItemIndex]
else
Result := Nil;
end;
procedure TFppkgPackageOptionsFrm.seCompilerOptionsChange(Sender: TObject);
begin
GetCurrentPackageVariantItem.CompilerOptions.Assign(seCompilerOptions.Lines);
end;
procedure TFppkgPackageOptionsFrm.ShowPackageVariants();
var
i: Integer;
begin
for i := 0 to FPackageVariantList.Count -1 do
begin
if cbPackageVariants.Items.Count <= i then
cbPackageVariants.Items.Add(FPackageVariantList[i].Name)
else
cbPackageVariants.Items[i] := FPackageVariantList[i].Name;
end;
for i := cbPackageVariants.Items.Count -1 downto FPackageVariantList.Count do
cbPackageVariants.Items.Delete(i);
if FPackageVariantList.Count > 0 then
begin
if cbPackageVariants.ItemIndex = -1 then
cbPackageVariants.ItemIndex := 0;
end
else
begin
cbPackageVariants.ItemIndex := -1;
end;
ShowCurrentPackageVariant;
end;
procedure TFppkgPackageOptionsFrm.ShowCurrentPackageVariant();
var
CurrentPackageVariant: TFppkgPackageVariant;
i: Integer;
begin
CurrentPackageVariant := GetCurrentPackageVariant;
if Assigned(CurrentPackageVariant) then
begin
for i := 0 to CurrentPackageVariant.Items.Count -1 do
begin
if lbPackageVariant.Items.Count <= i then
lbPackageVariant.Items.Add(CurrentPackageVariant.Items[i].Name)
else
lbPackageVariant.Items[i] := CurrentPackageVariant.Items[i].Name;
end;
for i := lbPackageVariant.Count -1 downto CurrentPackageVariant.Items.Count do
lbPackageVariant.Items.Delete(i);
Panel2.Visible := True;
end
else
begin
Panel2.Visible := False;
end;
ShowCurrentPackageVariantItem();
end;
procedure TFppkgPackageOptionsFrm.ShowCurrentPackageVariantItem();
var
PackageVariantItem: TFppkgPackageVariantItem;
i, StoredItemIndex: Integer;
s: String;
begin
PackageVariantItem := GetCurrentPackageVariantItem;
if Assigned(PackageVariantItem) then
begin
pPackageVariantItem.Visible := True;
lPackageItem.Caption := Format('Package variant [%s]-[%s]', [GetCurrentPackageVariant.Name, PackageVariantItem.Name]);
seCompilerOptions.Lines.Assign(PackageVariantItem.CompilerOptions);
StoredItemIndex := cbProjectFiles.ItemIndex;
lbPackageFiles.Clear;
cbProjectFiles.Clear;
for i := 0 to FPackageList.Count -1 do
begin
s := FPackageList.Strings[i];
if PackageVariantItem.PackageFiles.IndexOf(s) > -1 then
lbPackageFiles.Items.Add(s)
else
cbProjectFiles.Items.Add(s);
end;
cbProjectFiles.ItemIndex := min(cbProjectFiles.Items.Count -1, StoredItemIndex);
end
else
begin
pPackageVariantItem.Visible := False;
end;
end;
procedure TFppkgPackageOptionsFrm.aDeletePackageVariantUpdate(Sender: TObject);
begin
aDeletePackageVariant.Enabled := cbPackageVariants.ItemIndex > -1;
end;
procedure TFppkgPackageOptionsFrm.aFileAddExecute(Sender: TObject);
begin
if cbProjectFiles.ItemIndex > -1 then
GetCurrentPackageVariantItem.PackageFiles.Add(cbProjectFiles.Text);
ShowCurrentPackageVariantItem();
FModified := True;
end;
procedure TFppkgPackageOptionsFrm.aFileAddUpdate(Sender: TObject);
begin
aFileAdd.Enabled := cbProjectFiles.ItemIndex > -1;
end;
procedure TFppkgPackageOptionsFrm.aFileRemoveExecute(Sender: TObject);
var
i: Integer;
begin
i := lbPackageFiles.ItemIndex;
if i > -1 then
GetCurrentPackageVariantItem.PackageFiles.Delete(GetCurrentPackageVariantItem.PackageFiles.IndexOf(lbPackageFiles.Items[i]));
ShowCurrentPackageVariantItem();
FModified := True;
end;
procedure TFppkgPackageOptionsFrm.aFileRemoveUpdate(Sender: TObject);
begin
aFileRemove.Enabled := lbPackageFiles.ItemIndex > -1;
end;
procedure TFppkgPackageOptionsFrm.cbPackageVariantsChange(Sender: TObject);
begin
ShowCurrentPackageVariant;
end;
procedure TFppkgPackageOptionsFrm.aDeletePackageVariantExecute(Sender: TObject);
var
PackageVariant: TFppkgPackageVariant;
begin
PackageVariant := FPackageVariantList.FindItemByName(cbPackageVariants.Text);
if Assigned(PackageVariant) then
begin
if MessageDlg('Fppkg', Format('Are you sure you want to remove the package variant [%s]?', [PackageVariant.Name]), mtConfirmation, mbYesNo, 0) = mrYes then
begin
FPackageVariantList.Remove(PackageVariant);
end;
end;
FModified := True;
ShowPackageVariants;
end;
procedure TFppkgPackageOptionsFrm.aDeletePackageVariantItemExecute(Sender: TObject);
var
PackageVariantItem: TFppkgPackageVariantItem;
begin
PackageVariantItem := GetCurrentPackageVariant.Items.FindItemByName(lbPackageVariant.Items[lbPackageVariant.ItemIndex]);
if Assigned(PackageVariantItem) then
begin
if MessageDlg('Fppkg', Format('Are you sure you want to remove the item [%s]?', [PackageVariantItem.Name]), mtConfirmation, mbYesNo, 0) = mrYes then
begin
GetCurrentPackageVariant.Items.Remove(PackageVariantItem);
end;
end;
FModified := True;
ShowCurrentPackageVariant;
end;
procedure TFppkgPackageOptionsFrm.aDeletePackageVariantItemUpdate(Sender: TObject);
begin
aDeletePackageVariantItem.Enabled := lbPackageVariant.ItemIndex > -1;
end;
procedure TFppkgPackageOptionsFrm.aAddPackageVariantExecute(Sender: TObject);
var
NameVal: String;
Variant: TFppkgPackageVariant;
begin
if InputQuery('Fppkg', 'Enter the name of the new package-variants', false, NameVal) then
begin
if Assigned(FPackageVariantList.FindItemByName(NameVal)) then
begin
MessageDlg('Fppkg', Format('A packagevariant with the name [%s] already exists.', [NameVal]), mtError, [mbOK], 0);
Exit;
end;
Variant := TFppkgPackageVariant.Create;
Variant.Name := NameVal;
FPackageVariantList.Add(Variant);
end;
FModified := True;
ShowPackageVariants();
end;
procedure TFppkgPackageOptionsFrm.aAddPackageVariantItemExecute(Sender: TObject);
var
CurrentVariant: TFppkgPackageVariant;
NameVal: string;
Item: TFppkgPackageVariantItem;
begin
CurrentVariant := GetCurrentPackageVariant;
Assert(Assigned(CurrentVariant));
if InputQuery('Fppkg', 'Enter the name of the new item', false, NameVal) then
begin
if Assigned(CurrentVariant.Items.FindItemByName(NameVal)) then
begin
MessageDlg('Fppkg', Format('An item with the name [%s] already exists.', [NameVal]), mtError, [mbOK], 0);
Exit;
end;
Item := TFppkgPackageVariantItem.Create;
Item.Name := NameVal;
CurrentVariant.Items.Add(Item);
end;
FModified := True;
ShowCurrentPackageVariant();
end;
function TFppkgPackageOptionsFrm.GetTitle: String;
begin
Result := lisFppkgPckOptsTitle;
@ -70,9 +363,32 @@ end;
procedure TFppkgPackageOptionsFrm.ReadSettings(AOptions: TAbstractIDEOptions);
var
LazPackage: TIDEPackage;
i: Integer;
f: TLazPackageFile;
begin
LazPackage := (AOptions as TAbstractPackageIDEOptions).Package;
cbBuildMethod.ItemIndex := Ord(LazPackage.BuildMethod);
LazPackage.CustomOptions.AppendBasePath('Fppkg/');
try
LazPackage.CustomOptions.AppendBasePath('PackageVariants/');
try
FPackageVariantList.Load(LazPackage.CustomOptions);
finally
LazPackage.CustomOptions.UndoAppendBasePath;
end;
LazPackage.CustomOptions.GetValue('CustomCode', seCustomFPMakeCode.Lines);
finally
LazPackage.CustomOptions.UndoAppendBasePath;
end;
FPackageList.Clear;
for i := 0 to LazPackage.FileCount -1 do
if LazPackage.Files[i].GetShortFilename(false) <> '' then
FPackageList.Add(LazPackage.Files[i].GetShortFilename(false));
ShowPackageVariants();
FModified := False;
end;
procedure TFppkgPackageOptionsFrm.WriteSettings(AOptions: TAbstractIDEOptions);
@ -81,6 +397,29 @@ var
begin
LazPackage := (AOptions as TAbstractPackageIDEOptions).Package;
LazPackage.BuildMethod := TBuildMethod(cbBuildMethod.ItemIndex);
if FModified then
begin
LazPackage.Modified := True;
FModified := False;
end;
LazPackage.CustomOptions.AppendBasePath('Fppkg/');
try
if FPackageVariantList.Count>0 then
begin
LazPackage.CustomOptions.AppendBasePath('PackageVariants/');
try
FPackageVariantList.Save(LazPackage.CustomOptions);
finally
LazPackage.CustomOptions.UndoAppendBasePath;
end;
end;
LazPackage.CustomOptions.SetValue('CustomCode', seCustomFPMakeCode.Lines);
finally
LazPackage.CustomOptions.UndoAppendBasePath;
end;
end;
class function TFppkgPackageOptionsFrm.SupportedOptionsClass: TAbstractIDEOptionsClass;
@ -88,6 +427,22 @@ begin
Result := TAbstractPackageIDEOptions;
end;
constructor TFppkgPackageOptionsFrm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FPackageVariantList := TFppkgPackageVariantList.Create(True);
FPackageList := TStringList.Create;
TStringList(FPackageList).Sorted := True;
TStringList(FPackageList).Duplicates := dupIgnore;
end;
destructor TFppkgPackageOptionsFrm.Destroy;
begin
FPackageVariantList.Free;
FPackageList.Free;
inherited Destroy;
end;
initialization
RegisterIDEOptionsEditor(GroupPackage, TFppkgPackageOptionsFrm, FppkgPackageOptionID);
end.

View File

@ -0,0 +1,212 @@
unit fppkg_packagevariant;
{$mode objfpc}{$H+}
interface
uses
fgl,
Classes,
SysUtils,
Generics.Collections,
LazConfigStorage;
type
{ TFppkgNamedItem }
TFppkgNamedItem = class
private
FName: string;
public
constructor Create; virtual;
procedure Save(Config: TConfigStorage); virtual;
procedure Load(Config: TConfigStorage); virtual;
property Name: string read FName write FName;
end;
{ TFppkgNamedItemList }
generic TFppkgNamedItemList<T: TFppkgNamedItem> = class(specialize TObjectList<T>)
public
function FindItemByName(AName: string): T;
procedure Load(Config: TConfigStorage);
procedure Save(Config: TConfigStorage);
end;
{ TFppkgPackageVariantItem }
TFppkgPackageVariantItem = class(TFppkgNamedItem)
private
FCompilerOptions: TStrings;
FPackageFiles: TStrings;
public
constructor Create(); override;
destructor Destroy; override;
procedure Save(Config: TConfigStorage); override;
procedure Load(Config: TConfigStorage); override;
property CompilerOptions: TStrings read FCompilerOptions;
property PackageFiles: TStrings read FPackageFiles;
end;
TFppkgPackageVariantItemList = specialize TFppkgNamedItemList<TFppkgPackageVariantItem>;
{ TFppkgPackageVariant }
TFppkgPackageVariant = class(TFppkgNamedItem)
private
FItems: TFppkgPackageVariantItemList;
public
constructor Create;
destructor Destroy; override;
procedure Save(Config: TConfigStorage); override;
procedure Load(Config: TConfigStorage); override;
property Items: TFppkgPackageVariantItemList read FItems write FItems;
end;
TFppkgPackageVariantList = specialize TFppkgNamedItemList<TFppkgPackageVariant>;
implementation
{ TFppkgNamedItem }
constructor TFppkgNamedItem.Create;
begin
//
end;
procedure TFppkgNamedItem.Save(Config: TConfigStorage);
begin
Config.SetValue('name', Name);
end;
procedure TFppkgNamedItem.Load(Config: TConfigStorage);
begin
Name := Config.GetValue('name', '');
end;
{ TFppkgNamedItemList }
function TFppkgNamedItemList.FindItemByName(AName: string): T;
var
i: Integer;
begin
Result := Nil;
for i := 0 to Count -1 do
begin
if SameText(Items[I].Name, AName) then
begin
Result := Items[I];
Break;
end;
end;
end;
procedure TFppkgNamedItemList.Load(Config: TConfigStorage);
var
Cnt: Integer;
i: Integer;
Item: T;
begin
Config.AppendBasePath('Items');
try
Cnt := Config.GetValue('Count',0);
for i:=0 to Cnt-1 do
begin
Config.AppendBasePath('Item'+IntToStr(i+1)+'/');
try
Item := T.Create;
Add(Item);
Item.Load(Config);
finally
Config.UndoAppendBasePath;
end;
end;
finally
Config.UndoAppendBasePath;
end;
end;
procedure TFppkgNamedItemList.Save(Config: TConfigStorage);
var
i: Integer;
begin
if Count > 0 then
begin
Config.AppendBasePath('Items');
try
Config.SetDeleteValue('Count', Count, 0);
for i:=0 to Count-1 do
begin
Config.AppendBasePath('Item'+IntToStr(i+1)+'/');
try
Items[i].Save(Config);
finally
Config.UndoAppendBasePath;
end;
end;
finally
Config.UndoAppendBasePath;
end;
end;
end;
{ TFppkgPackageVariantItem }
constructor TFppkgPackageVariantItem.Create();
begin
inherited Create();
FCompilerOptions := TStringList.Create;
FPackageFiles := TStringList.Create;
end;
destructor TFppkgPackageVariantItem.Destroy;
begin
FCompilerOptions.Free;
FPackageFiles.Free;
inherited Destroy;
end;
procedure TFppkgPackageVariantItem.Save(Config: TConfigStorage);
begin
inherited;
Config.SetValue('CompilerOptions', CompilerOptions);
Config.SetValue('PackageFiles', PackageFiles);
end;
procedure TFppkgPackageVariantItem.Load(Config: TConfigStorage);
begin
inherited;
Config.GetValue('CompilerOptions', CompilerOptions);
Config.GetValue('PackageFiles', PackageFiles);
end;
{ TFppkgPackageVariant }
constructor TFppkgPackageVariant.Create;
begin
FItems := TFppkgPackageVariantItemList.Create(True);
end;
destructor TFppkgPackageVariant.Destroy;
begin
FItems.Free;
inherited Destroy;
end;
procedure TFppkgPackageVariant.Save(Config: TConfigStorage);
begin
Inherited;
FItems.Save(Config);
end;
procedure TFppkgPackageVariant.Load(Config: TConfigStorage);
begin
inherited;
FItems.Load(Config);
end;
end.

View File

@ -19,7 +19,7 @@
<Description Value="A packagemanager based on FPC's fppkg"/>
<License Value="GPL"/>
<Version Minor="1"/>
<Files Count="13">
<Files Count="14">
<Item1>
<Filename Value="lazfppkgmanagerintf.pas"/>
<HasRegisterProc Value="True"/>
@ -64,32 +64,39 @@
<Item11>
<Filename Value="fppkg_environmentoptions.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="fppkg_environmentoptions"/>
<UnitName Value="Fppkg_EnvironmentOptions"/>
</Item11>
<Item12>
<Filename Value="fppkg_interface.pas"/>
<UnitName Value="fppkg_interface"/>
<UnitName Value="Fppkg_Interface"/>
</Item12>
<Item13>
<Filename Value="fppkg_packageoptionsfrm.pas"/>
<UnitName Value="fppkg_packageoptionsfrm"/>
</Item13>
<Item14>
<Filename Value="fppkg_packagevariant.pas"/>
<UnitName Value="fppkg_packagevariant"/>
</Item14>
</Files>
<i18n>
<EnableI18N Value="True"/>
<OutDir Value="..\languages"/>
</i18n>
<RequiredPkgs Count="3">
<RequiredPkgs Count="4">
<Item1>
<PackageName Value="IDEIntf"/>
<PackageName Value="SynEdit"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
<PackageName Value="IDEIntf"/>
</Item2>
<Item3>
<PackageName Value="LCL"/>
</Item3>
<Item4>
<PackageName Value="FCL"/>
<MinVersion Major="1" Release="1" Valid="True"/>
</Item3>
</Item4>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>

View File

@ -10,7 +10,7 @@ interface
uses
lazfppkgmanagerintf, fppkg_const, fppkg_details, fppkg_mainfrm, fppkg_optionsfrm, laz_pkgrepos,
FppkgWorkerThread, Fppkg_EnvironmentOptions, Fppkg_Interface, fppkg_packageoptionsfrm,
LazarusPackageIntf;
fppkg_packagevariant, LazarusPackageIntf;
implementation

View File

@ -6,7 +6,8 @@ interface
uses
Classes,
SysUtils;
SysUtils,
PackageIntf;
type
@ -17,6 +18,9 @@ type
function GetUseFPMakeWhenPossible: Boolean; virtual; abstract;
function GetInstallFPMakeDependencies: Boolean; virtual; abstract;
public
function ConstructFpMakeInterfaceSection(APackage: TIDEPackage): string; virtual; abstract;
function ConstructFpMakeImplementationSection(APackage: TIDEPackage): string; virtual; abstract;
function ConstructFpMakeDependenciesFileSection(APackage: TIDEPackage): string; virtual; abstract;
property InstallFPMakeDependencies: Boolean read GetInstallFPMakeDependencies;
property UseFPMakeWhenPossible: Boolean read GetUseFPMakeWhenPossible;
end;

View File

@ -4878,6 +4878,10 @@ begin
s:=s+' P : TPackage;'+e;
s:=s+' T : TTarget;'+e;
s:=s+''+e;
if Assigned(FppkgInterface) then
s := s + FppkgInterface.ConstructFpMakeInterfaceSection(APackage);
s:=s+'begin'+e;
s:=s+' with Installer do'+e;
s:=s+' begin'+e;
@ -4901,23 +4905,31 @@ begin
s := s + StringToFpmakeOptionGroup(' P.IncludePath.Add',IncPath);
s := s + StringToFpmakeOptionGroup(' P.UnitPath.Add', UnitPath);
if Assigned(FppkgInterface) then
s := s + FppkgInterface.ConstructFpMakeImplementationSection(APackage);
s:=s+' T:=P.Targets.AddUnit('''+MainSrcFile+''');'+e;
for i := 0 to APackage.FileCount-1 do
if (APackage.Files[i].FileType=pftUnit) then
s:=s+' t.Dependencies.AddUnit('''+ExtractFileNameOnly(APackage.Files[i].Filename)+''');'+e;
if Assigned(FppkgInterface) then
s := s + FppkgInterface.ConstructFpMakeDependenciesFileSection(APackage)
else
begin
for i := 0 to APackage.FileCount-1 do
if (APackage.Files[i].FileType=pftUnit) then
s:=s+' t.Dependencies.AddUnit('''+ExtractFileNameOnly(APackage.Files[i].Filename)+''');'+e;
s:=s+''+e;
s:=s+''+e;
for i := 0 to APackage.FileCount-1 do
if (APackage.Files[i].FileType=pftUnit) then
begin
if (pffAddToPkgUsesSection in APackage.Files[i].Flags) then
s:=s+' T:=P.Targets.AddUnit('''+CreateRelativePath(APackage.Files[i].Filename,APackage.Directory)+''');'+e
else
for i := 0 to APackage.FileCount-1 do
if (APackage.Files[i].FileType=pftUnit) then
begin
s:=s+' P.Targets.AddImplicitUnit('''+CreateRelativePath(APackage.Files[i].Filename,APackage.Directory)+''');'+e;
if (pffAddToPkgUsesSection in APackage.Files[i].Flags) then
s:=s+' T:=P.Targets.AddUnit('''+CreateRelativePath(APackage.Files[i].Filename,APackage.Directory)+''');'+e
else
begin
s:=s+' P.Targets.AddImplicitUnit('''+CreateRelativePath(APackage.Files[i].Filename,APackage.Directory)+''');'+e;
end;
end;
end;
end;
s:=s+''+e;
s:=s+' // copy the compiled file, so the IDE knows how the package was compiled'+e;