lazbuild: fixed -r when lazarus was installed read only, issue #40747

This commit is contained in:
mattias 2024-02-02 17:45:12 +01:00
parent 5469260518
commit 12a2ed90bc
2 changed files with 38 additions and 25 deletions

View File

@ -2186,7 +2186,7 @@ begin
List:=nil; List:=nil;
try try
if ConsoleVerbosity>0 then if ConsoleVerbosity>0 then
debugln(['Hint: (lazarus) TBuildManager.MacroFuncInstantFPCCache ',Prog]); debugln(['Hint: (lazarus) [TBuildManager.MacroFuncInstantFPCCache] Exe=',Prog]);
List:=RunTool(Prog,'--get-cache','',ConsoleVerbosity<1); List:=RunTool(Prog,'--get-cache','',ConsoleVerbosity<1);
if (List<>nil) and (List.Count>0) then if (List<>nil) and (List.Count>0) then
FMacroInstantFPCCache:=List[0]; FMacroInstantFPCCache:=List[0];
@ -2199,7 +2199,7 @@ begin
end; end;
end; end;
if ConsoleVerbosity>=1 then if ConsoleVerbosity>=1 then
debugln(['Hint: (lazarus) [TBuildManager.MacroFuncInstantFPCCache] ',FMacroInstantFPCCache]); debugln(['Hint: (lazarus) [TBuildManager.MacroFuncInstantFPCCache] CacheDir=',FMacroInstantFPCCache]);
end; end;
Result:=FMacroInstantFPCCache; Result:=FMacroInstantFPCCache;
end; end;

View File

@ -410,7 +410,8 @@ type
var Note: string): TModalResult; var Note: string): TModalResult;
function CheckIfPackageNeedsCompilation(APackage: TLazPackage; function CheckIfPackageNeedsCompilation(APackage: TLazPackage;
SkipDesignTimePackages, GroupCompile: boolean; SkipDesignTimePackages, GroupCompile: boolean;
out NeedBuildAllFlag: boolean; var Note: string): TModalResult; var NeedBuildAllFlag: boolean; // pass true to force a build
var Note: string): TModalResult;
function PreparePackageOutputDirectory(APackage: TLazPackage; function PreparePackageOutputDirectory(APackage: TLazPackage;
CleanUp: boolean): TModalResult; CleanUp: boolean): TModalResult;
function GetFallbackOutputDir(APackage: TLazPackage): string; function GetFallbackOutputDir(APackage: TLazPackage): string;
@ -3525,7 +3526,7 @@ begin
end; end;
function TLazPackageGraph.CheckIfPackageNeedsCompilation(APackage: TLazPackage; function TLazPackageGraph.CheckIfPackageNeedsCompilation(APackage: TLazPackage;
SkipDesignTimePackages, GroupCompile: boolean; out NeedBuildAllFlag: boolean; SkipDesignTimePackages, GroupCompile: boolean; var NeedBuildAllFlag: boolean;
var Note: string): TModalResult; var Note: string): TModalResult;
var var
OutputDir: String; OutputDir: String;
@ -3533,25 +3534,27 @@ var
ConfigChanged: boolean; ConfigChanged: boolean;
DependenciesChanged: boolean; DependenciesChanged: boolean;
DefResult: TModalResult; DefResult: TModalResult;
OldNeedBuildAllFlag, IsDefDirWritable: Boolean; OldNeedBuildAllFlag, IsDefDirWritable, ForceBuild: Boolean;
OldOverride: String; OldOverride: String;
begin begin
Result:=mrYes; Result:=mrYes;
{$IFDEF VerbosePkgCompile} {$IFDEF VerbosePkgCompile}
debugln('TLazPackageGraph.CheckIfPackageNeedsCompilation A ',APackage.IDAsString); debugln('TLazPackageGraph.CheckIfPackageNeedsCompilation A ',APackage.IDAsString);
{$ENDIF} {$ENDIF}
NeedBuildAllFlag:=false; ForceBuild:=NeedBuildAllFlag;
if ForceBuild then begin
if APackage.AutoUpdate=pupManually then // user demands to rebuild the package
exit(mrNo); end else begin
if (APackage.AutoUpdate=pupManually) then
// check the current output directory exit(mrNo);
Result:=CheckIfCurPkgOutDirNeedsCompile(APackage, // check the current output directory
true,SkipDesignTimePackages,GroupCompile, Result:=CheckIfCurPkgOutDirNeedsCompile(APackage,
NeedBuildAllFlag,ConfigChanged,DependenciesChanged,Note); true,SkipDesignTimePackages,GroupCompile,
if Result=mrNo then begin NeedBuildAllFlag,ConfigChanged,DependenciesChanged,Note);
// the current output is valid if Result=mrNo then begin
exit; // the current output is valid
exit;
end;
end; end;
// the current output directory needs compilation // the current output directory needs compilation
@ -3576,13 +3579,20 @@ begin
end; end;
Note+='Normal output directory is not writable, switching to fallback.'+LineEnding; Note+='Normal output directory is not writable, switching to fallback.'+LineEnding;
APackage.CompilerOptions.ParsedOpts.OutputDirectoryOverride:=NewOutputDir; APackage.CompilerOptions.ParsedOpts.OutputDirectoryOverride:=NewOutputDir;
Result:=CheckIfCurPkgOutDirNeedsCompile(APackage, if ForceBuild then
true,SkipDesignTimePackages,GroupCompile, Result:=mrYes
NeedBuildAllFlag,ConfigChanged,DependenciesChanged,Note); else
Result:=CheckIfCurPkgOutDirNeedsCompile(APackage,
true,SkipDesignTimePackages,GroupCompile,
NeedBuildAllFlag,ConfigChanged,DependenciesChanged,Note);
end else begin end else begin
// the last compile was put to the fallback output directory // the last compile was put to the fallback output directory
if not IsDefDirWritable then begin if not IsDefDirWritable then begin
if ForceBuild then begin
// => keep using the fallback directory
exit;
end;
if not ConfigChanged then begin if not ConfigChanged then begin
// some source files have changed, not the compiler parameters // some source files have changed, not the compiler parameters
// => keep using the fallback directory // => keep using the fallback directory
@ -3604,8 +3614,8 @@ begin
debugln(['Hint: (lazarus) trying the default output directory of package ',APackage.IDAsString]); debugln(['Hint: (lazarus) trying the default output directory of package ',APackage.IDAsString]);
OldNeedBuildAllFlag:=NeedBuildAllFlag; OldNeedBuildAllFlag:=NeedBuildAllFlag;
DefResult:=CheckIfCurPkgOutDirNeedsCompile(APackage, DefResult:=CheckIfCurPkgOutDirNeedsCompile(APackage,
true,SkipDesignTimePackages,GroupCompile, true,SkipDesignTimePackages,GroupCompile,
NeedBuildAllFlag,ConfigChanged,DependenciesChanged,Note); NeedBuildAllFlag,ConfigChanged,DependenciesChanged,Note);
if IsDefDirWritable or (DefResult=mrNo) then begin if IsDefDirWritable or (DefResult=mrNo) then begin
// switching back to the default output directory // switching back to the default output directory
debugln(['Hint: (lazarus) switching back to the normal output directory: "',APackage.GetOutputDirectory,'" Package ',APackage.IDAsString]); debugln(['Hint: (lazarus) switching back to the normal output directory: "',APackage.GetOutputDirectory,'" Package ',APackage.IDAsString]);
@ -3652,7 +3662,8 @@ begin
ConfigChanged:=false; ConfigChanged:=false;
DependenciesChanged:=false; DependenciesChanged:=false;
if APackage.AutoUpdate=pupManually then exit(mrNo); if APackage.AutoUpdate=pupManually then
exit(mrNo);
SrcFilename:=APackage.GetSrcFilename; SrcFilename:=APackage.GetSrcFilename;
CompilerFilename:=APackage.GetCompilerFilename; CompilerFilename:=APackage.GetCompilerFilename;
@ -3666,7 +3677,8 @@ begin
// check state file // check state file
StateFilename:=APackage.GetStateFilename; StateFilename:=APackage.GetStateFilename;
Result:=LoadPackageCompiledState(APackage,false,true); Result:=LoadPackageCompiledState(APackage,false,true);
if Result<>mrOk then exit; // read error and user aborted if Result<>mrOk then
exit; // read error and user aborted
if not Stats.StateFileLoaded then begin if not Stats.StateFileLoaded then begin
// package was not compiled via Lazarus nor via Makefile/fpmake // package was not compiled via Lazarus nor via Makefile/fpmake
DebugLn('Hint: (lazarus) Missing state file of ',APackage.IDAsString,': ',StateFilename); DebugLn('Hint: (lazarus) Missing state file of ',APackage.IDAsString,': ',StateFilename);
@ -4094,6 +4106,7 @@ begin
BuildItems:=TObjectList.Create(true); BuildItems:=TObjectList.Create(true);
for i:=0 to PkgList.Count-1 do begin for i:=0 to PkgList.Count-1 do begin
CurPkg:=TLazPackage(PkgList[i]); CurPkg:=TLazPackage(PkgList[i]);
if CurPkg.AutoUpdate=pupManually then continue;
BuildItem:=TLazPkgGraphBuildItem.Create(nil); BuildItem:=TLazPkgGraphBuildItem.Create(nil);
BuildItem.LazPackage:=CurPkg; BuildItem.LazPackage:=CurPkg;
BuildItems.Add(BuildItem); BuildItems.Add(BuildItem);
@ -4299,7 +4312,7 @@ begin
end; end;
// check if compilation is needed and if a clean build is needed // check if compilation is needed and if a clean build is needed
NeedBuildAllFlag:=false; NeedBuildAllFlag:=pcfCleanCompile in Flags;
Note:=''; Note:='';
Result:=CheckIfPackageNeedsCompilation(APackage, Result:=CheckIfPackageNeedsCompilation(APackage,
pcfSkipDesignTimePackages in Flags, pcfSkipDesignTimePackages in Flags,