Changeset 161 for trunk/Target.pas
- Timestamp:
- Aug 20, 2024, 12:20:49 AM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target.pas
r151 r161 80 80 protected 81 81 FCompiledExtension: string; 82 FRunExtension: string;83 82 FSourceExtension: string; 84 83 FName: string; … … 118 117 procedure Compile; virtual; 119 118 procedure CompileToFile; virtual; 119 function GetSourceFileName: string; virtual; 120 function GetCompileParams: TStringArray; virtual; 121 function GetCompileFileName: string; virtual; 120 122 procedure RunFromFile; virtual; 123 function GetRunParams: TStringArray; virtual; 121 124 procedure Run; virtual; 122 125 procedure Pause; virtual; … … 129 132 procedure SaveToRegistry(Context: TRegistryContext); virtual; 130 133 property SourceExtension: string read FSourceExtension; 131 property RunExtension: string read FRunExtension;132 134 property CompiledExtension: string read FCompiledExtension; 133 135 property Name: string read FName; … … 183 185 184 186 uses 185 FormConsole ;187 FormConsole, Common; 186 188 187 189 procedure UpdateTranslation; … … 491 493 procedure TTarget.CompileToFile; 492 494 var 493 Process: TProcess; 494 CompiledFile: string; 495 SourceFile: string; 495 496 Lines: TStringList; 496 I: Integer;497 begin 498 CompiledFile := ExtractFilePath(ProjectFileName) +499 CompiledDir + DirectorySeparator + Name + DirectorySeparator + 500 ExtractFileNameOnly(ProjectFileName) + SourceExtension;501 ForceDirectories(ExtractFilePath( CompiledFile));497 Output, Error: string; 498 Executable: string; 499 Parameters: array of string; 500 begin 501 SourceFile := GetSourceFileName; 502 ForceDirectories(ExtractFilePath(SourceFile)); 502 503 with TStringList.Create do 503 504 try 504 505 Text := FTargetCode; 505 SaveToFile( CompiledFile);506 SaveToFile(SourceFile); 506 507 finally 507 508 Free; 508 509 end; 509 510 if CompilerPath <> '' then begin; 510 if FileExists(CompilerPath) then 511 try 512 Process := TProcess.Create(nil); 513 Process.CurrentDirectory := ExtractFilePath(CompiledFile); 514 Process.Executable := LongFileName(CompilerPath); 515 Process.Parameters.Add(LongFileName(CompiledFile)); 516 for I := 0 to GetEnvironmentVariableCount - 1 do 517 Process.Environment.Add(GetEnvironmentString(I)); 518 Process.Options := [poWaitOnExit, poUsePipes]; 519 Process.Execute; 511 if FileExists(CompilerPath) then begin 512 Executable := LongFileName(CompilerPath); 513 Parameters := GetCompileParams; 514 515 ExecuteProgramOutput(Executable, GetCompileParams, GetEnvironmentVariables, 516 Output, Error, ExitCode, ExtractFilePath(SourceFile)); 517 520 518 if Assigned(FOnLog) then begin 521 519 Lines := TStringList.Create; 522 Lines. LoadFromStream(Process.Output);523 Lines.Insert(0, Process.Executable + ' ' + Process.Parameters.Text);520 Lines.Text := Output; 521 Lines.Insert(0, Executable + ' ' + Implode(',', Parameters)); 524 522 FOnLog(Lines); 525 523 Lines.Free; 526 524 end; 527 finally 528 Process.Free; 525 529 526 end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath])); 530 527 end; 531 528 end; 532 529 533 procedure TTarget.RunFromFile; 534 var 535 CompiledFile: string; 536 RunFile: string; 537 FormConsole: TFormConsole; 538 begin 539 CompiledFile := ExtractFilePath(ProjectFileName) + 530 function TTarget.GetSourceFileName: string; 531 begin 532 Result := ExtractFilePath(ProjectFileName) + 533 CompiledDir + DirectorySeparator + Name + DirectorySeparator + 534 ExtractFileNameOnly(ProjectFileName) + SourceExtension; 535 end; 536 537 function TTarget.GetCompileParams: TStringArray; 538 begin 539 Result := [LongFileName(GetSourceFileName)]; 540 end; 541 542 function TTarget.GetCompileFileName: string; 543 begin 544 Result := ExtractFilePath(ProjectFileName) + 540 545 CompiledDir + DirectorySeparator + Name + DirectorySeparator + 541 546 ExtractFileNameOnly(ProjectFileName) + CompiledExtension; 542 RunFile := ExtractFilePath(ProjectFileName) + 543 CompiledDir + DirectorySeparator + Name + DirectorySeparator + 544 ExtractFileNameOnly(ProjectFileName) + RunExtension; 547 end; 548 549 procedure TTarget.RunFromFile; 550 var 551 CompiledFile: string; 552 FormConsole: TFormConsole; 553 Parameters: TStringArray; 554 I: Integer; 555 begin 556 CompiledFile := GetCompileFileName; 545 557 if FileExists(CompiledFile) then 546 558 try … … 550 562 raise Exception.Create(Format(SExecutorNotFound, [ExecutorPath])); 551 563 FormConsole.Executable := LongFileName(ExecutorPath); 552 FormConsole.Parameters.Add(LongFileName(RunFile)); 564 Parameters := GetRunParams; 565 for I := 0 to Length(Parameters) - 1 do 566 FormConsole.Parameters.Add(Parameters[I]); 553 567 end else 554 FormConsole.Executable := LongFileName( RunFile);568 FormConsole.Executable := LongFileName(CompiledFile); 555 569 FormConsole.ShowModal; 556 570 finally … … 558 572 end 559 573 else raise Exception.Create(Format(SCompiledFileNotFound, [CompiledFile])); 574 end; 575 576 function TTarget.GetRunParams: TStringArray; 577 begin 578 Result := [LongFileName(GetCompileFileName)]; 560 579 end; 561 580
Note:
See TracChangeset
for help on using the changeset viewer.