[Lazarus] a patch (was: Re: Is win32 svn broken?)

Gregory M. Turner gmt at malth.us
Thu Oct 13 17:26:58 CEST 2011


This almost works:

Index: buildlazdialog.pas
===================================================================
--- buildlazdialog.pas	(revision 32869)
+++ buildlazdialog.pas	(working copy)
@@ -145,7 +145,8 @@
 function CreateBuildLazarusOptions(Profiles: TBuildLazarusProfiles;
   Macros: TTransferMacroList; const PackageOptions: string;
   Flags: TBuildLazarusFlags; var AExOptions: string;
-  out UpdateRevisionInc: boolean; out OutputDirRedirected: boolean): TModalResult;
+  out UpdateRevisionInc: boolean; out OutputDirRedirected: boolean;
+  out ExeIsLocked: boolean): TModalResult;
 
 function SaveIDEMakeOptions(Profiles: TBuildLazarusProfiles;
   Macros: TTransferMacroList;
@@ -200,10 +201,9 @@
 var
   Tool: TExternalToolOptions;
   Options: TBuildLazarusProfile;
-  i: Integer;
   ExOptions: String;
   WorkingDirectory: String;
-  OutputDirRedirected, UpdateRevisionInc: boolean;
+  OutputDirRedirected, UpdateRevisionInc, ExeIsLocked: boolean;
 begin
   Result:=mrCancel;
 
@@ -262,13 +262,14 @@
       Tool.Title:=lisIDE;
       Tool.WorkingDirectory:=WorkingDirectory;
       case Options.IdeBuildMode of
-        bmBuild:      Tool.CmdLineParams:='all';
+        bmBuild:      Tool.CmdLineParams:='lazbuilder starter';
         bmCleanBuild: Tool.CmdLineParams:='clean all';
       end;
       // append extra options
       ExOptions:='';
       Result:=CreateBuildLazarusOptions(Profiles,Macros,PackageOptions,Flags,
-                                 ExOptions,UpdateRevisionInc,OutputDirRedirected);
+                                 ExOptions,UpdateRevisionInc,
+                                 OutputDirRedirected, ExeIsLocked);
       if Result<>mrOk then exit;
 
       if (not OutputDirRedirected)
@@ -290,6 +291,35 @@
       // run
       Result:=ExternalTools.Run(Tool,Macros,false);
       if Result<>mrOk then exit;
+      Tool.CmdLineParams:='ide';    // one more time...
+      // maybe superfluous?  just make sure there's something
+      // to append to
+      if ExeIsLocked and (ExOptions = '') then
+          Tool.EnvironmentOverrides.Values['OPT']:='';
+      if ExeIsLocked then begin
+          // FPC automatically changes the last extension (append or replace)
+          // For example under linux, where executables don't need any extension
+          // fpc removes the last extension of the -o option.
+          // Trick fpc:
+          if GetExecutableExt(Options.FPCTargetOS)='' then
+             Tool.EnvironmentOverrides.Values['OPT'] :=
+               Tool.EnvironmentOverrides.Values['OPT']+'.dummy'
+          else
+              Tool.EnvironmentOverrides.Values['OPT']:=
+                Tool.EnvironmentOverrides.Values['OPT']+' -olazarus.new'+
+                  GetExecutableExt(Options.FPCTargetOS);
+      end;
+
+      // add -w option to print leaving/entering messages
+      Tool.CmdLineParams:=Tool.CmdLineParams+' -w';
+      // append target OS
+      if Options.TargetOS<>'' then
+        Tool.CmdLineParams:=Tool.CmdLineParams+' OS_TARGET='+Options.FPCTargetOS;
+      // append target CPU
+      if Options.TargetCPU<>'' then
+        Tool.CmdLineParams:=Tool.CmdLineParams+' CPU_TARGET='+Options.FPCTargetCPU;
+      Result:=ExternalTools.Run(Tool,Macros,false);
+      if Result <> mrOK then exit;
     end;
     Result:=mrOk;
   finally
@@ -302,7 +332,8 @@
 function CreateBuildLazarusOptions(Profiles: TBuildLazarusProfiles;
   Macros: TTransferMacroList; const PackageOptions: string;
   Flags: TBuildLazarusFlags; var AExOptions: string;
-  out UpdateRevisionInc: boolean; out OutputDirRedirected: boolean): TModalResult;
+  out UpdateRevisionInc: boolean; out OutputDirRedirected: boolean;
+  out ExeIsLocked: boolean): TModalResult;
 
   procedure AppendExtraOption(const AddOption: string; EncloseIfSpace: boolean);
   begin
@@ -339,6 +370,7 @@
   Result:=mrOk;
   Options:=Profiles.Current;
   OutputDirRedirected:=false;
+  ExeIsLocked := false;
   UpdateRevisionInc:=Options.UpdateRevisionInc;
 
   // create extra options
@@ -511,17 +543,9 @@
     // FPC interpretes '\ ' as an escape for a space in a path,
     // so make sure the directory doesn't end with the path delimeter.
     AppendExtraOption('-FE'+ChompPathDelim(NewTargetDirectory));
+  if NewTargetFilename<>'' then
+    ExeIsLocked := True;
 
-  if NewTargetFilename<>'' then begin
-    // FPC automatically changes the last extension (append or replace)
-    // For example under linux, where executables don't need any extension
-    // fpc removes the last extension of the -o option.
-    // Trick fpc:
-    if GetExecutableExt(NewTargetOS)='' then
-      NewTargetFilename:=NewTargetFilename+'.dummy';
-    AppendExtraOption('-o'+NewTargetFilename);
-  end;
-
   // add package options for IDE
   //DebugLn(['CreateBuildLazarusOptions blfUseMakeIDECfg=',blfUseMakeIDECfg in FLags,' ExtraOptions="',AExOptions,'" ',PackageOptions]);
   if not (blfUseMakeIDECfg in Flags) then
@@ -588,10 +612,12 @@
   OptionsAsText: String;
   UpdateRevisionInc: boolean;
   OutputDirRedirected: boolean;
+  ExeIsLocked: boolean;
 begin
   ExOptions:='';
   Result:=CreateBuildLazarusOptions(Profiles, Macros, PackageOptions, Flags,
-                               ExOptions, UpdateRevisionInc, OutputDirRedirected);
+                               ExOptions, UpdateRevisionInc,
+                               OutputDirRedirected, ExeIsLocked);
   if Result<>mrOk then exit;
   Filename:=GetMakeIDEConfigFilename;
   try
--

Amusingly, however, with this patch, if you we try to build the IDE twice in a row, startlazarus stays running and it fails trying to build startlazarus.exe... sigh.  Should startlazarus be getting out of the way once it's renamed and invoked the new lazarus.exe?  Or is some kind of IPC supposed to happen to shut it down?

-gmt




More information about the Lazarus mailing list