IDE: invoke compiler: do not setcurrentdir

git-svn-id: trunk@35818 -
This commit is contained in:
mattias 2012-03-08 09:12:32 +00:00
parent 131d339368
commit fd960b161e
2 changed files with 85 additions and 97 deletions

View File

@ -8,8 +8,7 @@ interface
uses uses
Wiki2FPDocConvert, WikiFormat, Wiki2XHTMLConvert, Wiki2CHMConvert, Wiki2FPDocConvert, WikiFormat, Wiki2XHTMLConvert, Wiki2CHMConvert,
WikiParser, Wiki2HTMLConvert, wikihtmlindexer, WikiStrConsts, WikiParser, Wiki2HTMLConvert, WikiStrConsts, LazarusPackageIntf;
LazarusPackageIntf;
implementation implementation

View File

@ -66,7 +66,6 @@ type
FOnCmdLineCreate : TOnCmdLineCreate; FOnCmdLineCreate : TOnCmdLineCreate;
FOutputFilter: TOutputFilter; FOutputFilter: TOutputFilter;
FTheProcess: TProcessUTF8; FTheProcess: TProcessUTF8;
FOldCurDir: string;
{$IFDEF WithAsyncCompile} {$IFDEF WithAsyncCompile}
FFinishedCallback: TNotifyEvent; FFinishedCallback: TNotifyEvent;
procedure CompilationFinished(Sender: TObject); procedure CompilationFinished(Sender: TObject);
@ -142,109 +141,99 @@ begin
// if we want to show the compile progress, it's now time to show the dialog // if we want to show the compile progress, it's now time to show the dialog
CompileProgress.Show; CompileProgress.Show;
// change working directory CmdLine := CompilerFilename;
FOldCurDir:=GetCurrentDirUTF8;
if not SetCurrentDirUTF8(WorkingDir) then begin if Assigned(FOnCmdLineCreate) then begin
WriteError('TCompiler.Compile unable to set working directory '+WorkingDir); Abort:=false;
exit; FOnCmdLineCreate(CmdLine,Abort);
if Abort then begin
Result:=mrAbort;
exit;
end;
end; end;
try try
CmdLine := CompilerFilename; CheckIfFileIsExecutable(CmdLine);
except
if Assigned(FOnCmdLineCreate) then begin on E: Exception do begin
Abort:=false; WriteError(Format(lisCompilerErrorInvalidCompiler, [E.Message]));
FOnCmdLineCreate(CmdLine,Abort); if CmdLine='' then begin
if Abort then begin WriteError(lisCompilerHintYouCanSetTheCompilerPath);
Result:=mrAbort;
exit;
end; end;
exit;
end; end;
try end;
CheckIfFileIsExecutable(CmdLine); if BuildAll then
except CmdLine := CmdLine+' -B';
on E: Exception do begin if SkipLinking and SkipAssembler then
WriteError(Format(lisCompilerErrorInvalidCompiler, [E.Message])); CmdLine := CmdLine+' -s'
if CmdLine='' then begin else if SkipLinking then
WriteError(lisCompilerHintYouCanSetTheCompilerPath); CmdLine := CmdLine+' -Cn';
end;
exit;
end;
end;
if BuildAll then
CmdLine := CmdLine+' -B';
if SkipLinking and SkipAssembler then
CmdLine := CmdLine+' -s'
else if SkipLinking then
CmdLine := CmdLine+' -Cn';
if CompilerParams<>'' then
CmdLine := CmdLine+' '+CompilerParams;
if Assigned(FOnCmdLineCreate) then begin
Abort:=false;
FOnCmdLineCreate(CmdLine,Abort);
if Abort then begin
Result:=mrAbort;
exit;
end;
end;
DebugLn('[TCompiler.Compile] CmdLine="',CmdLine,'"');
if CompilerParams<>'' then
CmdLine := CmdLine+' '+CompilerParams;
if Assigned(FOnCmdLineCreate) then begin
Abort:=false;
FOnCmdLineCreate(CmdLine,Abort);
if Abort then begin
Result:=mrAbort;
exit;
end;
end;
DebugLn('[TCompiler.Compile] CmdLine="',CmdLine,'"');
try
if TheProcess=nil then
FTheProcess := TOutputFilterProcess.Create(nil);
TheProcess.CommandLine := CmdLine;
TheProcess.Options:= [poUsePipes, poStdErrToOutput];
TheProcess.ShowWindow := swoHide;
Result:=mrOk;
try try
if TheProcess=nil then TheProcess.CurrentDirectory:=WorkingDir;
FTheProcess := TOutputFilterProcess.Create(nil);
TheProcess.CommandLine := CmdLine; if OutputFilter<>nil then begin
TheProcess.Options:= [poUsePipes, poStdErrToOutput]; if BuildAll and Assigned(IDEMessagesWindow) then
TheProcess.ShowWindow := swoHide; IDEMessagesWindow.AddMsg(lisOptionsChangedRecompilingCleanWithB,
Result:=mrOk; WorkingDir, -1);
try OutputFilter.Options:=[ofoSearchForFPCMessages,ofoExceptionOnError];
TheProcess.CurrentDirectory:=WorkingDir; OutputFilter.CompilerOptions:=AProject.CompilerOptions;
{$IFDEF WithAsyncCompile}
if OutputFilter<>nil then begin if aFinishedCallback <> nil then
if BuildAll and Assigned(IDEMessagesWindow) then begin
IDEMessagesWindow.AddMsg(lisOptionsChangedRecompilingCleanWithB, OutputFilter.ExecuteAsyncron(TheProcess, @CompilationFinished, Self);
WorkingDir, -1); end
OutputFilter.Options:=[ofoSearchForFPCMessages,ofoExceptionOnError]; else
OutputFilter.CompilerOptions:=AProject.CompilerOptions; {$ENDIF}
{$IFDEF WithAsyncCompile} if not OutputFilter.Execute(TheProcess,Self) then
if aFinishedCallback <> nil then if OutputFilter.Aborted then
begin Result := mrAbort
OutputFilter.ExecuteAsyncron(TheProcess, @CompilationFinished, Self); else
end Result := mrCancel;
else end else begin
{$ENDIF} TheProcess.Execute;
if not OutputFilter.Execute(TheProcess,Self) then
if OutputFilter.Aborted then
Result := mrAbort
else
Result := mrCancel;
end else begin
TheProcess.Execute;
end;
finally
if TheProcess.Running
{$IFDEF WithAsyncCompile} and ((OutputFilter = nil) or (aFinishedCallback = nil)) {$ENDIF}
then begin
TheProcess.WaitOnExit;
if not (TheProcess.ExitStatus in [0,1]) then begin
WriteError(Format(listCompilerInternalError,[TheProcess.ExitStatus]));
Result:=mrCancel;
end;
end;
end; end;
except finally
on e: EOutputFilterError do begin if TheProcess.Running
Result:=mrCancel; {$IFDEF WithAsyncCompile} and ((OutputFilter = nil) or (aFinishedCallback = nil)) {$ENDIF}
exit; then begin
end; TheProcess.WaitOnExit;
on e: Exception do begin if not (TheProcess.ExitStatus in [0,1]) then begin
DebugLn('[TCompiler.Compile] exception "',E.Message,'"'); WriteError(Format(listCompilerInternalError,[TheProcess.ExitStatus]));
WriteError(E.Message); Result:=mrCancel;
Result:=mrCancel; end;
exit;
end; end;
end; end;
finally except
SetCurrentDirUTF8(FOldCurDir); on e: EOutputFilterError do begin
Result:=mrCancel;
exit;
end;
on e: Exception do begin
DebugLn('[TCompiler.Compile] exception "',E.Message,'"');
WriteError(E.Message);
Result:=mrCancel;
exit;
end;
end; end;
DebugLn('[TCompiler.Compile] end'); DebugLn('[TCompiler.Compile] end');
end; end;