From bd0a307669fc837ac7ea97075b3639e19132b164 Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 20 Dec 2020 14:16:16 +0000 Subject: [PATCH] IDE: fixed restart on darwin with lazarus.cfg git-svn-id: trunk@64249 - --- ide/idecmdline.pas | 14 +++++++++++++ ide/ideinstances.pas | 3 ++- ide/lazarusmanager.pas | 45 +++++++++++++++++++----------------------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/ide/idecmdline.pas b/ide/idecmdline.pas index 0d54cf7fc9..e93acaefd6 100644 --- a/ide/idecmdline.pas +++ b/ide/idecmdline.pas @@ -65,6 +65,7 @@ procedure ParseCommandLine(aCmdLineParams: TStrings; out IDEPid : Integer; function GetCommandLineParameters(aCmdLineParams: TStrings; isStartLazarus: Boolean = False) : string; function ExtractPrimaryConfigPath(aCmdLineParams: TStrings): string; +function ExpandParamFile(const s: string): string; function IsHelpRequested : Boolean; function IsVersionRequested : boolean; @@ -282,6 +283,19 @@ begin end; end; +function ExpandParamFile(const s: string): string; +var + p: string; +begin + Result:=s; + for p in [PrimaryConfPathOptLong,SecondaryConfPathOptLong,LazarusDirOpt] do + if LeftStr(Result,length(p))=p then + begin + Result:=LeftStr(Result,length(p))+ExpandFileNameUTF8(copy(Result,length(p)+1,length(Result))); + exit; + end; +end; + function IsHelpRequested : Boolean; var i: integer; diff --git a/ide/ideinstances.pas b/ide/ideinstances.pas index fa27dbd24c..c91629616a 100644 --- a/ide/ideinstances.pas +++ b/ide/ideinstances.pas @@ -483,6 +483,7 @@ begin debugln(['Debug: (lazarus) ',aPID,' TIDEInstances.StartUserBuiltIDE FileAge: Custom=',CustomExe,':',FileAgeUTF8(CustomExe),' < Default=',DefaultExe,':',FileAgeUTF8(DefaultExe)]); exit; end; + //debugln(['Debug: (lazarus) ',aPID,' TIDEInstances.StartUserBuiltIDE FileAge: Custom=',CustomExe,':',FileAgeUTF8(CustomExe),' >= Default=',DefaultExe,':',FileAgeUTF8(DefaultExe)]); if DirectoryIsWritable(DefaultDir) then begin @@ -520,7 +521,7 @@ begin {$ENDIF} // append params, including the lazarus.cfg params for i:=1 to CfgParams.Count-1 do - Params.Add(CfgParams[i]); + Params.Add(ExpandParamFile(CfgParams[i])); aProcess.Parameters:=Params; debugln(['Note: (lazarus) ',aPID,' TIDEInstances.StartUserBuiltIDE Starting custom IDE: aProcess.Executable=',aProcess.Executable,' Params=[',Params.Text,']']); aProcess.Execute; diff --git a/ide/lazarusmanager.pas b/ide/lazarusmanager.pas index 9aa16f67f5..80f79858b5 100644 --- a/ide/lazarusmanager.pas +++ b/ide/lazarusmanager.pas @@ -113,13 +113,13 @@ type FProcess: TProcessUTF8; FWantsRestart: boolean; public - constructor Create(const LazarusPath: string; const CommandLine: string; - EnvOverrides: TStringList = nil); + constructor Create; destructor Destroy; override; procedure Execute; procedure WaitOnExit; property WantsRestart: boolean read FWantsRestart; property OnStart: TNotifyEvent read FOnStart write FOnStart; + property Process: TProcessUTF8 read FProcess; end; type @@ -283,6 +283,8 @@ var MsgResult: TModalResult; StartPath: String; EnvOverrides: TStringList; + Params: TStringListUTF8; + i: Integer; begin WaitForLazarus; try @@ -380,10 +382,15 @@ begin DebugLn(['Info: (startlazarus) [TLazarusManager.Run] starting ',FLazarusPath,' ...']); EnvOverrides:=TStringList.Create; + Params:=TStringListUTF8.Create; + FLazarusProcess := TLazarusProcess.Create; try {$IFDEF Linux} EnvOverrides.Values['LIBOVERLAY_SCROLLBAR']:='0'; {$ENDIF} + FLazarusProcess.Process.Executable:=fLazarusPath; + if (EnvOverrides<>nil) and (EnvOverrides.Count>0) then + AssignEnvironmentTo(FLazarusProcess.Process.Environment,EnvOverrides); {$IFDEF darwin} // "open" process runs a bundle, but doesn't wait for it to finish execution // "startlazarus" logic suggests that the Lazarus process would be waited @@ -391,20 +398,18 @@ begin // would repeat the restart process. // Since "open" doesn't play nice with "startlazarus" logic. // The arguments would not indicate that lazarus was started by startlazarus - FLazarusProcess := - TLazarusProcess.Create('open', - ' -a ' + FLazarusPath + ' --args' - +' '+NoSplashScreenOptLong - +' '+GetCommandLineParameters(FCmdLineParams, False) - +' '+FCmdLineFiles, - EnvOverrides); - {$ELSE} - FLazarusProcess := - TLazarusProcess.Create(FLazarusPath, - GetCommandLineParameters(FCmdLineParams, True)+' '+FCmdLineFiles, - EnvOverrides); + FLazarusProcess.Process.Executable:='/usr/bin/open'; + Params.Add('-a'); + Params.Add(FLazarusPath); + Params.Add('--args'); {$ENDIF} + Params.Add(NoSplashScreenOptLong); + Params.Add(StartedByStartLazarusOpt); + for i:=0 to FCmdLineParams.Count-1 do + Params.Add(ExpandParamFile(FCmdLineParams[i])); + FLazarusProcess.Process.Parameters.AddStrings(Params); finally + Params.Free; EnvOverrides.Free; end; // clear the command line files, so that they are passed only once. @@ -432,22 +437,12 @@ end; { TLazarusProcess } -constructor TLazarusProcess.Create(const LazarusPath: string; - const CommandLine: string; EnvOverrides: TStringList); -var - Params: TStringListUTF8; +constructor TLazarusProcess.Create; begin FProcess := TProcessUTF8.Create(nil); FProcess.InheritHandles := false; FProcess.Options := []; FProcess.ShowWindow := swoShow; - Params:=TStringListUTF8.Create; - SplitCmdLineParams(CommandLine,Params); - FProcess.Executable:=LazarusPath; - FProcess.Parameters:=Params; - Params.Free; - if (EnvOverrides<>nil) and (EnvOverrides.Count>0) then - AssignEnvironmentTo(FProcess.Environment,EnvOverrides); end; destructor TLazarusProcess.Destroy;