fppkg: Create fppkg-configuration for Lazarus automatically

git-svn-id: trunk@55293 -
This commit is contained in:
joost 2017-06-09 19:48:21 +00:00
parent cf2b24196c
commit 6528ea2484
5 changed files with 296 additions and 43 deletions

View File

@ -204,16 +204,6 @@ msgstr ""
msgid "Advanced"
msgstr ""
#: tinitializeoptionsform.buttonpanel.closebutton.caption
msgctxt "tinitializeoptionsform.buttonpanel.closebutton.caption"
msgid "&Close"
msgstr ""
#: tinitializeoptionsform.buttonpanel.okbutton.caption
msgctxt "tinitializeoptionsform.buttonpanel.okbutton.caption"
msgid "&Write Fppkg configuration files"
msgstr ""
#: tinitializeoptionsform.caption
msgid "Create configuration files"
msgstr ""
@ -222,22 +212,55 @@ msgstr ""
msgid "Compiler:"
msgstr ""
#: tinitializeoptionsform.edit1.text
msgid "Edit1"
#: tinitializeoptionsform.fpcbuttonpanel.closebutton.caption
msgctxt "tinitializeoptionsform.fpcbuttonpanel.closebutton.caption"
msgid "&Close"
msgstr ""
#: tinitializeoptionsform.fpcbuttonpanel.okbutton.caption
msgctxt "tinitializeoptionsform.fpcbuttonpanel.okbutton.caption"
msgid "&Write Fppkg configuration files"
msgstr ""
#: tinitializeoptionsform.fpcdirectoryedit.texthint
msgctxt "tinitializeoptionsform.fpcdirectoryedit.texthint"
msgid "This location normally contains the compiler-executable along with a 'units' and 'fpmkinst' directory."
msgstr ""
#: tinitializeoptionsform.initializefppkglabel.caption
msgctxt "tinitializeoptionsform.initializefppkglabel.caption"
msgid "Create new configuration files for fppkg."
msgstr ""
#: tinitializeoptionsform.initializelazaruslabel.caption
msgid "Create new Lazarus configuration file for fppkg."
msgstr ""
#: tinitializeoptionsform.label1.caption
msgctxt "tinitializeoptionsform.label1.caption"
msgid "Please give the location where FPC is installed."
msgstr ""
#: tinitializeoptionsform.label2.caption
msgctxt "tinitializeoptionsform.label2.caption"
msgid "Please give the location where Lazarus is installed."
msgstr ""
#: tinitializeoptionsform.lazarusbuttonpanel.closebutton.caption
msgctxt "tinitializeoptionsform.lazarusbuttonpanel.closebutton.caption"
msgid "&Close"
msgstr ""
#: tinitializeoptionsform.lazarusbuttonpanel.okbutton.caption
msgctxt "tinitializeoptionsform.lazarusbuttonpanel.okbutton.caption"
msgid "&Write Lazarus configuration file"
msgstr ""
#: tinitializeoptionsform.lazarusdirectoryedit.texthint
msgctxt "tinitializeoptionsform.lazarusdirectoryedit.texthint"
msgid "This location normally contains the compiler-executable along with a 'units' and 'fpmkinst' directory."
msgstr ""
#: tinitializeoptionsform.pathlabel.caption
msgid "Path:"
msgstr ""

View File

@ -235,22 +235,55 @@ msgstr "Создание файлов настройки"
msgid "Compiler:"
msgstr "Компилятор:"
#: tinitializeoptionsform.edit1.text
msgid "Edit1"
#: tinitializeoptionsform.fpcbuttonpanel.closebutton.caption
msgctxt "tinitializeoptionsform.fpcbuttonpanel.closebutton.caption"
msgid "&Close"
msgstr "Edit1"
#: tinitializeoptionsform.fpcbuttonpanel.okbutton.caption
msgctxt "tinitializeoptionsform.fpcbuttonpanel.okbutton.caption"
msgid "&Write Fppkg configuration files"
msgstr ""
#: tinitializeoptionsform.fpcdirectoryedit.texthint
msgctxt "tinitializeoptionsform.fpcdirectoryedit.texthint"
msgid "This location normally contains the compiler-executable along with a 'units' and 'fpmkinst' directory."
msgstr "Этот каталог обычно содержит исполнимый файл компилятора наряду с подкаталогами 'units' и 'fpmkinst'."
#: tinitializeoptionsform.initializefppkglabel.caption
msgctxt "tinitializeoptionsform.initializefppkglabel.caption"
msgid "Create new configuration files for fppkg."
msgstr "Создание новых файлов настройки для Fppkg."
#: tinitializeoptionsform.initializelazaruslabel.caption
msgid "Create new Lazarus configuration file for fppkg."
msgstr ""
#: tinitializeoptionsform.label1.caption
msgctxt "tinitializeoptionsform.label1.caption"
msgid "Please give the location where FPC is installed."
msgstr "Задайте путь к FPC."
#: tinitializeoptionsform.label2.caption
msgctxt "tinitializeoptionsform.label2.caption"
msgid "Please give the location where Lazarus is installed."
msgstr ""
#: tinitializeoptionsform.lazarusbuttonpanel.closebutton.caption
msgctxt "tinitializeoptionsform.lazarusbuttonpanel.closebutton.caption"
msgid "&Close"
msgstr ""
#: tinitializeoptionsform.lazarusbuttonpanel.okbutton.caption
msgctxt "tinitializeoptionsform.lazarusbuttonpanel.okbutton.caption"
msgid "&Write Lazarus configuration file"
msgstr ""
#: tinitializeoptionsform.lazarusdirectoryedit.texthint
msgctxt "tinitializeoptionsform.lazarusdirectoryedit.texthint"
msgid "This location normally contains the compiler-executable along with a 'units' and 'fpmkinst' directory."
msgstr ""
#: tinitializeoptionsform.pathlabel.caption
msgid "Path:"
msgstr "Путь:"

View File

@ -1,20 +1,20 @@
object InitializeOptionsForm: TInitializeOptionsForm
Left = 2095
Height = 451
Top = 274
Left = 2512
Height = 450
Top = 301
Width = 473
Caption = 'Create configuration files'
ClientHeight = 451
ClientHeight = 450
ClientWidth = 473
LCLVersion = '1.9.0.0'
object FppkgConfigPanel: TPanel
Left = 0
Height = 451
Height = 450
Top = 0
Width = 473
Align = alClient
BevelOuter = bvNone
ClientHeight = 451
ClientHeight = 450
ClientWidth = 473
TabOrder = 0
Visible = False
@ -40,14 +40,6 @@ object InitializeOptionsForm: TInitializeOptionsForm
Caption = 'Please give the location where FPC is installed.'
ParentColor = False
end
object Edit1: TEdit
Left = -2368
Height = 37
Top = 119
Width = 80
TabOrder = 0
Text = 'Edit1'
end
object FPCDirectoryEdit: TDirectoryEdit
Left = 30
Height = 37
@ -62,7 +54,7 @@ object InitializeOptionsForm: TInitializeOptionsForm
BorderSpacing.Around = 5
BorderSpacing.CellAlignHorizontal = ccaCenter
MaxLength = 0
TabOrder = 1
TabOrder = 0
OnChange = FPCDirectoryEditChange
TextHint = 'This location normally contains the compiler-executable along with a ''units'' and ''fpmkinst'' directory.'
end
@ -79,10 +71,10 @@ object InitializeOptionsForm: TInitializeOptionsForm
ParentColor = False
ParentFont = False
end
object ButtonPanel: TButtonPanel
object FPCButtonPanel: TButtonPanel
Left = 6
Height = 46
Top = 399
Top = 398
Width = 461
OKButton.Name = 'OKButton'
OKButton.Caption = '&Write Fppkg configuration files'
@ -97,7 +89,7 @@ object InitializeOptionsForm: TInitializeOptionsForm
CloseButton.OnClick = CloseButtonClick
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 2
TabOrder = 5
ShowButtons = [pbOK, pbClose]
end
object AdvancedCheckbox: TCheckBox
@ -109,7 +101,7 @@ object InitializeOptionsForm: TInitializeOptionsForm
BorderSpacing.Around = 5
Caption = 'Advanced'
OnChange = AdvancedCheckboxChange
TabOrder = 3
TabOrder = 1
end
object PathLabel: TLabel
Left = 30
@ -134,7 +126,7 @@ object InitializeOptionsForm: TInitializeOptionsForm
BorderSpacing.Right = 25
BorderSpacing.Around = 5
Enabled = False
TabOrder = 4
TabOrder = 2
end
object PrefixLabel: TLabel
Left = 30
@ -159,7 +151,7 @@ object InitializeOptionsForm: TInitializeOptionsForm
BorderSpacing.Right = 25
BorderSpacing.Around = 5
Enabled = False
TabOrder = 5
TabOrder = 3
end
object CompilerLabel: TLabel
Left = 30
@ -184,7 +176,93 @@ object InitializeOptionsForm: TInitializeOptionsForm
BorderSpacing.Right = 25
BorderSpacing.Around = 5
Enabled = False
TabOrder = 6
TabOrder = 4
end
end
object LazarusConfigPanel: TPanel
Left = 0
Height = 450
Top = 0
Width = 473
Align = alClient
BevelOuter = bvNone
ClientHeight = 450
ClientWidth = 473
TabOrder = 1
Visible = False
object LazarusButtonPanel: TButtonPanel
Left = 6
Height = 46
Top = 398
Width = 461
OKButton.Name = 'OKButton'
OKButton.Caption = '&Write Lazarus configuration file'
OKButton.DefaultCaption = False
OKButton.Enabled = False
OKButton.OnClick = OnLazarusButtonClick
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
CloseButton.Name = 'CloseButton'
CloseButton.Caption = '&Close'
CloseButton.DefaultCaption = False
CloseButton.OnClick = CloseButtonClick
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 1
ShowButtons = [pbOK, pbClose]
end
object InitializeLazarusLabel: TLabel
Left = 5
Height = 20
Top = 5
Width = 463
Align = alTop
BorderSpacing.Around = 5
Caption = 'Create new Lazarus configuration file for fppkg.'
ParentColor = False
end
object Label2: TLabel
Left = 30
Height = 20
Top = 40
Width = 438
Align = alTop
BorderSpacing.Left = 25
BorderSpacing.Top = 10
BorderSpacing.Around = 5
Caption = 'Please give the location where Lazarus is installed.'
ParentColor = False
end
object LazarusDirectoryEdit: TDirectoryEdit
Left = 30
Height = 37
Top = 65
Width = 413
ShowHidden = False
ButtonWidth = 23
NumGlyphs = 1
Align = alTop
BorderSpacing.Left = 25
BorderSpacing.Right = 25
BorderSpacing.Around = 5
BorderSpacing.CellAlignHorizontal = ccaCenter
MaxLength = 0
TabOrder = 0
OnChange = LazarusDirectoryEditChange
TextHint = 'This location normally contains the compiler-executable along with a ''units'' and ''fpmkinst'' directory.'
end
object LazarusDirValidationLabel: TLabel
Left = 30
Height = 20
Top = 107
Width = 438
Align = alTop
AutoSize = False
BorderSpacing.Left = 25
BorderSpacing.Around = 5
Font.Color = clMaroon
ParentColor = False
ParentFont = False
end
end
end

View File

@ -7,21 +7,27 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, EditBtn,
ButtonPanel,
fpTemplate,
// fppkg
pkgglobals, pkgFppkg, pkgoptions;
pkgglobals, pkgFppkg, pkgoptions, pkgUninstalledSrcsRepo;
type
{ TInitializeOptionsForm }
TInitializeOptionsForm = class(TForm)
ButtonPanel: TButtonPanel;
AdvancedCheckbox: TCheckBox;
LazarusDirValidationLabel: TLabel;
LazarusButtonPanel: TButtonPanel;
FPCButtonPanel: TButtonPanel;
CompilerEdit: TEdit;
LazarusDirectoryEdit: TDirectoryEdit;
InitializeLazarusLabel: TLabel;
Label2: TLabel;
LazarusConfigPanel: TPanel;
PrefixLabel: TLabel;
PathEdit: TEdit;
FPCDirectoryEdit: TDirectoryEdit;
Edit1: TEdit;
FppkgConfigPanel: TPanel;
InitializeFppkgLabel: TLabel;
Label1: TLabel;
@ -32,12 +38,16 @@ type
procedure AdvancedCheckboxChange(Sender: TObject);
procedure CloseButtonClick(Sender: TObject);
procedure FPCDirectoryEditChange(Sender: TObject);
procedure LazarusDirectoryEditChange(Sender: TObject);
procedure OKButtonClick(Sender: TObject);
procedure OnLazarusButtonClick(Sender: TObject);
private
function IsVersionStr(AString: string): Boolean;
public
class function CheckInitialConfiguration: Boolean;
class function RecreateFppkgConfiguration: Boolean;
class function CheckLazarusConfiguration: Boolean;
class function RecreateLazarusConfiguration: Boolean;
end;
var
@ -66,7 +76,6 @@ begin
if FileExists(Dir+'units') and FileExists(Dir+'fpmkinst') then
begin
FPCDirValidationLabel.Caption := '';
ButtonPanel.OKButton.Enabled := True;
s := ExtractFileName(ExcludeTrailingPathDelimiter(Dir));
Prefix := ExtractFilePath(ExcludeTrailingPathDelimiter(Dir));
@ -93,7 +102,24 @@ begin
begin
FPCDirValidationLabel.Caption := 'Compiler not found at given location'
end;
end;
FPCButtonPanel.OKButton.Enabled := FPCDirValidationLabel.Caption = '';
end;
procedure TInitializeOptionsForm.LazarusDirectoryEditChange(Sender: TObject);
var
Dir: string;
begin
Dir := IncludeTrailingPathDelimiter(LazarusDirectoryEdit.Text);
if not DirectoryExists(Dir) then
LazarusDirValidationLabel.Caption := 'Directory does not exist'
else if DirectoryExists(Dir+'components') and DirectoryExists(Dir+'lcl') and DirectoryExists(Dir+'packager') then
begin
LazarusDirValidationLabel.Caption := '';
end
else
LazarusDirValidationLabel.Caption := 'This location does not seems to contain a valid lazarus-installation';
LazarusButtonPanel.OKButton.Enabled := LazarusDirValidationLabel.Caption = '';
end;
procedure TInitializeOptionsForm.CloseButtonClick(Sender: TObject);
@ -114,9 +140,7 @@ var
FPpkg: TpkgFPpkg;
FileName: string;
CurrentSection: TFppkgRepositoryOptionSection;
Dir: string;
begin
Dir := IncludeTrailingPathDelimiter(FPCDirectoryEdit.Text);
FPpkg := TpkgFPpkg.Create(Self);
try
CurrentSection := FPpkg.Options.AddRepositoryOptionSection(TFppkgRepositoryOptionSection);
@ -143,7 +167,7 @@ begin
// Remove the default configuration-file, so a new one will be generated
FileName:=FPpkg.Options.GlobalSection.CompilerConfigDir+FPpkg.Options.CommandLineSection.CompilerConfig;
if FileExists(FileName) then
DeleteFile(FileName);
RenameFile(FileName, ChangeFileExt(FileName, '.bak'));
// This will create the compiler-configuration file
FPpkg.InitializeCompilerOptions;
finally
@ -151,6 +175,67 @@ begin
end;
end;
procedure TInitializeOptionsForm.OnLazarusButtonClick(Sender: TObject);
var
Dir: string;
LazarusConfFilename: RawByteString;
OptionParser: TTemplateParser;
LazarusConfFile: TStrings;
GlobalOpt: TFppkgGlobalOptionSection;
procedure AddLazarusPackageLocation(ARepoName, ARepoDescription, ALocation: string);
var
SourceOptSection: TFppkgUninstalledSourceRepositoryOptionSection;
OptSection: TFppkgUninstalledRepositoryOptionSection;
begin
OptSection := TFppkgUninstalledRepositoryOptionSection.Create(OptionParser);
SourceOptSection := TFppkgUninstalledSourceRepositoryOptionSection.Create(OptionParser);
try
SourceOptSection.RepositoryName := ARepoName + '-src';
SourceOptSection.Description := ARepoDescription + ' sources';
SourceOptSection.Path := Dir + ALocation;
SourceOptSection.InstallRepositoryName := ARepoName;
SourceOptSection.SaveToStrings(LazarusConfFile);
LazarusConfFile.Add('');
OptSection.RepositoryName := ARepoName;
OptSection.Description := ARepoDescription;
OptSection.Path := Dir + ALocation;
OptSection.SourceRepositoryName := ARepoName + '-src';
OptSection.SaveToStrings(LazarusConfFile);
LazarusConfFile.Add('');
finally
SourceOptSection.Free;
OptSection.Free;
end;
end;
begin
Dir := IncludeTrailingPathDelimiter(LazarusDirectoryEdit.Text);
LazarusConfFilename := ConcatPaths([GetUserDir, '.fppkg', 'config', 'conf.d', 'lazarus.conf']);
LazarusConfFile := TStringList.Create;
try
OptionParser := TTemplateParser.Create;
try
AddLazarusPackageLocation('laz-comp', 'Lazarus components', 'components');
AddLazarusPackageLocation('laz-packages', 'Lazarus packager', 'packager');
AddLazarusPackageLocation('laz-lclbase', 'Lazarus LCL-base', '');
AddLazarusPackageLocation('laz-lcl', 'Lazarus LCL', 'lcl');
LazarusConfFile.Add('[Global]');
LazarusConfFile.Add('FPMakeOptions=--lazarusdir=' + Dir);
finally
OptionParser.Free;
end;
ForceDirectories(ExtractFileDir(LazarusConfFilename));
LazarusConfFile.SaveToFile(LazarusConfFilename);
finally
LazarusConfFile.Free;
end;
end;
function TInitializeOptionsForm.IsVersionStr(AString: string): Boolean;
var
i: Integer;
@ -202,5 +287,30 @@ begin
end;
end;
class function TInitializeOptionsForm.CheckLazarusConfiguration: Boolean;
begin
Result := true;
if not FileExists(ConcatPaths([GetUserDir, '.fppkg', 'config', 'conf.d', 'lazarus.conf'])) then
begin
Result := RecreateLazarusConfiguration;
end;
end;
class function TInitializeOptionsForm.RecreateLazarusConfiguration: Boolean;
var
Frm: TInitializeOptionsForm;
begin
Frm := TInitializeOptionsForm.Create(nil);
try
Frm.LazarusConfigPanel.Visible := True;
if Frm.ShowModal in [mrClose, mrCancel] then
Result := False
else
Result := True;
finally
Frm.Free;
end;
end;
end.

View File

@ -355,6 +355,7 @@ begin
Application.Terminate;
Exit;
end;
TInitializeOptionsForm.CheckLazarusConfiguration;
FFPpkg := TpkgFPpkg.Create(Self);
@ -851,6 +852,14 @@ begin
LoadFppkgConfiguration;
end;
end
else if not Assigned(FFPpkg.FindPackage('lcl', pkgpkInstalled)) then
begin
ShowMessage('Fppkg seems to be configured for using Lazarus-packages, but the LCL could not be found. Please fix the Fppkg-configuration for Lazarus with the wizard or manualy.');
if TInitializeOptionsForm.RecreateLazarusConfiguration then
begin
LoadFppkgConfiguration;
end;
end
else
FFPpkg.LoadLocalAvailableMirrors;
end;