mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 00:19:15 +02:00
IDE: added package option Write compiler config file
This commit is contained in:
parent
071135a4c9
commit
6ceeb57076
@ -787,6 +787,7 @@ var
|
|||||||
function StartBuilding : boolean;
|
function StartBuilding : boolean;
|
||||||
var
|
var
|
||||||
CfgCode: TCodeBuffer;
|
CfgCode: TCodeBuffer;
|
||||||
|
CfgFilename: String;
|
||||||
begin
|
begin
|
||||||
Result := false;
|
Result := false;
|
||||||
|
|
||||||
@ -894,11 +895,12 @@ var
|
|||||||
|
|
||||||
if Project1.CompilerOptions.WriteConfigFile then
|
if Project1.CompilerOptions.WriteConfigFile then
|
||||||
begin
|
begin
|
||||||
CfgCode:=Project1.WriteCompilerCfgFile(Project1,CompilerParams,CmdLineParams);
|
CfgFilename:=Project1.GetWriteConfigFilePath;
|
||||||
|
CfgCode:=WriteCompilerCfgFile(CfgFilename,CompilerParams,CmdLineParams);
|
||||||
if CfgCode=nil then
|
if CfgCode=nil then
|
||||||
Error(ErrorBuildFailed,'unable to read "'+Project1.GetWriteConfigFilePath+'"');
|
Error(ErrorBuildFailed,'unable to read "'+CfgFilename+'"');
|
||||||
if CfgCode.FileOnDiskNeedsUpdate and (not CfgCode.Save) then
|
if CfgCode.FileOnDiskNeedsUpdate and (not CfgCode.Save) then
|
||||||
Error(ErrorBuildFailed,'unable to write "'+Project1.GetWriteConfigFilePath+'"');
|
Error(ErrorBuildFailed,'unable to write "'+CfgFilename+'"');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// write state file to avoid building clean every time
|
// write state file to avoid building clean every time
|
||||||
|
@ -6842,7 +6842,7 @@ var
|
|||||||
TargetExeName: String;
|
TargetExeName: String;
|
||||||
TargetExeDirectory: String;
|
TargetExeDirectory: String;
|
||||||
CompilerVersion: integer;
|
CompilerVersion: integer;
|
||||||
aCompileHint, ShortFilename: String;
|
aCompileHint, ShortFilename, CfgFilename: String;
|
||||||
OldToolStatus: TIDEToolStatus;
|
OldToolStatus: TIDEToolStatus;
|
||||||
IsComplete: Boolean;
|
IsComplete: Boolean;
|
||||||
StartTime: TDateTime;
|
StartTime: TDateTime;
|
||||||
@ -7107,10 +7107,11 @@ begin
|
|||||||
|
|
||||||
if Project1.CompilerOptions.WriteConfigFile then
|
if Project1.CompilerOptions.WriteConfigFile then
|
||||||
begin
|
begin
|
||||||
CfgCode:=Project1.WriteCompilerCfgFile(Project1,CompilerParams,CmdLineParams);
|
CfgFilename:=Project1.GetWriteConfigFilePath;
|
||||||
|
CfgCode:=WriteCompilerCfgFile(CfgFilename,CompilerParams,CmdLineParams);
|
||||||
if CfgCode=nil then begin
|
if CfgCode=nil then begin
|
||||||
IDEMessageDialog(lisReadError,Format(lisUnableToReadFile2,
|
IDEMessageDialog(lisReadError,Format(lisUnableToReadFile2,
|
||||||
[Project1.GetWriteConfigFilePath]),mtError,[mbOk]);
|
[CfgFilename]),mtError,[mbOk]);
|
||||||
exit(mrCancel);
|
exit(mrCancel);
|
||||||
end;
|
end;
|
||||||
if CfgCode.FileOnDiskNeedsUpdate and (SaveCodeBuffer(CfgCode)<>mrOk) then
|
if CfgCode.FileOnDiskNeedsUpdate and (SaveCodeBuffer(CfgCode)<>mrOk) then
|
||||||
|
@ -1078,8 +1078,6 @@ type
|
|||||||
function LoadStateFile(IgnoreErrors: boolean): TModalResult;
|
function LoadStateFile(IgnoreErrors: boolean): TModalResult;
|
||||||
function SaveStateFile(const CompilerFilename: string; CompilerParams: TStrings;
|
function SaveStateFile(const CompilerFilename: string; CompilerParams: TStrings;
|
||||||
Complete: boolean): TModalResult;
|
Complete: boolean): TModalResult;
|
||||||
function WriteCompilerCfgFile(aProject: TProject; CompilerParams: TStrings;
|
|
||||||
out CmdLineParams: TStrings): TCodeBuffer;
|
|
||||||
|
|
||||||
// source editor
|
// source editor
|
||||||
procedure UpdateAllCustomHighlighter;
|
procedure UpdateAllCustomHighlighter;
|
||||||
@ -5321,40 +5319,6 @@ begin
|
|||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TProject.WriteCompilerCfgFile(aProject: TProject;
|
|
||||||
CompilerParams: TStrings; out CmdLineParams: TStrings): TCodeBuffer;
|
|
||||||
var
|
|
||||||
CfgFile, Src, Param: String;
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
Result:=nil;
|
|
||||||
CmdLineParams:=TStringListUTF8Fast.Create;
|
|
||||||
CmdLineParams.Add('@'+aProject.GetWriteConfigFilePath);
|
|
||||||
CfgFile:=AProject.GetWriteConfigFilePath;
|
|
||||||
Src:='# Auto generated by Lazarus. Do not edit.'+LineEnding;
|
|
||||||
for i:=CompilerParams.Count-1 downto 0 do
|
|
||||||
begin
|
|
||||||
Param:=CompilerParams[i];
|
|
||||||
if (Param[1]='@')
|
|
||||||
or (Param='n')
|
|
||||||
or (Param[1]<>'-') then
|
|
||||||
CmdLineParams.Insert(1,Param)
|
|
||||||
else begin
|
|
||||||
Src+=Param+LineEnding;
|
|
||||||
CompilerParams.Delete(i);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Result:=CodeToolBoss.LoadFile(CfgFile,true,true);
|
|
||||||
if (Result=nil) and FileExistsCached(CfgFile) then
|
|
||||||
exit; // failed loading old cfg
|
|
||||||
if (Result<>nil) and (Result.Source=Src) then
|
|
||||||
exit; // nothing changed -> skip
|
|
||||||
if Result=nil then
|
|
||||||
Result:=CodeToolBoss.CreateFile(CfgFile);
|
|
||||||
Result.Source:=Src;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TProject.UpdateAllCustomHighlighter;
|
procedure TProject.UpdateAllCustomHighlighter;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
@ -634,6 +634,7 @@ type
|
|||||||
function GetSrcFilename: string;
|
function GetSrcFilename: string;
|
||||||
function GetSrcPPUFilename: string;
|
function GetSrcPPUFilename: string;
|
||||||
function GetCompilerFilename: string;
|
function GetCompilerFilename: string;
|
||||||
|
function GetWriteConfigFilePath: string;
|
||||||
function GetPOOutDirectory: string;
|
function GetPOOutDirectory: string;
|
||||||
function GetUnitPath(RelativeToBaseDir: boolean): string;
|
function GetUnitPath(RelativeToBaseDir: boolean): string;
|
||||||
function GetIncludePath(RelativeToBaseDir: boolean): string;
|
function GetIncludePath(RelativeToBaseDir: boolean): string;
|
||||||
@ -3910,6 +3911,11 @@ begin
|
|||||||
Result:=CompilerOptions.ParsedOpts.GetParsedValue(pcosCompilerPath);
|
Result:=CompilerOptions.ParsedOpts.GetParsedValue(pcosCompilerPath);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLazPackage.GetWriteConfigFilePath: string;
|
||||||
|
begin
|
||||||
|
Result:=CompilerOptions.ParsedOpts.GetParsedValue(pcosWriteConfigFilePath);
|
||||||
|
end;
|
||||||
|
|
||||||
function TLazPackage.GetPOOutDirectory: string;
|
function TLazPackage.GetPOOutDirectory: string;
|
||||||
begin
|
begin
|
||||||
Result:=TrimFilename(SubstitutePkgMacros(fPOOutputDirectory,false));
|
Result:=TrimFilename(SubstitutePkgMacros(fPOOutputDirectory,false));
|
||||||
|
@ -538,6 +538,9 @@ function FPCParamNeedsBuildAll(const Param: String): boolean;
|
|||||||
function FPCParamForBuildAllHasChanged(OldParams, NewParams: TStrings): boolean;
|
function FPCParamForBuildAllHasChanged(OldParams, NewParams: TStrings): boolean;
|
||||||
function RemoveFPCVerbosityParams(CompParams: TStrings): TStrings;
|
function RemoveFPCVerbosityParams(CompParams: TStrings): TStrings;
|
||||||
procedure WarnSuspiciousCompilerOptions(ViewCaption, Target: string; CompilerParams: TStrings);
|
procedure WarnSuspiciousCompilerOptions(ViewCaption, Target: string; CompilerParams: TStrings);
|
||||||
|
function WriteCompilerCfgFile(CfgFilename: string; CompilerParams: TStrings;
|
||||||
|
out CmdLineParams: TStrings): TCodeBuffer;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -755,6 +758,39 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function WriteCompilerCfgFile(CfgFilename: string; CompilerParams: TStrings;
|
||||||
|
out CmdLineParams: TStrings): TCodeBuffer;
|
||||||
|
var
|
||||||
|
Src, Param: String;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result:=nil;
|
||||||
|
CmdLineParams:=TStringListUTF8Fast.Create;
|
||||||
|
CmdLineParams.Add('@'+CfgFilename);
|
||||||
|
Src:='# Auto generated by Lazarus. Do not edit.'+LineEnding;
|
||||||
|
for i:=CompilerParams.Count-1 downto 0 do
|
||||||
|
begin
|
||||||
|
Param:=CompilerParams[i];
|
||||||
|
if (Param[1]='@')
|
||||||
|
or (Param='n')
|
||||||
|
or (Param[1]<>'-') then
|
||||||
|
CmdLineParams.Insert(1,Param)
|
||||||
|
else begin
|
||||||
|
Src+=Param+LineEnding;
|
||||||
|
CompilerParams.Delete(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result:=CodeToolBoss.LoadFile(CfgFilename,true,true);
|
||||||
|
if (Result=nil) and FileExistsCached(CfgFilename) then
|
||||||
|
exit; // failed loading old cfg
|
||||||
|
if (Result<>nil) and (Result.Source=Src) then
|
||||||
|
exit; // nothing changed -> skip
|
||||||
|
if Result=nil then
|
||||||
|
Result:=CodeToolBoss.CreateFile(CfgFilename);
|
||||||
|
Result.Source:=Src;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TLazPackageGraphFileCache }
|
{ TLazPackageGraphFileCache }
|
||||||
|
|
||||||
constructor TLazPackageGraphFileCache.Create(AOwner: TLazPackageGraph);
|
constructor TLazPackageGraphFileCache.Create(AOwner: TLazPackageGraph);
|
||||||
@ -4192,12 +4228,13 @@ var
|
|||||||
CompilerFilename: String;
|
CompilerFilename: String;
|
||||||
CompilePolicy: TPackageUpdatePolicy;
|
CompilePolicy: TPackageUpdatePolicy;
|
||||||
NeedBuildAllFlag, NeedBuildAll: Boolean;
|
NeedBuildAllFlag, NeedBuildAll: Boolean;
|
||||||
CompilerParams: TStrings;
|
CompilerParams, CmdLineParams: TStrings;
|
||||||
Note: String;
|
Note: String;
|
||||||
WorkingDir: String;
|
WorkingDir: String;
|
||||||
ToolTitle: String;
|
ToolTitle, CfgFilename: String;
|
||||||
ExtToolData: TLazPkgGraphExtToolData;
|
ExtToolData: TLazPkgGraphExtToolData;
|
||||||
BuildMethod: TBuildMethod;
|
BuildMethod: TBuildMethod;
|
||||||
|
CfgCode: TCodeBuffer;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
|
|
||||||
@ -4252,6 +4289,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
CompilerParams:=nil;
|
CompilerParams:=nil;
|
||||||
|
CmdLineParams:=nil;
|
||||||
try
|
try
|
||||||
if (BuildItem=nil) and (LazarusIDE<>nil) then
|
if (BuildItem=nil) and (LazarusIDE<>nil) then
|
||||||
LazarusIDE.MainBarSubTitle:=APackage.Name;
|
LazarusIDE.MainBarSubTitle:=APackage.Name;
|
||||||
@ -4346,6 +4384,19 @@ begin
|
|||||||
NeedBuildAll:=true;
|
NeedBuildAll:=true;
|
||||||
|
|
||||||
WarnSuspiciousCompilerOptions('Compile checks','package '+APackage.IDAsString+':',CompilerParams);
|
WarnSuspiciousCompilerOptions('Compile checks','package '+APackage.IDAsString+':',CompilerParams);
|
||||||
|
|
||||||
|
if APackage.CompilerOptions.WriteConfigFile then
|
||||||
|
begin
|
||||||
|
CfgFilename:=APackage.GetWriteConfigFilePath;
|
||||||
|
CfgCode:=WriteCompilerCfgFile(CfgFilename,CompilerParams,CmdLineParams);
|
||||||
|
if CfgCode=nil then begin
|
||||||
|
IDEMessageDialog(lisReadError,Format(lisUnableToReadFile2,
|
||||||
|
[CfgFilename]),mtError,[mbOk]);
|
||||||
|
exit(mrCancel);
|
||||||
|
end;
|
||||||
|
if CfgCode.FileOnDiskNeedsUpdate and (SaveCodeBuffer(CfgCode)<>mrOk) then
|
||||||
|
exit(mrCancel);
|
||||||
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
CompilerFilename:='fppkg';
|
CompilerFilename:='fppkg';
|
||||||
CompilerParams:=TStringListUTF8Fast.Create;
|
CompilerParams:=TStringListUTF8Fast.Create;
|
||||||
@ -4451,6 +4502,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
finally
|
finally
|
||||||
|
if CmdLineParams<>CompilerParams then
|
||||||
|
CmdLineParams.Free;
|
||||||
CompilerParams.Free;
|
CompilerParams.Free;
|
||||||
if (BuildItem=nil) and (LazarusIDE<>nil) then
|
if (BuildItem=nil) and (LazarusIDE<>nil) then
|
||||||
LazarusIDE.MainBarSubTitle:='';
|
LazarusIDE.MainBarSubTitle:='';
|
||||||
|
Loading…
Reference in New Issue
Block a user