DocMgr: added selectable FCL packages

git-svn-id: trunk@35414 -
This commit is contained in:
dodi 2012-02-17 12:25:20 +00:00
parent 922fe9141a
commit 5f5da586dd
7 changed files with 185 additions and 17 deletions

View File

@ -187,6 +187,8 @@ procedure TConfigFile.WriteSection(const Section: string; Strings: TStrings);
var var
sec: TStringList; sec: TStringList;
begin begin
if Strings.Count = 0 then
exit; //delete section???
sec := AddSection(Section); sec := AddSection(Section);
if not sec.Equals(Strings) then begin if not sec.Equals(Strings) then begin
sec.Assign(Strings); sec.Assign(Strings);

View File

@ -1079,6 +1079,11 @@ This method searches the units for the given description files and adds them to
<short>Searches for source files in ADir, which match an unit name in AList, and returns -1 if none matches.</short> <short>Searches for source files in ADir, which match an unit name in AList, and returns -1 if none matches.</short>
<descr>Used to find input files for description files. The Result is not very useful, because the matched entry is removed from AList.</descr> <descr>Used to find input files for description files. The Result is not very useful, because the matched entry is removed from AList.</descr>
</element> </element>
<element name="TFCLDocPackage.SrcDirs">
<short>List of all FCL source directories, with include indicators.</short>
<descr>The list constains name/value pairs. The name is the directory part of $FPC/packages/NAME/src/, or ../packages/NAME/src/.
A nonzero value indicates that the directory is included into the docs.</descr>
</element>
</module> </module>
<!-- uManager --> <!-- uManager -->
</package> </package>

View File

@ -1,7 +1,7 @@
object CfgWizard: TCfgWizard object CfgWizard: TCfgWizard
Left = 362 Left = 368
Height = 300 Height = 300
Top = 165 Top = 116
Width = 317 Width = 317
Caption = 'Configuration Assistant' Caption = 'Configuration Assistant'
ClientHeight = 300 ClientHeight = 300
@ -214,12 +214,46 @@ object CfgWizard: TCfgWizard
object swFCLads: TCheckBox object swFCLads: TCheckBox
Left = 12 Left = 12
Height = 19 Height = 19
Hint = 'Add lazarus/docs/xml/fcl to the FCL descriptions'
Top = 56 Top = 56
Width = 169 Width = 169
Caption = 'Add Lazarus docs to the FCL' Caption = 'Add Lazarus docs to the FCL'
OnChange = swFCLadsChange OnChange = swFCLadsChange
TabOrder = 0 TabOrder = 0
end end
object swDirs: TCheckListBox
Left = 12
Height = 128
Hint = 'Check the directories to include into the FCL docs'
Top = 80
Width = 280
Anchors = [akTop, akLeft, akRight, akBottom]
Columns = 2
Items.Strings = (
'fcl-base'
'fcl-db'
'fcl-extra'
'fcl-process'
'fcl-web'
'paszlib'
)
ItemHeight = 17
OnExit = swDirsExit
TabOrder = 1
Data = {
06000000010101010101
}
end
object buScanFcl: TButton
Left = 217
Height = 25
Hint = 'Scan the FCL source directory'
Top = 50
Width = 75
Caption = 'Scan FCL'
OnClick = buScanFclClick
TabOrder = 2
end
end end
end end
object sb: TStatusBar object sb: TStatusBar

View File

@ -24,6 +24,8 @@ type
buCancel: TButton; buCancel: TButton;
buRtlBat: TButton; buRtlBat: TButton;
buLazDir: TButton; buLazDir: TButton;
buScanFcl: TButton;
swDirs: TCheckListBox;
swFCLads: TCheckBox; swFCLads: TCheckBox;
edFpcDir: TEdit; edFpcDir: TEdit;
edFpcDocs: TEdit; edFpcDocs: TEdit;
@ -52,6 +54,7 @@ type
procedure buLazDirClick(Sender: TObject); procedure buLazDirClick(Sender: TObject);
procedure buNextClick(Sender: TObject); procedure buNextClick(Sender: TObject);
procedure buRtlBatClick(Sender: TObject); procedure buRtlBatClick(Sender: TObject);
procedure buScanFclClick(Sender: TObject);
procedure buSelFpcClick(Sender: TObject); procedure buSelFpcClick(Sender: TObject);
procedure buSelFpcDocsClick(Sender: TObject); procedure buSelFpcDocsClick(Sender: TObject);
procedure buSelRootClick(Sender: TObject); procedure buSelRootClick(Sender: TObject);
@ -66,9 +69,12 @@ type
procedure MkRTLShow(Sender: TObject); procedure MkRTLShow(Sender: TObject);
procedure SelFPDirShow(Sender: TObject); procedure SelFPDirShow(Sender: TObject);
procedure SelRootShow(Sender: TObject); procedure SelRootShow(Sender: TObject);
procedure swDirsExit(Sender: TObject);
procedure swFCLadsChange(Sender: TObject); procedure swFCLadsChange(Sender: TObject);
private private
NoRun: boolean; NoRun: boolean;
procedure GetFclDirs;
procedure PutFclDirs;
public public
{ public declarations } { public declarations }
end; end;
@ -80,6 +86,8 @@ implementation
uses uses
uManager; uManager;
var
FclPkg: TDocPackage;
{$R *.lfm} {$R *.lfm}
@ -158,6 +166,7 @@ begin
swFCLads.Checked := False; swFCLads.Checked := False;
ShowMessage('Please select FPC and Lazarus directories first!'); ShowMessage('Please select FPC and Lazarus directories first!');
end; end;
GetFclDirs;
end; end;
procedure TCfgWizard.MkLCLShow(Sender: TObject); procedure TCfgWizard.MkLCLShow(Sender: TObject);
@ -246,10 +255,75 @@ begin
buNext.Enabled := Manager.RootDir <> ''; buNext.Enabled := Manager.RootDir <> '';
end; end;
procedure TCfgWizard.swDirsExit(Sender: TObject);
begin
if swDirs.Count > 0 then
PutFclDirs;
end;
procedure TCfgWizard.swFCLadsChange(Sender: TObject); procedure TCfgWizard.swFCLadsChange(Sender: TObject);
begin begin
Manager.UpdateFCL(swFCLads.Checked); Manager.UpdateFCL(swFCLads.Checked);
end; end;
procedure TCfgWizard.buScanFclClick(Sender: TObject);
var
s: string;
begin
s := Manager.FpcDir + 'packages' + DirectorySeparator;
ListDirs(s, swDirs.Items); //dupes suppressed
swDirs.Sorted := True; //sort?
PutFclDirs;
end;
procedure TCfgWizard.GetFclDirs;
var
i, il: integer;
s: string;
b: boolean;
lst: TStrings;
begin
//read fcl.SrcDirs
FclPkg := Manager.AddPackage('fcl');
if FclPkg = nil then
exit;
lst := FclPkg.SrcDirs;
if (lst = nil) or (lst.Count = 0) then begin
//scan FCL
buScanFclClick(nil);
exit;
end;
//read from config
swDirs.Clear;
for i := 0 to lst.Count - 1 do begin
s := lst.Names[i];
b := lst.ValueFromIndex[i] > '0';
il := swDirs.Items.Add(s); //dupes?
swDirs.Checked[il] := b;
end;
end;
procedure TCfgWizard.PutFclDirs;
var
i, il: integer;
s: string;
b: boolean;
lst: TStrings;
const
tf: array[boolean] of string = ('0','1');
begin
if FclPkg = nil then
exit;
lst := FclPkg.SrcDirs;
if (lst = nil) then
exit;
for i := 0 to swDirs.Count - 1 do begin
s := swDirs.Items[i];
b := swDirs.Checked[i];
lst.Values[s] := tf[b];
end;
FclPkg.UpdateConfig;
end;
end. end.

View File

@ -587,7 +587,12 @@ begin
u := CurUnit u := CurUnit
else else
u := ''; u := '';
Manager.Update(CurPkg, u); try
Manager.Update(CurPkg, u);
except
on e: Exception do
LogToFile(self, e.Message);
end;
LogDone; LogDone;
end; end;

View File

@ -174,7 +174,8 @@ type
function CheckSkelOptions: string; function CheckSkelOptions: string;
function CleanXML(const FileName: string): boolean; function CleanXML(const FileName: string): boolean;
function SelectedPackage: TFPDocPackage; function SelectedPackage: TFPDocPackage;
property Package: TFPDocPackage read SelectedPackage write SetPackage; //property Package: TFPDocPackage read SelectedPackage write SetPackage;
property Package: TFPDocPackage read FPackage write SetPackage; //without message
property CmdAction: TCreatorAction read FCmdAction write SetCmdAction; property CmdAction: TCreatorAction read FCmdAction write SetCmdAction;
property DryRun: boolean read FDryRun write SetDryRun; property DryRun: boolean read FDryRun write SetDryRun;
property ReadProject: boolean read FProjectFile; property ReadProject: boolean read FProjectFile;
@ -1020,7 +1021,6 @@ begin
end; end;
function TFPDocMaker.ParseFPDocOption(const S: string): TCreatorAction; function TFPDocMaker.ParseFPDocOption(const S: string): TCreatorAction;
//procedure TFPDocAplication.Parseoption(Const S : String);
var var
Cmd, Arg: String; Cmd, Arg: String;
begin begin
@ -1030,7 +1030,9 @@ begin
if Result <> caInvalid then if Result <> caInvalid then
exit; exit;
Result := caDefault; //assume succ Result := caDefault; //assume succ
if Cmd = '--content' then if (Cmd = '-t') or (Cmd = '--emit-notes') then
Options.EmitNotes := True
else if Cmd = '--content' then
SelectedPackage.ContentFile := Arg SelectedPackage.ContentFile := Arg
else if Cmd = '--import' then else if Cmd = '--import' then
SelectedPackage.Imports.Add(Arg) SelectedPackage.Imports.Add(Arg)

View File

@ -69,6 +69,7 @@ type
FName: string; FName: string;
FProjectDir: string; FProjectDir: string;
FProjectFile: string; FProjectFile: string;
FSrcDirs: TStrings;
FRequires: TStrings; FRequires: TStrings;
FUnitPath: string; FUnitPath: string;
FUnits: TStrings; FUnits: TStrings;
@ -88,9 +89,9 @@ type
procedure SetUnits(AValue: TStrings); procedure SetUnits(AValue: TStrings);
protected protected
Config: TConfigFile; Config: TConfigFile;
procedure ReadConfig; procedure ReadConfig; virtual;
public public
constructor Create; constructor Create; virtual;
destructor Destroy; override; destructor Destroy; override;
function IniFileName: string; function IniFileName: string;
function CreateProject(APrj: TFPDocHelper; const AFile: string): boolean; virtual; //new package project function CreateProject(APrj: TFPDocHelper; const AFile: string): boolean; virtual; //new package project
@ -108,6 +109,7 @@ type
property Descriptions: TStrings read FDescriptions write SetDescriptions; property Descriptions: TStrings read FDescriptions write SetDescriptions;
property AltDir: string read FAltDir write SetAltDir; property AltDir: string read FAltDir write SetAltDir;
property InputDir: string read FInputDir write SetInputDir; property InputDir: string read FInputDir write SetInputDir;
property SrcDirs: TStrings read FSrcDirs;
property Units: TStrings read FUnits write SetUnits; property Units: TStrings read FUnits write SetUnits;
property Requires: TStrings read FRequires write SetRequires; //only string? property Requires: TStrings read FRequires write SetRequires; //only string?
property IncludePath: string read FIncludePath write SetIncludePath; //-Fi property IncludePath: string read FIncludePath write SetIncludePath; //-Fi
@ -117,6 +119,8 @@ type
{ TFCLDocPackage } { TFCLDocPackage }
TFCLDocPackage = class(TDocPackage) TFCLDocPackage = class(TDocPackage)
protected
procedure ReadConfig; override;
public public
function CreateProject(APrj: TFPDocHelper; const AFile: string): boolean; override; function CreateProject(APrj: TFPDocHelper; const AFile: string): boolean; override;
end; end;
@ -256,7 +260,8 @@ begin
if not ((Info.Attr and faDirectory) = faDirectory) then if not ((Info.Attr and faDirectory) = faDirectory) then
continue; continue;
s := Info.Name; s := Info.Name;
if s[1] <> '.' then if (s[1] <> '.')
and (AList.IndexOf(s) < 0) then //exclude dupes
AList.Add(s); //name only, allow to create relative refs AList.Add(s); //name only, allow to create relative refs
until FindNext(info)<>0; until FindNext(info)<>0;
end; end;
@ -303,17 +308,34 @@ end;
{ TFCLDocPackage } { TFCLDocPackage }
procedure TFCLDocPackage.ReadConfig;
begin
inherited ReadConfig;
if FSrcDirs = nil then
FSrcDirs := TStringList.Create;
Config.ReadSection('SrcDirs', FSrcDirs);
end;
function TFCLDocPackage.CreateProject(APrj: TFPDocHelper; const AFile: string function TFCLDocPackage.CreateProject(APrj: TFPDocHelper; const AFile: string
): boolean; ): boolean;
var var
i: integer; i: integer;
s, d, f: string; s, d, f: string;
dirs, descs: TStringList; dirs, descs: TStringList;
incl, excl: boolean;
begin begin
(* This seems to be called twice for Refresh???
*)
if APrj.Package <> nil then
exit(True); //already configured
Result:=inherited CreateProject(APrj, AFile); Result:=inherited CreateProject(APrj, AFile);
//add lazdir //add lazdir
if AltDir = '' then exit; if AltDir = '' then exit;
dirs := TStringList.Create; (* Add inputs for all descrs found in AltDir.
For *MakeSkel* add all units in the selected(!) fcl packages to inputs.
How to distinguish both modes?
*)
dirs := TStringList.Create; //use prepared list?
descs := TStringList.Create; descs := TStringList.Create;
s := Manager.LazarusDir + 'docs' + DirectorySeparator + 'xml' + DirectorySeparator + 'fcl'; s := Manager.LazarusDir + 'docs' + DirectorySeparator + 'xml' + DirectorySeparator + 'fcl';
//APrj.ParseFPDocOption(Format('--descr-dir="%s"', [s])); //todo: add includes //APrj.ParseFPDocOption(Format('--descr-dir="%s"', [s])); //todo: add includes
@ -327,12 +349,31 @@ begin
for i := dirs.Count - 1 downto 0 do begin for i := dirs.Count - 1 downto 0 do begin
d := s + dirs[i] + DirectorySeparator + 'src'; d := s + dirs[i] + DirectorySeparator + 'src';
if not DirectoryExists(d) then continue; if not DirectoryExists(d) then continue;
if MatchUnits(d, descs) >= 0 then begin (* Problem: some files may not parse without specific compiler options.
//add dir Creating skeletons will fail for these files, but how can we in/exclude
APrj.ParseFPDocOption(Format('--input-dir="%s"', [d])); //todo: add includes? specific source files from skeleton creation?
For now: skip explicitly excluded packages!
*)
excl := (assigned(FSrcDirs)
and (SrcDirs.IndexOfName(dirs[i]) >= 0)
and (SrcDirs.Values[dirs[i]] <= '0'));
if excl then begin
//todo: add only selected units
Manager.DoLog('Skipping directory ' + dirs[i]);
end else begin
incl := (assigned(FSrcDirs)
and (SrcDirs.IndexOfName(dirs[i]) >= 0)
and (SrcDirs.Values[dirs[i]] > '0'))
or (MatchUnits(d, descs) >= 0);
if incl then begin
//add dir
Manager.DoLog('Adding directory ' + dirs[i]);
APrj.ParseFPDocOption(Format('--input-dir="%s"', [d])); //todo: add includes?
end;
end; end;
end; end;
//re-create project? //re-create project? The normal project was already created by inherited!
if AFile <> '' then begin if AFile <> '' then begin
f := ChangeFileExt(AFile, '_ext.xml'); //preserve unmodified project? f := ChangeFileExt(AFile, '_ext.xml'); //preserve unmodified project?
APrj.CreateProjectFile(f); APrj.CreateProjectFile(f);
@ -506,10 +547,11 @@ end;
destructor TDocPackage.Destroy; destructor TDocPackage.Destroy;
begin begin
FreeAndNil(Config);
FreeAndNil(FUnits); FreeAndNil(FUnits);
FreeAndNil(FDescriptions); FreeAndNil(FDescriptions);
FreeAndNil(FRequires); FreeAndNil(FRequires);
FreeAndNil(Config); FreeAndNil(FSrcDirs);
inherited Destroy; inherited Destroy;
end; end;
@ -523,8 +565,11 @@ var
pkg: TFPDocPackage; pkg: TFPDocPackage;
i: integer; i: integer;
begin begin
Result := False; Result := APrj.Package <> nil; //already configured?
if ProjectDir = '' then if Result then
exit;
Result := ProjectDir <> '';
if not Result then
exit; //dir must be known exit; //dir must be known
//create pkg //create pkg
APrj.ParseFPDocOption('--package=' + Name); //selects or creates the pkg APrj.ParseFPDocOption('--package=' + Name); //selects or creates the pkg
@ -670,6 +715,7 @@ begin
//units //units
Config.WriteSectionValues('units', Units); Config.WriteSectionValues('units', Units);
Config.WriteSectionValues('descrs', Descriptions); Config.WriteSectionValues('descrs', Descriptions);
Config.WriteSectionValues('SrcDirs', SrcDirs);
//all done //all done
Config.Flush; Config.Flush;
Loaded := True; Loaded := True;