mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-25 13:29:38 +02:00
* Only add files to an archive when a package is actually being installed
* Do not create archives with no files in it. git-svn-id: trunk@28898 -
This commit is contained in:
parent
678090c48b
commit
89cdc6dafe
@ -67,6 +67,12 @@ Interface
|
|||||||
{$define HAS_TAR_SUPPORT}
|
{$define HAS_TAR_SUPPORT}
|
||||||
{$endif NO_TAR_SUPPORT}
|
{$endif NO_TAR_SUPPORT}
|
||||||
|
|
||||||
|
{$ifdef unix}
|
||||||
|
{$ifdef HAS_TAR_SUPPORT}
|
||||||
|
{$define CREATE_TAR_FILE}
|
||||||
|
{$endif HAS_TAR_SUPPORT}
|
||||||
|
{$endif unix}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$ifdef UNIX}
|
{$ifdef UNIX}
|
||||||
BaseUnix,
|
BaseUnix,
|
||||||
@ -1002,6 +1008,7 @@ Type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{ TBuildEngine }
|
{ TBuildEngine }
|
||||||
|
TCopyFileProc = procedure(const APackage: TPackage; Const ASourceFileName, ADestFileName : String) of object;
|
||||||
|
|
||||||
TBuildEngine = Class(TComponent)
|
TBuildEngine = Class(TComponent)
|
||||||
private
|
private
|
||||||
@ -1029,6 +1036,8 @@ Type
|
|||||||
FBeforeCompile: TNotifyEvent;
|
FBeforeCompile: TNotifyEvent;
|
||||||
FBeforeInstall: TNotifyEvent;
|
FBeforeInstall: TNotifyEvent;
|
||||||
FBeforeManifest: TNotifyEvent;
|
FBeforeManifest: TNotifyEvent;
|
||||||
|
FOnCopyFile: TCopyFileProc;
|
||||||
|
FOnFinishCopy: TNotifyEvent;
|
||||||
|
|
||||||
FCachedlibcPath: string;
|
FCachedlibcPath: string;
|
||||||
FGeneralCriticalSection: TRTLCriticalSection;
|
FGeneralCriticalSection: TRTLCriticalSection;
|
||||||
@ -1037,7 +1046,10 @@ Type
|
|||||||
{$endif HAS_UNIT_ZIPPER}
|
{$endif HAS_UNIT_ZIPPER}
|
||||||
{$ifdef HAS_TAR_SUPPORT}
|
{$ifdef HAS_TAR_SUPPORT}
|
||||||
FTarWriter: TTarWriter;
|
FTarWriter: TTarWriter;
|
||||||
|
FGZFileStream: TGZFileStream;
|
||||||
{$endif HAS_TAR_SUPPORT}
|
{$endif HAS_TAR_SUPPORT}
|
||||||
|
procedure AddFileToArchive(const APackage: TPackage; Const ASourceFileName, ADestFileName : String);
|
||||||
|
procedure FinishArchive(Sender: TObject);
|
||||||
Protected
|
Protected
|
||||||
Procedure Error(const Msg : String);
|
Procedure Error(const Msg : String);
|
||||||
Procedure Error(const Fmt : String; const Args : Array of const);
|
Procedure Error(const Fmt : String; const Args : Array of const);
|
||||||
@ -1113,7 +1125,7 @@ Type
|
|||||||
Procedure Compile(APackage : TPackage);
|
Procedure Compile(APackage : TPackage);
|
||||||
Procedure MaybeCompile(APackage:TPackage);
|
Procedure MaybeCompile(APackage:TPackage);
|
||||||
Function ReadyToCompile(APackage:TPackage) : Boolean;
|
Function ReadyToCompile(APackage:TPackage) : Boolean;
|
||||||
Procedure Install(APackage : TPackage);
|
Procedure Install(APackage : TPackage; AnArchiveFiles: boolean);
|
||||||
Procedure Archive(APackage : TPackage);
|
Procedure Archive(APackage : TPackage);
|
||||||
Procedure Manifest(APackage : TPackage);
|
Procedure Manifest(APackage : TPackage);
|
||||||
Procedure Clean(APackage : TPackage; AllTargets: boolean);
|
Procedure Clean(APackage : TPackage; AllTargets: boolean);
|
||||||
@ -4712,6 +4724,66 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBuildEngine.AddFileToArchive(const APackage: TPackage; const ASourceFileName, ADestFileName: String);
|
||||||
|
var
|
||||||
|
SourceDir: string;
|
||||||
|
begin
|
||||||
|
{$ifdef CREATE_TAR_FILE}
|
||||||
|
{$ifdef HAS_TAR_SUPPORT}
|
||||||
|
if not assigned(FTarWriter) then
|
||||||
|
begin
|
||||||
|
FGZFileStream := TGZFileStream.create(Defaults.ZipPrefix + APackage.Name + MakeZipSuffix(Defaults.CPU,Defaults.OS) +'.tar.gz', gzopenwrite);
|
||||||
|
try
|
||||||
|
FTarWriter := TTarWriter.Create(FGZFileStream);
|
||||||
|
FTarWriter.Permissions := [tpReadByOwner, tpWriteByOwner, tpReadByGroup, tpReadByOther];
|
||||||
|
FTarWriter.UserName := 'root';
|
||||||
|
FTarWriter.GroupName := 'root';
|
||||||
|
except
|
||||||
|
FGZFileStream.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
FTarWriter.AddFile(ASourceFileName, ADestFileName);
|
||||||
|
{$endif HAS_TAR_SUPPORT}
|
||||||
|
{$else CREATE_TAR_FILE}
|
||||||
|
{$ifdef HAS_UNIT_ZIPPER}
|
||||||
|
if not assigned(FZipper) then
|
||||||
|
begin
|
||||||
|
FZipper := TZipper.Create;
|
||||||
|
FZipper.FileName := Defaults.ZipPrefix + APackage.Name + MakeZipSuffix(Defaults.CPU,Defaults.OS) + '.zip';
|
||||||
|
end;
|
||||||
|
|
||||||
|
if assigned(APackage) and (APackage.Directory<>'') then
|
||||||
|
SourceDir:=IncludeTrailingPathDelimiter(APackage.Directory)
|
||||||
|
else
|
||||||
|
SourceDir:='';
|
||||||
|
|
||||||
|
FZipper.Entries.AddFileEntry(SourceDir + ASourceFileName, ADestFileName);
|
||||||
|
{$endif HAS_UNIT_ZIPPER}
|
||||||
|
{$ENDIF CREATE_TAR_FILE}
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TBuildEngine.FinishArchive(Sender: TObject);
|
||||||
|
begin
|
||||||
|
{$ifdef HAS_TAR_SUPPORT}
|
||||||
|
if assigned(FTarWriter) then
|
||||||
|
begin
|
||||||
|
FreeAndNil(FTarWriter);
|
||||||
|
FGZFileStream.Free;
|
||||||
|
end;
|
||||||
|
{$endif HAS_TAR_SUPPORT}
|
||||||
|
{$ifdef HAS_UNIT_ZIPPER}
|
||||||
|
if assigned(FZipper) then
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
FZipper.ZipAllFiles;
|
||||||
|
FZipper.Clear;
|
||||||
|
finally
|
||||||
|
FreeAndNil(FZipper);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$endif HAS_UNIT_ZIPPER}
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TBuildEngine.Error(const Msg: String);
|
procedure TBuildEngine.Error(const Msg: String);
|
||||||
begin
|
begin
|
||||||
@ -4977,30 +5049,9 @@ Var
|
|||||||
Args : String;
|
Args : String;
|
||||||
I : Integer;
|
I : Integer;
|
||||||
DestFileName : String;
|
DestFileName : String;
|
||||||
SourceDir : string;
|
|
||||||
begin
|
begin
|
||||||
// When the files should be written to an archive, add them
|
// When the files should be written to an archive, add them
|
||||||
if assigned(FZipper) then
|
if assigned(FOnCopyFile) then
|
||||||
begin
|
|
||||||
if assigned(APackage) and (APackage.Directory<>'') then
|
|
||||||
SourceDir:=IncludeTrailingPathDelimiter(APackage.Directory)
|
|
||||||
else
|
|
||||||
SourceDir:='';
|
|
||||||
For I:=0 to List.Count-1 do
|
|
||||||
if List.Names[i]<>'' then
|
|
||||||
begin
|
|
||||||
if IsRelativePath(list.ValueFromIndex[i]) then
|
|
||||||
DestFileName:=DestDir+list.ValueFromIndex[i]
|
|
||||||
else
|
|
||||||
DestFileName:=list.ValueFromIndex[i];
|
|
||||||
FZipper.Entries.AddFileEntry(SourceDir+List.names[i], DestFileName);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
FZipper.Entries.AddFileEntry(SourceDir+List[i], DestDir+ExtractFileName(List[i]));
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
{$ifdef HAS_TAR_SUPPORT}
|
|
||||||
if assigned(FTarWriter) then
|
|
||||||
begin
|
begin
|
||||||
For I:=0 to List.Count-1 do
|
For I:=0 to List.Count-1 do
|
||||||
if List.Names[i]<>'' then
|
if List.Names[i]<>'' then
|
||||||
@ -5009,13 +5060,12 @@ begin
|
|||||||
DestFileName:=DestDir+list.ValueFromIndex[i]
|
DestFileName:=DestDir+list.ValueFromIndex[i]
|
||||||
else
|
else
|
||||||
DestFileName:=list.ValueFromIndex[i];
|
DestFileName:=list.ValueFromIndex[i];
|
||||||
FTarWriter.AddFile(List.names[i], DestFileName);
|
FOnCopyFile(APackage, List.names[i], DestFileName);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
FTarWriter.AddFile(List[i], DestDir+ExtractFileName(List[i]));
|
FOnCopyFile(APackage, List[i], DestDir+ExtractFileName(List[i]));
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
{$endif HAS_TAR_SUPPORT}
|
|
||||||
|
|
||||||
// Copy the files to their new location on disk
|
// Copy the files to their new location on disk
|
||||||
CmdCreateDir(DestDir);
|
CmdCreateDir(DestDir);
|
||||||
@ -6532,7 +6582,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TBuildEngine.Install(APackage: TPackage);
|
procedure TBuildEngine.Install(APackage: TPackage; AnArchiveFiles: boolean);
|
||||||
Var
|
Var
|
||||||
UC,D : String;
|
UC,D : String;
|
||||||
B : Boolean;
|
B : Boolean;
|
||||||
@ -6541,8 +6591,15 @@ begin
|
|||||||
MaybeCompile(APackage);
|
MaybeCompile(APackage);
|
||||||
try
|
try
|
||||||
Log(vlCommand,SInfoInstallingPackage,[APackage.Name]);
|
Log(vlCommand,SInfoInstallingPackage,[APackage.Name]);
|
||||||
|
if AnArchiveFiles and APackage.SeparateArchive then
|
||||||
|
FinishArchive(APackage);
|
||||||
If (APackage.Directory<>'') then
|
If (APackage.Directory<>'') then
|
||||||
EnterDir(APackage.Directory);
|
EnterDir(APackage.Directory);
|
||||||
|
if AnArchiveFiles then
|
||||||
|
begin
|
||||||
|
FOnCopyFile:=@AddFileToArchive;
|
||||||
|
FOnFinishCopy:=@FinishArchive;
|
||||||
|
end;
|
||||||
DoBeforeInstall(APackage);
|
DoBeforeInstall(APackage);
|
||||||
// units
|
// units
|
||||||
B:=false;
|
B:=false;
|
||||||
@ -6581,6 +6638,11 @@ begin
|
|||||||
// Done.
|
// Done.
|
||||||
APackage.FTargetState:=tsInstalled;
|
APackage.FTargetState:=tsInstalled;
|
||||||
DoAfterInstall(APackage);
|
DoAfterInstall(APackage);
|
||||||
|
if AnArchiveFiles then
|
||||||
|
begin
|
||||||
|
FOnCopyFile:=nil;
|
||||||
|
FOnFinishCopy:=nil;
|
||||||
|
end;
|
||||||
Finally
|
Finally
|
||||||
If (APackage.Directory<>'') then
|
If (APackage.Directory<>'') then
|
||||||
EnterDir('');
|
EnterDir('');
|
||||||
@ -6962,7 +7024,7 @@ begin
|
|||||||
P:=Packages.PackageItems[i];
|
P:=Packages.PackageItems[i];
|
||||||
If PackageOK(P) then
|
If PackageOK(P) then
|
||||||
begin
|
begin
|
||||||
Install(P);
|
Install(P, False);
|
||||||
log(vlWarning, SWarnInstallationPackagecomplete, [P.Name, Defaults.Target]);
|
log(vlWarning, SWarnInstallationPackagecomplete, [P.Name, Defaults.Target]);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -6974,65 +7036,14 @@ end;
|
|||||||
|
|
||||||
procedure TBuildEngine.ZipInstall(Packages: TPackages);
|
procedure TBuildEngine.ZipInstall(Packages: TPackages);
|
||||||
|
|
||||||
{$ifdef unix}
|
|
||||||
{$ifdef HAS_TAR_SUPPORT}
|
|
||||||
{$define CreateTarFile}
|
|
||||||
{$endif HAS_TAR_SUPPORT}
|
|
||||||
{$endif unix}
|
|
||||||
|
|
||||||
{$ifdef CreateTarFile}
|
|
||||||
var
|
|
||||||
S : TGZFileStream;
|
|
||||||
|
|
||||||
procedure InitArchive(AFileName: string);
|
|
||||||
begin
|
|
||||||
S := TGZFileStream.create(AFileName +'.tar.gz', gzopenwrite);
|
|
||||||
try
|
|
||||||
FTarWriter := TTarWriter.Create(S);
|
|
||||||
FTarWriter.Permissions := [tpReadByOwner, tpWriteByOwner, tpReadByGroup, tpReadByOther];
|
|
||||||
FTarWriter.UserName := 'root';
|
|
||||||
FTarWriter.GroupName := 'root';
|
|
||||||
except
|
|
||||||
S.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure FinishArchive;
|
|
||||||
begin
|
|
||||||
FreeAndNil(FTarWriter);
|
|
||||||
S.Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{$else}
|
|
||||||
|
|
||||||
procedure InitArchive(AFileName: string);
|
|
||||||
begin
|
|
||||||
FZipper := TZipper.Create;
|
|
||||||
FZipper.FileName := AFileName + '.zip';
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure FinishArchive;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
FZipper.ZipAllFiles;
|
|
||||||
FZipper.Clear;
|
|
||||||
finally
|
|
||||||
FreeAndNil(FZipper);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{$endif}
|
|
||||||
|
|
||||||
var
|
var
|
||||||
I : Integer;
|
I : Integer;
|
||||||
P : TPackage;
|
P : TPackage;
|
||||||
IsArchiveInitialized : boolean;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
If Assigned(BeforeInstall) then
|
If Assigned(BeforeInstall) then
|
||||||
BeforeInstall(Self);
|
BeforeInstall(Self);
|
||||||
|
|
||||||
IsArchiveInitialized:=false;
|
|
||||||
Defaults.IntSetBaseInstallDir('lib/fpc/' + Defaults.FCompilerVersion+ '/');
|
Defaults.IntSetBaseInstallDir('lib/fpc/' + Defaults.FCompilerVersion+ '/');
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -7041,25 +7052,14 @@ begin
|
|||||||
P:=Packages.PackageItems[i];
|
P:=Packages.PackageItems[i];
|
||||||
If PackageOK(P) then
|
If PackageOK(P) then
|
||||||
begin
|
begin
|
||||||
if IsArchiveInitialized and P.SeparateArchive then
|
Install(P, True);
|
||||||
begin
|
|
||||||
FinishArchive;
|
|
||||||
IsArchiveInitialized:=false;
|
|
||||||
end;
|
|
||||||
if not IsArchiveInitialized then
|
|
||||||
begin
|
|
||||||
InitArchive(Defaults.ZipPrefix + P.Name + MakeZipSuffix(Defaults.CPU,Defaults.OS));
|
|
||||||
IsArchiveInitialized:=true;
|
|
||||||
end;
|
|
||||||
Install(P);
|
|
||||||
log(vlWarning, SWarnInstallationPackagecomplete, [P.Name, Defaults.Target]);
|
log(vlWarning, SWarnInstallationPackagecomplete, [P.Name, Defaults.Target]);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log(vlWarning,SWarnSkipPackageTarget,[P.Name, Defaults.Target]);
|
log(vlWarning,SWarnSkipPackageTarget,[P.Name, Defaults.Target]);
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
if IsArchiveInitialized then
|
FinishArchive(P);
|
||||||
FinishArchive;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
If Assigned(AfterInstall) then
|
If Assigned(AfterInstall) then
|
||||||
|
Loading…
Reference in New Issue
Block a user