Browse Source

--- Merging r19046 into '.':
U packages/fppkg/src/pkghandler.pp
--- Recording mergeinfo for merge of r19046 into '.':
U .
--- Merging r20065 into '.':
U utils/fppkg/fppkg.pp
--- Recording mergeinfo for merge of r20065 into '.':
G .

git-svn-id: branches/fixes_2_6@25437 -

joost 12 years ago
parent
commit
66ad4e0a26
2 changed files with 110 additions and 2 deletions
  1. 104 0
      packages/fppkg/src/pkghandler.pp
  2. 6 2
      utils/fppkg/fppkg.pp

+ 104 - 0
packages/fppkg/src/pkghandler.pp

@@ -2,12 +2,27 @@
 {$h+}
 unit pkghandler;
 
+{$IFDEF OS2}
+ {$DEFINE NO_UNIT_PROCESS}
+{$ENDIF OS2}
+
+{$IFDEF GO32V2}
+ {$DEFINE NO_UNIT_PROCESS}
+{$ENDIF GO32V2}
+
+{$ifndef NO_UNIT_PROCESS}
+  {$define HAS_UNIT_PROCESS}
+{$endif NO_UNIT_PROCESS}
+
 interface
 
 uses
   Classes,SysUtils,
   pkgglobals,
   pkgoptions,
+{$ifdef HAS_UNIT_PROCESS}
+  process,
+{$endif HAS_UNIT_PROCESS}
   fprepos;
 
 type
@@ -169,11 +184,100 @@ begin
   FPackageName:=APackageName;
 end;
 
+{$ifdef HAS_UNIT_PROCESS}
+function ExecuteFPC(const Path: string; const ComLine: string): integer;
+var
+  P: TProcess;
+  ConsoleOutput: TMemoryStream;
+  BytesRead: longint;
+
+  function ReadFromStream: longint;
+
+  const
+    READ_BYTES = 2048;
+
+  var
+    n: longint;
+    BuffPos: longint;
+    sLine: string;
+    ch: char;
+  begin
+    // make sure we have room
+    ConsoleOutput.SetSize(BytesRead + READ_BYTES);
+
+    // try reading it
+    n := P.Output.Read((ConsoleOutput.Memory + BytesRead)^, READ_BYTES);
+    if n > 0 then
+    begin
+      Inc(BytesRead, n);
+
+      sLine := '';
+      BuffPos := ConsoleOutput.Position;
+
+      //read lines from the stream
+      repeat
+        ConsoleOutput.Read(ch,1);
+
+        if ch in [#10, #13] then
+        begin
+          log(vlProgres,sLine);
+          sLine := '';
+          BuffPos := ConsoleOutput.Position;
+        end
+        else
+          sLine := sLine + ch;
+
+      until ConsoleOutput.Position >= BytesRead;
+
+      ConsoleOutput.Position := BuffPos;
+    end
+    else
+    begin
+      // no data, wait 100 ms
+      Sleep(100);
+    end;
+
+    Result := n;
+  end;
+
+begin
+  result := -1;
+  BytesRead := 0;
+  ConsoleOutput := TMemoryStream.Create;
+  try
+    P := TProcess.Create(nil);
+    try
+      P.CommandLine := Path + ' ' + ComLine;
+      P.Options := [poUsePipes];
+      P.Execute;
+      while P.Running do
+        ReadFromStream;
+
+      // read last part
+      repeat
+      until ReadFromStream = 0;
+      ConsoleOutput.SetSize(BytesRead);
+
+      result := P.ExitStatus;
+    finally
+      P.Free;
+    end;
+  finally
+    ConsoleOutput.Free;
+  end;
+end;
+{$endif HAS_UNIT_PROCESS}
+
 Function TPackageHandler.ExecuteProcess(Const Prog,Args:String):Integer;
+var T:TProcess;
 begin
   Log(vlCommands,SLogExecute,[Prog,Args]);
   Flush(StdOut);
+{$ifdef HAS_UNIT_PROCESS}
+  Result:=ExecuteFPC(Prog,Args);
+{$else HAS_UNIT_PROCESS}
   Result:=SysUtils.ExecuteProcess(Prog,Args);
+{$endif HAS_UNIT_PROCESS}
 end;
 
 

+ 6 - 2
utils/fppkg/fppkg.pp

@@ -320,8 +320,12 @@ begin
     FindInstalledPackages(FPMakeCompilerOptions,true);
     CheckFPMakeDependencies;
     // We only need to reload the status when we use a different
-    // configuration for compiling fpmake
-    if GlobalOptions.CompilerConfig<>GlobalOptions.FPMakeCompilerConfig then
+    // configuration for compiling fpmake or when the CPU, OS or compiler
+    // are set in the command-line
+    if (GlobalOptions.CompilerConfig<>GlobalOptions.FPMakeCompilerConfig) or
+       (CompilerOptions.CompilerCPU<>FPMakeCompilerOptions.CompilerCPU) or
+       (CompilerOptions.CompilerOS<>FPMakeCompilerOptions.CompilerOS) or
+       (CompilerOptions.Compiler<>FPMakeCompilerOptions.Compiler) then
       FindInstalledPackages(CompilerOptions,true);
 
     // Check for broken dependencies