Ignore:
Timestamp:
Jul 17, 2012, 9:15:42 AM (12 years ago)
Author:
chronos
Message:
  • Added: Form with text output of executed external producer tool.
  • Fixed: Template for new unit mustn't initialize new project but only add unit file to project.
  • Added: Project manager file deletion and rename.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/UProducer.pas

    r59 r61  
    66
    77uses
    8   USourceCode, Classes, SysUtils, StrUtils, SpecializedList;
     8  USourceCode, Classes, SysUtils, StrUtils, SpecializedList, Process,
     9  FileUtil, Forms;
    910
    1011type
    1112
    1213  TWriteTargetEvent = function (Name: string; const Code: string): Boolean of object;
     14  TStringEvent = procedure (Value: string) of object;
    1315
    1416  { TProducer }
     
    1618  TProducer = class
    1719  private
     20    FOnProcessOutput: TStringEvent;
    1821    FOnWriteTarget: TWriteTargetEvent;
    1922  public
     23    Process: TProcess;
    2024    TextSource: TStringList;
    2125    IndentationLength: Integer;
    2226    Indentation: Integer;
    2327    CompilerPath: string;
     28    CompilerParameters: string;
    2429    procedure Emit(AText: string);
    2530    procedure EmitLn(AText: string = '');
    2631    procedure AssignToStringList(Target: TStringList); virtual; abstract;
    2732    procedure Produce(Module: TModule); virtual; abstract;
     33    procedure ExternalExecute(CommandLine: string);
    2834    constructor Create;
    2935    destructor Destroy; override;
    3036    property OnWriteTarget: TWriteTargetEvent read FOnWriteTarget write FOnWriteTarget;
     37    property OnProcessOutput: TStringEvent read FOnProcessOutput write FOnProcessOutput;
    3138  end;
    3239
     
    4148end;
    4249
     50procedure TProducer.ExternalExecute(CommandLine: string);
     51var
     52  Buffer: string;
     53  Count: Integer;
     54  Text: string;
     55  Line: string;
     56begin
     57  if not FileExistsUTF8(CompilerPath) then Exit;
     58  Text := '';
     59  try
     60    Process := TProcess.Create(nil);
     61    //if Path <> '' then
     62    //  Process.CurrentDirectory := Path;
     63    //Path := '';
     64    //if Environment <> '' then
     65    //  Process.Environment.Text := Environment;
     66    //Environment := '';
     67    Process.CommandLine := CommandLine;
     68    Process.Options := [poUsePipes, poNoConsole];
     69    Process.Execute;
     70    Application.ProcessMessages;
     71    while Process.Running or (Process.Output.NumBytesAvailable > 0) or
     72    (Process.Stderr.NumBytesAvailable > 0) do
     73    begin
     74      if Process.Output.NumBytesAvailable > 0 then begin
     75        SetLength(Buffer, 1000);
     76        Count := Process.Output.Read(Buffer[1], Length(Buffer));
     77        SetLength(Buffer, Count);
     78        Text := Text + Buffer;
     79        while Pos(LineEnding, Text) > 0 do begin
     80          Line := Copy(Text, 1, Pos(LineEnding, Text) - 1);
     81          Delete(Text, 1, Length(Line) + Length(LineEnding));
     82          if Assigned(FOnProcessOutput) then
     83            FOnProcessOutput(Line);
     84        end;
     85      end;
     86
     87      if Process.Stderr.NumBytesAvailable > 0 then begin
     88        SetLength(Buffer, 1000);
     89        Count := Process.Stderr.Read(Buffer[1], Length(Buffer));
     90        SetLength(Buffer, Count);
     91        Text := Text + Buffer;
     92        while Pos(LineEnding, Text) > 0 do begin
     93          Line := Copy(Text, 1, Pos(LineEnding, Text) - 1);
     94          Delete(Text, 1, Length(Line) + Length(LineEnding));
     95          if Assigned(FOnProcessOutput) then
     96            FOnProcessOutput(Line);
     97        end;
     98      end;
     99      Sleep(10);
     100      Application.ProcessMessages;
     101    end;
     102  finally
     103    if Assigned(FOnProcessOutput) then
     104      FOnProcessOutput(Text);
     105    FreeAndNil(Process);
     106  end;
     107end;
     108
    43109constructor TProducer.Create;
    44110begin
    45111  TextSource := TStringList.Create;
    46112  IndentationLength := 2;
     113  CompilerParameters := '%0:s';
    47114end;
    48115
Note: See TracChangeset for help on using the changeset viewer.