* Added ability to use include-files in configuration-files

git-svn-id: trunk@34717 -
This commit is contained in:
joost 2016-10-15 12:08:26 +00:00
parent df8687c259
commit 41c9543ddf
2 changed files with 116 additions and 0 deletions

View File

@ -114,6 +114,11 @@ Resourcestring
SLogRepositoryPath = ' Dir: "%s" -> "%s"';
SLogRepositoryPrefix = ' Prefix: "%s" -> "%s"';
SLogIncludeFile = ' IncludeFile: "%s" -> "\%s"';
SLogIncludeFileMask = ' IncludeFileMask: "%s" -> "\%s"';
SLogIncludeFileDoesNotExist = 'The log-file "%s" does not exist';
SLogIncludeFileMaskDoesNotExist = 'The directory "%s" of the include-mask "%s" does not exist';
SLogPackageInfoName = 'Package: %s';
SLogPackageInfoVersion = 'Version: %s';
SLogPackageInfoAuthor = 'Author: %s %s';

View File

@ -32,6 +32,7 @@ Type
{ TFppkgOptionSection }
TCompilerOptions = class;
TFppkgOptions = class;
TFppkgOptionSection = class(TPersistent)
private
FOptionParser: TTemplateParser;
@ -137,6 +138,25 @@ Type
property Prefix: string read GetPrefix write SetPrefix;
end;
{ TFppkgIncludeFilesOptionSection }
TFppkgIncludeFilesOptionSection = class(TFppkgOptionSection)
private
FOptions: TFppkgOptions;
// Only used for logging
FOptionCache: TStringList;
FCurrentDir: String;
procedure IncludeFile(AFileName: string);
procedure IncludeFileMask(AFileNameMask: string);
public
constructor Create(AnOptionParser: TTemplateParser; AnOptions: TFppkgOptions; ACurrentDir: string);
destructor Destroy; override;
procedure AddKeyValue(const AKey, AValue: string); override;
procedure LogValues(ALogLevel: TLogLevel); override;
function AllowDuplicate: Boolean; override;
end;
{ TFppkgCommandLineOptionSection }
TFppkgCommandLineOptionSection = class(TFppkgOptionSection)
@ -260,6 +280,7 @@ Const
KeyGlobalSection = 'Global';
KeyRepositorySection = 'Repository';
KeySrcRepositorySection = 'UninstalledSourceRepository';
KeyIncludeFilesSection = 'IncludeFiles';
KeyRemoteMirrorsURL = 'RemoteMirrors';
KeyRemoteRepository = 'RemoteRepository';
KeyLocalRepository = 'LocalRepository';
@ -277,6 +298,9 @@ Const
KeyRepositoryPath = 'Path';
KeyRepositoryPrefix = 'Prefix';
KeyIncludeFile = 'File';
KeyIncludeFileMask = 'FileMask';
// Compiler dependent config
KeyGlobalPrefix = 'GlobalPrefix';
KeyLocalPrefix = 'LocalPrefix';
@ -287,6 +311,91 @@ Const
KeyCompilerCPU = 'CPU';
KeyCompilerVersion = 'Version';
{ TFppkgIncludeFilesOptionSection }
procedure TFppkgIncludeFilesOptionSection.IncludeFile(AFileName: string);
begin
AFileName := FOptionParser.ParseString(AFileName);
if FileExists(AFileName) then
begin
FOptions.LoadFromFile(AFileName);
end
else
log(llWarning, SLogIncludeFileDoesNotExist, [AFileName]);
end;
procedure TFppkgIncludeFilesOptionSection.IncludeFileMask(AFileNameMask: string);
var
FileDir: string;
SR: TSearchRec;
begin
AFileNameMask := FOptionParser.ParseString(AFileNameMask);
FileDir := IncludeTrailingPathDelimiter(ExtractFileDir(AFileNameMask));
if IsRelativePath(AFileNameMask) then
FileDir := ConcatPaths([FCurrentDir, FileDir]);
if DirectoryExists(FileDir) then
begin
if IsRelativePath(AFileNameMask) then
AFileNameMask := ConcatPaths([FCurrentDir, AFileNameMask]);
if FindFirst(AFileNameMask, faAnyFile-faDirectory, SR)=0 then
begin
repeat
IncludeFile(FileDir+SR.Name);
until FindNext(SR)<>0;
end;
end
else
log(llWarning, SLogIncludeFileMaskDoesNotExist, [FileDir, AFileNameMask]);
end;
constructor TFppkgIncludeFilesOptionSection.Create(AnOptionParser: TTemplateParser;
AnOptions: TFppkgOptions; ACurrentDir: string);
begin
inherited Create(AnOptionParser);
FOptions := AnOptions;
FCurrentDir := ACurrentDir;
FOptionCache := TStringList.Create;
end;
destructor TFppkgIncludeFilesOptionSection.Destroy;
begin
FOptionCache.Free;
inherited Destroy;
end;
procedure TFppkgIncludeFilesOptionSection.AddKeyValue(const AKey, AValue: string);
begin
if SameText(AKey,KeyIncludeFile) then
begin
FOptionCache.Append(SLogIncludeFile + '=' + AValue);
IncludeFile(AValue);
end
else if SameText(AKey,KeyIncludeFileMask) then
begin
FOptionCache.Append(SLogIncludeFileMask + '=' + AValue);
IncludeFileMask(AValue);
end;
end;
procedure TFppkgIncludeFilesOptionSection.LogValues(ALogLevel: TLogLevel);
var
i: Integer;
begin
inherited LogValues(ALogLevel);
for i := 0 to FOptionCache.Count -1 do
begin
log(ALogLevel, FOptionCache.Names[i], [FOptionCache.ValueFromIndex[i], FOptionParser.ParseString(FOptionCache.ValueFromIndex[i])]);
end;
end;
function TFppkgIncludeFilesOptionSection.AllowDuplicate: Boolean;
begin
Result := inherited AllowDuplicate;
end;
{ TFppkgRepositoryOptionSection }
procedure TFppkgRepositoryOptionSection.SetDescription(AValue: string);
@ -697,6 +806,8 @@ begin
CurrentSection := TFppkgRepositoryOptionSection.Create(FOptionParser)
else if SameText(s, KeySrcRepositorySection) then
CurrentSection := TFppkgUninstalledSourceRepositoryOptionSection.Create(FOptionParser)
else if SameText(s, KeyIncludeFilesSection) then
CurrentSection := TFppkgIncludeFilesOptionSection.Create(FOptionParser, Self, ExtractFileDir(AFileName))
else
CurrentSection := TFppkgCustomOptionSection.Create(FOptionParser);
FSectionList.Add(CurrentSection);