Don't use "const" for some function parameters related to OutputDirectory. Can cause mysterious errors.

This commit is contained in:
Juha 2024-02-02 19:27:26 +02:00
parent a11e3cd50a
commit 39fb484747
5 changed files with 41 additions and 38 deletions

View File

@ -401,8 +401,8 @@ type
class procedure MergeXMLConfig(ParentDefTempl: TDefineTemplate; class procedure MergeXMLConfig(ParentDefTempl: TDefineTemplate;
var FirstSibling, LastSibling:TDefineTemplate; var FirstSibling, LastSibling:TDefineTemplate;
XMLConfig: TXMLConfig; const Path, NewNamePrefix: string); XMLConfig: TXMLConfig; const Path, NewNamePrefix: string);
constructor Create(const AName, ADescription, AVariable, AValue: string; constructor Create(const AName, ADescription, AVariable: string;
AnAction: TDefineAction); AValue: string; AnAction: TDefineAction);
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
procedure ConsistencyCheck; procedure ConsistencyCheck;
@ -4629,8 +4629,9 @@ begin
inherited Create; inherited Create;
end; end;
constructor TDefineTemplate.Create(const AName, ADescription, AVariable, constructor TDefineTemplate.Create(const AName, ADescription, AVariable: string;
AValue: string; AnAction: TDefineAction); AValue: string; AnAction: TDefineAction);
// Don't use "const" for AValue parameter.
begin begin
inherited Create; inherited Create;
Name:=AName; Name:=AName;

View File

@ -261,7 +261,7 @@ const
CompilerOptionMacroPlatformIndependent = 1; CompilerOptionMacroPlatformIndependent = 1;
type type
TLocalSubstitutionEvent = function(const s: string; TLocalSubstitutionEvent = function(s: string;
PlatformIndependent: boolean): string of object; PlatformIndependent: boolean): string of object;
TInheritedCompOptsParseTypesStrings = TInheritedCompOptsParseTypesStrings =
@ -303,7 +303,7 @@ type
function GetParsedPIValue(Option: TParsedCompilerOptString): string;// platform independent function GetParsedPIValue(Option: TParsedCompilerOptString): string;// platform independent
procedure SetUnparsedValue(Option: TParsedCompilerOptString; procedure SetUnparsedValue(Option: TParsedCompilerOptString;
const NewValue: string); const NewValue: string);
function DoParseOption(const OptionText: string; function DoParseOption(OptionText: string;
Option: TParsedCompilerOptString; Option: TParsedCompilerOptString;
PlatformIndependent: boolean): string; PlatformIndependent: boolean): string;
procedure Assign(Src: TParsedCompilerOptions); procedure Assign(Src: TParsedCompilerOptions);
@ -3858,8 +3858,9 @@ begin
Values[Option].UnparsedValue:=NewValue; Values[Option].UnparsedValue:=NewValue;
end; end;
function TParsedCompilerOptions.DoParseOption(const OptionText: string; function TParsedCompilerOptions.DoParseOption(OptionText: string;
Option: TParsedCompilerOptString; PlatformIndependent: boolean): string; Option: TParsedCompilerOptString; PlatformIndependent: boolean): string;
// Don't use "const" for OptionText parameter.
function GetBaseDir: string; function GetBaseDir: string;
begin begin
@ -3878,67 +3879,67 @@ function TParsedCompilerOptions.DoParseOption(const OptionText: string;
aFilename:=TrimFilename(aFilename); aFilename:=TrimFilename(aFilename);
if (aFilename<>'') and (not FilenameIsAbsolute(aFilename)) then begin if (aFilename<>'') and (not FilenameIsAbsolute(aFilename)) then begin
BaseDirectory:=GetBaseDir; BaseDirectory:=GetBaseDir;
if (BaseDirectory<>'') then aFilename:=TrimFilename(BaseDirectory+aFilename); if (BaseDirectory<>'') then
aFilename:=TrimFilename(BaseDirectory+aFilename);
end; end;
end; end;
var var
s: String;
BaseDirectory, h: String; BaseDirectory, h: String;
begin begin
s:=OptionText; Result:=OptionText;
// apply overrides // apply overrides
if not PlatformIndependent then begin if not PlatformIndependent then begin
if Option=pcosOutputDir then begin if Option=pcosOutputDir then begin
if Assigned(OnGetOutputDirectoryOverride) then if Assigned(OnGetOutputDirectoryOverride) then
OnGetOutputDirectoryOverride(Self,s,bmgtAll); OnGetOutputDirectoryOverride(Self,Result,bmgtAll);
end; end;
end; end;
// parse locally (macros depending on owner, like pkgdir and build macros) // parse locally (macros depending on owner, like pkgdir and build macros)
if Assigned(OnLocalSubstitute) then if Assigned(OnLocalSubstitute) then
begin begin
//DebugLn(['TParsedCompilerOptions.DoParseOption local "',s,'" ...']); //DebugLn(['TParsedCompilerOptions.DoParseOption local "',Result,'" ...']);
s:=OnLocalSubstitute(s,PlatformIndependent) Result:=OnLocalSubstitute(Result,PlatformIndependent)
end else end else
begin begin
//DebugLn(['TParsedCompilerOptions.DoParseOption global "',s,'" ...']); //DebugLn(['TParsedCompilerOptions.DoParseOption global "',Result,'" ...']);
s:=ParseString(Self,s,PlatformIndependent); Result:=ParseString(Self,Result,PlatformIndependent);
end; end;
//DebugLn(['TParsedCompilerOptions.DoParseOption complete "',s,'" ...']); //DebugLn(['TParsedCompilerOptions.DoParseOption complete "',Result,'" ...']);
// improve // improve
if Option=pcosBaseDir then if Option=pcosBaseDir then
// base directory // base directory
s:=AppendPathDelim(TrimFilename(s)) Result:=AppendPathDelim(TrimFilename(Result))
else if Option in ParsedCompilerFilenames then else if Option in ParsedCompilerFilenames then
begin begin
// make filename absolute // make filename absolute
//debugln(['TParsedCompilerOptions.DoParseOption ',ParsedCompilerOptsVars[Option],' s="',s,'"']); //debugln(['TParsedCompilerOptions.DoParseOption ',ParsedCompilerOptsVars[Option],' Result="',Result,'"']);
if (Option in ParsedCompilerExecutables) and (ExtractFilePath(s)='') then if (Option in ParsedCompilerExecutables) and (ExtractFilePath(Result)='') then
begin begin
h:=FileUtil.FindDefaultExecutablePath(s,GetBaseDir); h:=FileUtil.FindDefaultExecutablePath(Result,GetBaseDir);
if h<>'' then s:=h; if h<>'' then
Result:=h;
end; end;
MakeFilenameAbsolute(s); MakeFilenameAbsolute(Result);
end end
else if Option in ParsedCompilerDirectories then else if Option in ParsedCompilerDirectories then
begin begin
// make directory absolute // make directory absolute
s:=TrimFilename(s); Result:=TrimFilename(Result);
if Option<>pcosBaseDir then if Option<>pcosBaseDir then
MakeFilenameAbsolute(s); MakeFilenameAbsolute(Result);
s:=AppendPathDelim(s); Result:=AppendPathDelim(Result);
end end
else if Option in ParsedCompilerSearchPaths then else if Option in ParsedCompilerSearchPaths then
begin begin
// make search paths absolute // make search paths absolute
BaseDirectory:=GetBaseDir; BaseDirectory:=GetBaseDir;
s:=TrimSearchPath(s,BaseDirectory); Result:=TrimSearchPath(Result,BaseDirectory);
end else if Option=pcosCustomOptions then begin end else if Option=pcosCustomOptions then begin
s:=SpecialCharsToSpaces(s,true); Result:=SpecialCharsToSpaces(Result,true);
end; end;
Result:=s;
end; end;
procedure TParsedCompilerOptions.Assign(Src: TParsedCompilerOptions); procedure TParsedCompilerOptions.Assign(Src: TParsedCompilerOptions);

View File

@ -554,7 +554,7 @@ type
procedure SetUnitPaths(const AValue: string); override; procedure SetUnitPaths(const AValue: string); override;
procedure SetUnitOutputDir(const AValue: string); override; procedure SetUnitOutputDir(const AValue: string); override;
procedure SetConditionals(AValue: string); override; procedure SetConditionals(AValue: string); override;
function SubstituteProjectMacros(const s: string; function SubstituteProjectMacros(s: string;
PlatformIndependent: boolean): string; PlatformIndependent: boolean): string;
public public
constructor Create(const AOwner: TObject); override; constructor Create(const AOwner: TObject); override;
@ -6526,8 +6526,9 @@ begin
inherited SetConditionals(AValue); inherited SetConditionals(AValue);
end; end;
function TProjectCompilerOptions.SubstituteProjectMacros(const s: string; function TProjectCompilerOptions.SubstituteProjectMacros(s: string;
PlatformIndependent: boolean): string; PlatformIndependent: boolean): string;
// Don't use "const" for s parameter.
begin begin
Result:=s; Result:=s;
if LazProject=nil then exit; if LazProject=nil then exit;

View File

@ -34,7 +34,7 @@ type
class function Instance: TFppkgHelper; class function Instance: TFppkgHelper;
function HasPackage(const PackageName: string): Boolean; function HasPackage(const PackageName: string): Boolean;
procedure ListPackages(AList: TStringList); procedure ListPackages(AList: TStringList);
function GetPackageUnitPath(const PackageName: string): string; function GetPackageUnitPath(PackageName: string): string;
function IsProperlyConfigured(out Message: string): Boolean; function IsProperlyConfigured(out Message: string): Boolean;
function GetCompilerFilename: string; function GetCompilerFilename: string;
function GetConfigurationFileName: string; function GetConfigurationFileName: string;
@ -154,7 +154,8 @@ begin
end; end;
end; end;
function TFppkgHelper.GetPackageUnitPath(const PackageName: string): string; function TFppkgHelper.GetPackageUnitPath(PackageName: string): string;
// Don't use "const" for PackageName parameter.
var var
FppkgPackage: TFPPackage; FppkgPackage: TFPPackage;
{$IF not (FPC_FULLVERSION>30300)} {$IF not (FPC_FULLVERSION>30300)}

View File

@ -652,7 +652,7 @@ type
function GetSrcPath(RelativeToBaseDir: boolean): string; function GetSrcPath(RelativeToBaseDir: boolean): string;
function GetFPDocPackageName: string; function GetFPDocPackageName: string;
function NeedsDefineTemplates: boolean; function NeedsDefineTemplates: boolean;
function SubstitutePkgMacros(const s: string; PlatformIndependent: boolean): string; function SubstitutePkgMacros(s: string; PlatformIndependent: boolean): string;
procedure WriteInheritedUnparsedOptions; procedure WriteInheritedUnparsedOptions;
function GetActiveBuildMethod: TBuildMethod; function GetActiveBuildMethod: TBuildMethod;
// files // files
@ -2235,8 +2235,8 @@ begin
FUserReadOnly:=AValue; FUserReadOnly:=AValue;
end; end;
function TLazPackage.SubstitutePkgMacros(const s: string; function TLazPackage.SubstitutePkgMacros(s: string; PlatformIndependent: boolean): string;
PlatformIndependent: boolean): string; // Don't use "const" for s parameter.
begin begin
Result:=s; Result:=s;
if PlatformIndependent then if PlatformIndependent then
@ -3840,11 +3840,10 @@ end;
function TLazPackage.GetOutputDirectory(UseOverride: boolean = true): string; function TLazPackage.GetOutputDirectory(UseOverride: boolean = true): string;
begin begin
if HasDirectory then begin if HasDirectory then begin
if GetActiveBuildMethod = bmFPMake then begin if GetActiveBuildMethod = bmFPMake then
Result :=TFppkgHelper.Instance.GetPackageUnitPath(name); Result :=TFppkgHelper.Instance.GetPackageUnitPath(name)
end else begin else
Result:=CompilerOptions.ParsedOpts.GetParsedValue(pcosOutputDir,UseOverride); Result:=CompilerOptions.ParsedOpts.GetParsedValue(pcosOutputDir,UseOverride);
end;
end else end else
Result:=''; Result:='';
end; end;