IDE: CheckIfPackageNeedsCompilation: check if default is read only and alternative output directory exists

git-svn-id: trunk@23075 -
This commit is contained in:
mattias 2009-12-10 20:29:14 +00:00
parent 32b72756c1
commit e86f7533e4
2 changed files with 43 additions and 11 deletions

View File

@ -622,6 +622,7 @@ type
FLastCompilerFileDate: integer;
FLastCompilerFilename: string;
FLastCompilerParams: string;
FLastStateFileName: string;
FLazDocPaths: string;
FLicense: string;
FLPKSource: TCodeBuffer;
@ -639,7 +640,7 @@ type
FRegistered: boolean;
FRemovedFiles: TFPList; // TFPList of TPkgFile
FSourceDirectories: TFileReferenceList;
FStateFileDate: longint;
FLastStateFileDate: longint;
FStorePathDelim: TPathDelimSwitch;
FTopologicalLevel: integer;
FTranslated: string;
@ -715,7 +716,7 @@ type
function GetSourceDirs(WithPkgDir, WithoutOutputDir: boolean): string;
procedure GetInheritedCompilerOptions(var OptionsList: TFPList);
function GetOutputDirectory(UseOverride: boolean = true): string; // this can change before building, when default dir is readonly
function GetStateFilename: string;
function GetStateFilename(OutputDir: string = ''): string;
function GetCompileSourceFilename: string;// as GetSrcFilename without directory
function GetSrcFilename: string;
function GetCompilerFilename: string;
@ -847,7 +848,8 @@ type
property RemovedFilesCount: integer read GetRemovedCount;
property RemovedFiles[Index: integer]: TPkgFile read GetRemovedFiles;
property SourceDirectories: TFileReferenceList read FSourceDirectories;
property StateFileDate: longint read FStateFileDate write FStateFileDate;
property LastStateFileDate: longint read FLastStateFileDate write FLastStateFileDate;
property LastStateFileName: string read FLastStateFileName write FLastStateFileName;
property StorePathDelim: TPathDelimSwitch read FStorePathDelim write SetStorePathDelim;
property TopologicalLevel: integer read FTopologicalLevel write FTopologicalLevel;
property Translated: string read FTranslated write FTranslated;
@ -3409,10 +3411,11 @@ begin
Result:='';
end;
function TLazPackage.GetStateFilename: string;
function TLazPackage.GetStateFilename(OutputDir: string = ''): string;
begin
Result:=GetOutputDirectory
+ChangeFileExt(GetCompileSourceFilename,'.compiled');
if OutputDir='' then
OutputDir:=GetOutputDirectory;
Result:=OutputDir+Name+'.compiled';
end;
function TLazPackage.GetSrcFilename: string;

View File

@ -2648,7 +2648,8 @@ begin
APackage.LastCompilerFilename:=CompilerFilename;
APackage.LastCompilerFileDate:=CompilerFileDate;
APackage.LastCompilerParams:=CompilerParams;
APackage.StateFileDate:=FileAgeUTF8(StateFile);
APackage.LastStateFileName:=StateFile;
APackage.LastStateFileDate:=FileAgeUTF8(StateFile);
APackage.Flags:=APackage.Flags+[lpfStateFileLoaded];
except
on E: Exception do begin
@ -2681,7 +2682,8 @@ begin
// read the state file
StateFileAge:=FileAgeUTF8(StateFile);
if (not (lpfStateFileLoaded in APackage.Flags))
or (APackage.StateFileDate<>StateFileAge) then begin
or (APackage.LastStateFileDate<>StateFileAge)
or (APackage.LastStateFileName<>StateFile) then begin
APackage.Flags:=APackage.Flags-[lpfStateFileLoaded];
try
XMLConfig:=TXMLConfig.Create(StateFile);
@ -2692,7 +2694,8 @@ begin
finally
XMLConfig.Free;
end;
APackage.StateFileDate:=StateFileAge;
APackage.LastStateFileName:=StateFile;
APackage.LastStateFileDate:=StateFileAge;
except
on E: Exception do begin
if IgnoreErrors then begin
@ -2743,7 +2746,7 @@ begin
DebugLn('TPkgManager.CheckCompileNeedDueToDependencies No state file for ',RequiredPackage.IDAsString);
exit;
end;
if StateFileAge<RequiredPackage.StateFileDate then begin
if StateFileAge<RequiredPackage.LastStateFileDate then begin
DebugLn('TPkgManager.CheckCompileNeedDueToDependencies Required ',
RequiredPackage.IDAsString,' State file is newer than ',
'State file ',GetOwnerID);
@ -2805,6 +2808,8 @@ var
StateFileAge: Integer;
i: Integer;
CurFile: TPkgFile;
NewOutputDir: String;
OutputDir: String;
begin
Result:=mrYes;
{$IFDEF VerbosePkgCompile}
@ -2813,7 +2818,7 @@ begin
NeedBuildAllFlag:=false;
if APackage.AutoUpdate=pupManually then exit(mrNo);
if (APackage.LastCompilerFilename<>CompilerFilename)
or (ExtractCompilerParamsForBuildAll(APackage.LastCompilerParams)
<>ExtractCompilerParamsForBuildAll(CompilerParams))
@ -2823,6 +2828,30 @@ begin
then
NeedBuildAllFlag:=true;
if (APackage.CompilerOptions.ParsedOpts.OutputDirectoryOverride='') then
begin
OutputDir:=APackage.GetOutputDirectory(false);
if not DirectoryIsWritableCached(OutputDir) then
begin
// the package uses the default output directory, but the default is
// not writable.
// => check the alternative
if Assigned(OnGetWritablePkgOutputDirectory) then begin
NewOutputDir:=OutputDir;
OnGetWritablePkgOutputDirectory(APackage,NewOutputDir);
if (NewOutputDir<>OutputDir) and (NewOutputDir<>'') then begin
StateFilename:=APackage.GetStateFilename(NewOutputDir);
if FileExistsCached(StateFilename) then begin
// the alternative output directory contains a state file
// this means the user has compiled his own version
// => use the alternative output directory
APackage.CompilerOptions.ParsedOpts.OutputDirectoryOverride:=NewOutputDir;
end;
end;
end;
end;
end;
// check state file
StateFilename:=APackage.GetStateFilename;
Result:=LoadPackageCompiledState(APackage,false);