From e375a961ce8aa341d8ddaa033268365bde1cb604 Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 30 Sep 2024 10:10:11 +0200 Subject: [PATCH] ide: fixed keep WriteConfigFile on cancel, fixed keeping order in config, except for search paths --- ide/packages/ideconfig/compileroptions.pp | 2 + ide/packages/idepackager/packagesystem.pas | 53 ++++++++++++++++++---- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/ide/packages/ideconfig/compileroptions.pp b/ide/packages/ideconfig/compileroptions.pp index b1e09b8a2c..1759905721 100644 --- a/ide/packages/ideconfig/compileroptions.pp +++ b/ide/packages/ideconfig/compileroptions.pp @@ -2994,6 +2994,8 @@ begin // Other fDontUseConfigFile := CompOpts.fDontUseConfigFile; + FWriteConfigFile := CompOpts.FWriteConfigFile; + FWriteConfigFilePath := CompOpts.FWriteConfigFilePath; fCustomConfigFile := CompOpts.fCustomConfigFile; fConfigFilePath := CompOpts.fConfigFilePath; fStopAfterErrCount := CompOpts.fStopAfterErrCount; diff --git a/ide/packages/idepackager/packagesystem.pas b/ide/packages/idepackager/packagesystem.pas index bec228d38b..a561b02f57 100644 --- a/ide/packages/idepackager/packagesystem.pas +++ b/ide/packages/idepackager/packagesystem.pas @@ -741,25 +741,60 @@ end; function WriteCompilerCfgFile(CfgFilename: string; CompilerParams: TStrings; out CmdLineParams: TStrings): TCodeBuffer; + + function GetPathOpt(const Param: string): char; + begin + Result:=' '; + if length(Param)<3 then exit; + if (Param[1]<>'-') or (Param[2]<>'F') then exit; + Result:=Param[3]; + end; + var Src, Param: String; - i: Integer; + i, First, Cnt, j: Integer; + Opt: Char; begin Result:=nil; + + // search paths like -Fu have reverse order in fpc's cfg file + // otherwise the params must keep the order! + // For example linker options -k must keep the order + // and an -FU after -Fu must stay after -Fu + + // create Src and CmdLineParams CmdLineParams:=TStringListUTF8Fast.Create; CmdLineParams.Add('@'+CfgFilename); Src:='# Auto generated by Lazarus. Do not edit.'+LineEnding; + Cnt:=CompilerParams.Count; + i:=0; + while i'-') then + CmdLineParams.Add(Param) + else begin + Opt:=GetPathOpt(Param); + if Opt<>' ' then + begin + // path option -F + // -> add in reverse order + First:=i; + while (i+1'-') then - CmdLineParams.Insert(1,Param) - else begin - Src+=Param+LineEnding; - CompilerParams.Delete(i); - end; + if (Param='-n') or (Param[1]<>'-') then continue; + CompilerParams.Delete(i); end; Result:=CodeToolBoss.LoadFile(CfgFilename,true,true);