build_lcl_docs: made xml src dir, pas src dir and include paths generic

git-svn-id: trunk@50684 -
This commit is contained in:
mattias 2015-12-06 12:41:06 +00:00
parent e74f7e54e5
commit 4146a5aea4

View File

@ -9,7 +9,8 @@ program update_lcl_docs;
{$ENDIF} {$ENDIF}
uses uses
Classes, Sysutils, GetOpts, LazFileUtils, FileUtil, UTF8Process, Process; Classes, Sysutils, GetOpts, LazFileUtils, FileUtil, UTF8Process, LazUtilities,
Process;
var var
DefaultFPDocExe: string = 'fpdoc'; DefaultFPDocExe: string = 'fpdoc';
@ -18,44 +19,64 @@ var
Verbosity: integer; Verbosity: integer;
ShowCmd: Boolean; ShowCmd: Boolean;
EnvParams: String; EnvParams: String;
XCTDir: String; DefaultXCTDir: String;
DefaultFPDocParams: string = ''; DefaultFPDocParams: string = '';
DefaultOutFormat: string = 'html'; DefaultOutFormat: string = 'html';
DefaultFooterFilename: string; DefaultFooterFilename: string; // ToDo
type type
TFPDocRunStep = (
frsCreated,
frsVarsInitialized,
frsFilesGathered,
frsOutDirCreated,
frsFPDocExecuted,
frsComplete
);
{ TFPDocRun } { TFPDocRun }
TFPDocRun = class TFPDocRun = class
private private
FFPDocParams: string; FCSSFile: String;
FInputFileList: string; FFooterFilename: String;
FIncludePath: string;
FInputFile: string;
FPackageName: string; FPackageName: string;
FPasSrcDir: string; FPasSrcDir: string;
FStep: TFPDocRunStep;
FXCTDir: string;
FXMLSrcDir: string; FXMLSrcDir: string;
procedure SetFPDocParams(AValue: string); procedure SetCSSFile(AValue: String);
procedure SetInputFileList(AValue: string); procedure SetFooterFilename(AValue: String);
procedure SetIncludePath(AValue: string);
procedure SetInputFile(AValue: string);
procedure SetPasSrcDir(AValue: string); procedure SetPasSrcDir(AValue: string);
procedure SetXCTDir(AValue: string);
procedure SetXMLSrcDir(AValue: string); procedure SetXMLSrcDir(AValue: string);
public public
OutDir: string;
FPDocExe: String; FPDocExe: String;
CSSFile: String;
Params: String; Params: String;
FooterFilename: String; ParseParams: string;
OutFormat: String; OutFormat: String;
UsedPkgs: TStringList; // e.g. 'rtl','fcl', 'lazutils' UsedPkgs: TStringList; // e.g. 'rtl','fcl', 'lazutils'
constructor Create(aPackageName: string); constructor Create(aPackageName: string);
destructor Destroy; override; destructor Destroy; override;
procedure InitVars; procedure InitVars;
procedure AddFilesToList(Dir: String; List: TStrings); procedure AddFilesToList(Dir: String; List: TStrings);
procedure MakeFileList; procedure FindSourceFiles;
procedure CreateOuputDir; procedure CreateOuputDir;
procedure Run; procedure Run;
property PackageName: string read FPackageName; property PackageName: string read FPackageName;
property XMLSrcDir: string read FXMLSrcDir write SetXMLSrcDir; property XMLSrcDir: string read FXMLSrcDir write SetXMLSrcDir;
property PasSrcDir: string read FPasSrcDir write SetPasSrcDir; property PasSrcDir: string read FPasSrcDir write SetPasSrcDir;
property Input_FileList_Filename: string read FInputFileList write SetInputFileList; property IncludePath: string read FIncludePath write SetIncludePath;// semicolon separated search path
property FPDocParams: string read FFPDocParams write SetFPDocParams; property InputFile: string read FInputFile write SetInputFile; // relative to OutDir, automatically created
property CSSFile: String read FCSSFile write SetCSSFile;
property FooterFilename: String read FFooterFilename write SetFooterFilename; // ToDo
property XCTDir: string read FXCTDir write SetXCTDir;
property Step: TFPDocRunStep read FStep;
end; end;
procedure GetEnvDef(var S: String; DefaultValue: String; EnvName: String); procedure GetEnvDef(var S: String; DefaultValue: String; EnvName: String);
@ -136,7 +157,7 @@ begin
2: DefaultFPDocExe := OptArg; 2: DefaultFPDocExe := OptArg;
3: DefaultOutFormat := OptArg; 3: DefaultOutFormat := OptArg;
4: ShowCmd := True; 4: ShowCmd := True;
5: XCTDir := OptArg; 5: DefaultXCTDir := OptArg;
6: DefaultFooterFilename := OptArg; 6: DefaultFooterFilename := OptArg;
7: WarningsCount:=0; 7: WarningsCount:=0;
8: DefaultCssFile := OptArg; 8: DefaultCssFile := OptArg;
@ -157,9 +178,7 @@ begin
GetEnvDef(EnvParams, '', 'FPDOCPARAMS'); GetEnvDef(EnvParams, '', 'FPDOCPARAMS');
GetEnvDef(DefaultFPDocExe, DefaultFPDocExe, 'FPDOC'); GetEnvDef(DefaultFPDocExe, DefaultFPDocExe, 'FPDOC');
GetEnvDef(DefaultFooterFilename, '', 'FPDOCFOOTER'); GetEnvDef(DefaultFooterFilename, '', 'FPDOCFOOTER');
GetEnvDef(XCTDir, XCTDir, 'FPCDOCS'); GetEnvDef(DefaultXCTDir, DefaultXCTDir, 'FPCDOCS');
XCTDir:=TrimAndExpandDirectory(XCTDir);
if DefaultOutFormat = '' then if DefaultOutFormat = '' then
begin begin
@ -170,25 +189,101 @@ end;
{ TFPDocRun } { TFPDocRun }
procedure TFPDocRun.InitVars; procedure TFPDocRun.SetInputFile(AValue: string);
var
Pkg, Prefix: String;
begin begin
AValue:=TrimFilename(AValue);
if FInputFile=AValue then Exit;
FInputFile:=AValue;
end;
procedure TFPDocRun.SetIncludePath(AValue: string);
begin
if FIncludePath=AValue then Exit;
FIncludePath:=AValue;
end;
procedure TFPDocRun.SetCSSFile(AValue: String);
begin
AValue:=TrimAndExpandFilename(AValue);
if FCSSFile=AValue then Exit;
FCSSFile:=AValue;
end;
procedure TFPDocRun.SetFooterFilename(AValue: String);
begin
AValue:=TrimAndExpandFilename(AValue);
if FFooterFilename=AValue then Exit;
FFooterFilename:=AValue;
end;
procedure TFPDocRun.SetPasSrcDir(AValue: string);
begin
AValue:=TrimAndExpandFilename(AValue);
if FPasSrcDir=AValue then Exit;
FPasSrcDir:=AValue;
end;
procedure TFPDocRun.SetXCTDir(AValue: string);
begin
AValue:=TrimAndExpandFilename(AValue);
if FXCTDir=AValue then Exit;
FXCTDir:=AValue;
end;
procedure TFPDocRun.SetXMLSrcDir(AValue: string);
begin
AValue:=TrimAndExpandFilename(AValue);
if FXMLSrcDir=AValue then Exit;
FXMLSrcDir:=AValue;
end;
constructor TFPDocRun.Create(aPackageName: string);
begin
FPackageName:=aPackageName;
UsedPkgs:=TStringList.Create;
InputFile := 'inputfile.txt';
OutDir:=TrimAndExpandFilename(PackageName);
FPDocExe:=TrimFilename(DefaultFPDocExe); FPDocExe:=TrimFilename(DefaultFPDocExe);
CSSFile:=TrimFilename(DefaultCSSFile); CSSFile:=TrimFilename(DefaultCSSFile);
XMLSrcDir := '..'+PathDelim+'..'+PathDelim+'xml'+PathDelim+PackageName+PathDelim; Params := DefaultFPDocParams;
PasSrcDir := '..'+PathDelim+'..'+PathDelim+PackageName+PathDelim;
Input_FileList_Filename := 'inputfile.txt';
FPDocParams := ' --content='+PackageName+'.xct'
+ ' --package='+PackageName
+ ' --descr='+XMLSrcDir+PackageName+'.xml'
+ ' --input=@'+Input_FileList_Filename+' ';
Params:=DefaultFPDocParams;
OutFormat:=DefaultOutFormat; OutFormat:=DefaultOutFormat;
FooterFilename:=TrimFilename(DefaultFooterFilename); FooterFilename:=TrimFilename(DefaultFooterFilename);
XCTDir:=DefaultXCTDir;
FStep:=frsCreated;
end;
Params+=' --format='+OutFormat+' '; destructor TFPDocRun.Destroy;
begin
FreeAndNil(UsedPkgs);
inherited Destroy;
end;
procedure TFPDocRun.InitVars;
var
Pkg, Prefix, IncludeDir: String;
p: Integer;
begin
if ord(Step)>=ord(frsVarsInitialized) then
raise Exception.Create('TFPDocRun.InitVars not again');
// add IncludePath to ParseParams
p:=1;
while p<=length(IncludePath) do begin
IncludeDir:=GetNextDelimitedItem(IncludePath,';',p);
if IncludeDir='' then continue;
IncludeDir:=TrimAndExpandFilename(ChompPathDelim(IncludeDir));
ParseParams+=' -Fi'+CreateRelativePath(IncludeDir,OutDir);
end;
Params += ' --content='+PackageName+'.xct'
+ ' --package='+PackageName
+ ' --descr='+CreateRelativePath(AppendPathDelim(XMLSrcDir)+PackageName+'.xml',OutDir)
+ ' --format='+OutFormat;
if FilenameIsAbsolute(InputFile) then
Params += ' --input=@'+CreateRelativePath(InputFile,OutDir)
else
Params += ' --input=@'+InputFile;
if XCTDir <> '' then if XCTDir <> '' then
begin begin
@ -203,7 +298,7 @@ begin
Prefix:=''; Prefix:='';
GetEnvDef(Prefix, Prefix, UpperCase(Pkg)+'LINKPREFIX'); GetEnvDef(Prefix, Prefix, UpperCase(Pkg)+'LINKPREFIX');
Params+=' --import='+TrimFilename(XCTDir+PathDelim+LowerCase(Pkg)+'.xct'); Params+=' --import='+CreateRelativePath(AppendPathDelim(XCTDir)+LowerCase(Pkg)+'.xct',OutDir);
if Prefix<>'' then if Prefix<>'' then
Params+=','+Prefix; Params+=','+Prefix;
end; end;
@ -211,23 +306,42 @@ begin
if OutFormat='chm' then if OutFormat='chm' then
begin begin
if CSSFile='' then CSSFile:='..'+PathDelim+'fpdoc.css'; //css file is chm only
Params+=' --output='+ ChangeFileExt(PackageName, '.chm') Params+=' --output='+ ChangeFileExt(PackageName, '.chm')
+' --auto-toc --auto-index --make-searchable' +' --auto-toc --auto-index --make-searchable';
+' --css-file='+CSSFile+' '; if CSSFile<>'' then
Params+=' --css-file='+CreateRelativePath(CSSFile,OutDir);
end; end;
if EnvParams<>'' then
Params += ' '+EnvParams;
if Verbosity>0 then
begin
writeln('Verbose Params: ------------------');
writeln('FPDocExe=',FPDocExe);
writeln('OutFormat=',OutFormat);
writeln('CSSFile=',CSSFile);
writeln('FooterFilename=',FooterFilename);
writeln('InputFile=',InputFile);
writeln('OutDir=',OutDir);
writeln('ParseParams=',ParseParams);
writeln('FPDocParams=',Params);
writeln('----------------------------------');
end;
FStep:=frsVarsInitialized;
end; end;
procedure TFPDocRun.AddFilesToList(Dir: String; List: TStrings); procedure TFPDocRun.AddFilesToList(Dir: String; List: TStrings);
var var
FRec: TSearchRec; FRec: TSearchRec;
SubDirs: String; // we do not want the PasSrcDir in this string but the subfolders only
begin begin
Dir:=AppendPathDelim(Dir); Dir:=AppendPathDelim(Dir);
if FindFirstUTF8(Dir+AllFilesMask, faAnyFile, FRec)=0 then if FindFirstUTF8(Dir+AllFilesMask, faAnyFile, FRec)=0 then
repeat repeat
//WriteLn('Checking file ' +FRec.Name); //WriteLn('Checking file ' +FRec.Name);
if (FRec.Name='') or (FRec.Name='.') or (FRec.Name='..') then continue; if (FRec.Name='') or (FRec.Name='.') or (FRec.Name='..') then continue;
if (FRec.Name='fpmake.pp') then continue;
if ((FRec.Attr and faDirectory) <> 0) then if ((FRec.Attr and faDirectory) <> 0) then
begin begin
AddFilesToList(Dir+FRec.Name, List); AddFilesToList(Dir+FRec.Name, List);
@ -235,22 +349,24 @@ begin
end end
else if FilenameIsPascalUnit(FRec.Name) then else if FilenameIsPascalUnit(FRec.Name) then
begin begin
SubDirs := AppendPathDelim(Copy(Dir, Length(PasSrcDir)+1, Length(Dir))); List.Add(Dir+FRec.Name);
if Length(SubDirs) = 1 then
SubDirs:='';
List.Add(SubDirs+FRec.Name);
end; end;
until FindNextUTF8(FRec)<>0; until FindNextUTF8(FRec)<>0;
FindCloseUTF8(FRec); FindCloseUTF8(FRec);
end; end;
procedure TFPDocRun.MakeFileList; procedure TFPDocRun.FindSourceFiles;
var var
FileList: TStringList; FileList: TStringList;
InputList: TStringList; InputList: TStringList;
I: Integer; I: Integer;
XMLFile: String; XMLFile: String;
begin begin
if ord(Step)>=ord(frsFilesGathered) then
raise Exception.Create('TFPDocRun.FindSourceFiles not again');
if ord(Step)<ord(frsVarsInitialized) then
InitVars;
if Verbosity>0 then if Verbosity>0 then
writeln('PasSrcDir="',PasSrcDir,'"'); writeln('PasSrcDir="',PasSrcDir,'"');
FileList := TStringList.Create; FileList := TStringList.Create;
@ -260,11 +376,11 @@ begin
FileList.Sort; FileList.Sort;
for I := 0 to FileList.Count-1 do for I := 0 to FileList.Count-1 do
begin begin
XMLFile := XMLSrcDir+ChangeFileExt(FileList[I],'.xml'); XMLFile := XMLSrcDir+ExtractFileNameOnly(FileList[I])+'.xml';
if FileExistsUTF8(PackageName+PathDelim+XMLFile) and (filelist[i]<>'fpmake.pp') then if FileExistsUTF8(XMLFile) then
begin begin
InputList.Add('..'+PathDelim+PasSrcDir+FileList[I] + ' -Fi..'+PathDelim+PasSrcDir+'include'); InputList.Add(CreateRelativePath(FileList[I],OutDir) + ParseParams);
Params:=Params+' --descr='+XMLSrcDir+ChangeFileExt(FileList[I],'.xml'); Params:=Params+' --descr='+CreateRelativePath(XMLFile,OutDir);
end end
else else
begin begin
@ -275,34 +391,43 @@ begin
end; end;
end; end;
FileList.Free; FileList.Free;
InputList.SaveToFile(PackageName+PathDelim+Input_FileList_Filename); InputList.SaveToFile(InputFile);
InputList.Free; InputList.Free;
FStep:=frsFilesGathered;
end; end;
procedure TFPDocRun.CreateOuputDir; procedure TFPDocRun.CreateOuputDir;
var
OutDir: String;
begin begin
OutDir:=PackageName; if ord(Step)>=ord(frsOutDirCreated) then
raise Exception.Create('TFPDocRun.CreateOuputDir not again');
if ord(Step)<ord(frsFilesGathered) then
FindSourceFiles;
if Not DirectoryExistsUTF8(OutDir) then if Not DirectoryExistsUTF8(OutDir) then
begin begin
writeln('Creating directory "',OutDir,'"'); writeln('Creating directory "',OutDir,'"');
if not CreateDirUTF8(OutDir) then if not CreateDirUTF8(OutDir) then
raise Exception.Create('unable to create directory "'+OutDir+'"'); raise Exception.Create('unable to create directory "'+OutDir+'"');
end; end;
FStep:=frsOutDirCreated;
end; end;
procedure TFPDocRun.Run; procedure TFPDocRun.Run;
var var
Process: TProcess; Process: TProcess;
CmdLine: String; CmdLine: String;
WorkDir: String;
begin begin
CmdLine := FPDocExe + FPDocParams + Params + EnvParams; if ord(Step)>=ord(frsFPDocExecuted) then
WorkDir := GetCurrentDirUTF8+PathDelim+PackageName; raise Exception.Create('TFPDocRun.Run not again');
if ord(Step)<ord(frsOutDirCreated) then
CreateOuputDir;
CmdLine := FPDocExe + Params;
if ShowCmd then if ShowCmd then
begin begin
Writeln('WorkDirectory:',WorkDir); Writeln('WorkDirectory:',OutDir);
WriteLn(CmdLine); WriteLn(CmdLine);
Exit; Exit;
end; end;
@ -316,7 +441,7 @@ begin
Process := TProcessUTF8.Create(nil); Process := TProcessUTF8.Create(nil);
try try
Process.Options := Process.Options + [poWaitOnExit]; Process.Options := Process.Options + [poWaitOnExit];
Process.CurrentDirectory := WorkDir; Process.CurrentDirectory := OutDir;
Process.CommandLine := CmdLine; Process.CommandLine := CmdLine;
if Verbosity>0 then if Verbosity>0 then
writeln('Command="',Process.CommandLine,'"'); writeln('Command="',Process.CommandLine,'"');
@ -333,42 +458,8 @@ begin
finally finally
Process.Free; Process.Free;
end; end;
end;
procedure TFPDocRun.SetFPDocParams(AValue: string); FStep:=frsComplete;
begin
if FFPDocParams=AValue then Exit;
FFPDocParams:=AValue;
end;
procedure TFPDocRun.SetInputFileList(AValue: string);
begin
if FInputFileList=AValue then Exit;
FInputFileList:=AValue;
end;
procedure TFPDocRun.SetPasSrcDir(AValue: string);
begin
if FPasSrcDir=AValue then Exit;
FPasSrcDir:=AValue;
end;
procedure TFPDocRun.SetXMLSrcDir(AValue: string);
begin
if FXMLSrcDir=AValue then Exit;
FXMLSrcDir:=AValue;
end;
constructor TFPDocRun.Create(aPackageName: string);
begin
UsedPkgs:=TStringList.Create;
FPackageName:=aPackageName;
end;
destructor TFPDocRun.Destroy;
begin
FreeAndNil(UsedPkgs);
inherited Destroy;
end; end;
var var
@ -379,12 +470,10 @@ begin
Run:=TFPDocRun.Create('lcl'); Run:=TFPDocRun.Create('lcl');
Run.UsedPkgs.Add('rtl'); Run.UsedPkgs.Add('rtl');
Run.UsedPkgs.Add('fcl'); Run.UsedPkgs.Add('fcl');
Run.XMLSrcDir := '..'+PathDelim+'xml'+PathDelim+'lcl'+PathDelim;
Run.InitVars; Run.PasSrcDir := '..'+PathDelim+'..'+PathDelim+'lcl'+PathDelim;
Run.MakeFileList; Run.IncludePath := Run.PasSrcDir+PathDelim+'include';
Run.CreateOuputDir;
Run.Run; Run.Run;
Run.Free; Run.Free;
end. end.