remove more nonsense setCurrDir while calling dub or dmd

This commit is contained in:
Basile Burg 2019-02-03 20:38:57 +01:00
parent 3422a25b4d
commit c9fac84dab
3 changed files with 52 additions and 87 deletions

View File

@ -33,7 +33,6 @@ type
fModified: boolean; fModified: boolean;
fRootFolder: string; fRootFolder: string;
fBasePath: string; fBasePath: string;
fRunnerOldCwd: string;
fVersion: string; fVersion: string;
fLibAliases: TStringList; fLibAliases: TStringList;
fAutoDeps: boolean; fAutoDeps: boolean;
@ -157,24 +156,20 @@ begin
fAsProjectItf := self as ICommonProject; fAsProjectItf := self as ICommonProject;
fSymStringExpander := getSymStringExpander; fSymStringExpander := getSymStringExpander;
fMsgs:= getMessageDisplay; fMsgs:= getMessageDisplay;
//
fRunnerOldCwd := GetCurrentDirUTF8;
fProjectSubject := TProjectSubject.create; fProjectSubject := TProjectSubject.create;
//
fLibAliases := TStringList.Create; fLibAliases := TStringList.Create;
fSrcs := TStringList.Create; fSrcs := TStringList.Create;
fSrcs.OnChange := @subMemberChanged; fSrcs.OnChange := @subMemberChanged;
fConfigs := TCollection.create(TCompilerConfiguration); fConfigs := TCollection.create(TCompilerConfiguration);
//
reset; reset;
addDefaults; addDefaults;
subjProjNew(fProjectSubject, self); subjProjNew(fProjectSubject, self);
subjProjChanged(fProjectSubject, self); subjProjChanged(fProjectSubject, self);
//
{$IFNDEF WINDOWS} {$IFNDEF WINDOWS}
fBasePath := '/'; fBasePath := '/';
{$ENDIF} {$ENDIF}
//
fModified := false; fModified := false;
end; end;
@ -873,14 +868,10 @@ end;
procedure TNativeProject.run(const runArgs: string = ''); procedure TNativeProject.run(const runArgs: string = '');
var var
prm: string; p: string;
i: Integer; i: integer;
cwd: string;
begin begin
killProcess(fRunner); killProcess(fRunner);
if fRunnerOldCwd.dirExists then
ChDir(fRunnerOldCwd);
//
fRunner := TDexedProcess.Create(nil); fRunner := TDexedProcess.Create(nil);
fRunner.XTermProgram:=consoleProgram; fRunner.XTermProgram:=consoleProgram;
currentConfiguration.runOptions.setProcess(fRunner); currentConfiguration.runOptions.setProcess(fRunner);
@ -888,29 +879,24 @@ begin
begin begin
i := 1; i := 1;
repeat repeat
prm := ExtractDelimited(i, runArgs, [' ']); p := ExtractDelimited(i, runArgs, [' ']);
prm := fSymStringExpander.expand(prm); p := fSymStringExpander.expand(p);
if prm.isNotEmpty then if p.isNotEmpty then
fRunner.Parameters.AddText(prm); fRunner.Parameters.AddText(p);
Inc(i); Inc(i);
until prm = ''; until p = '';
end; end;
//
if not outputFilename.fileExists then if not outputFilename.fileExists then
begin begin
fMsgs.message('output executable missing: ' + shortenPath(outputFilename, 25), fMsgs.message('output executable missing: ' + shortenPath(outputFilename, 25),
fAsProjectItf, amcProj, amkErr); fAsProjectItf, amcProj, amkErr);
exit; exit;
end; end;
//
fRunner.Executable := outputFilename; fRunner.Executable := outputFilename;
fRunnerOldCwd := GetCurrentDirUTF8;
if fRunner.CurrentDirectory.isEmpty then if fRunner.CurrentDirectory.isEmpty then
begin fRunner.CurrentDirectory := fRunner.Executable.extractFilePath;
cwd := fRunner.Executable.extractFilePath;
SetCurrentDirUTF8(cwd);
fRunner.CurrentDirectory := cwd;
end;
if poUsePipes in fRunner.Options then if poUsePipes in fRunner.Options then
begin begin
fRunner.OnReadData := @runProcOutput; fRunner.OnReadData := @runProcOutput;
@ -938,16 +924,13 @@ begin
finally finally
lst.Free; lst.Free;
end; end;
//
proc := TProcess(sender); proc := TProcess(sender);
if not proc.Running then if not proc.Running then
begin begin
getprocInputHandler.removeProcess(TProcess(sender)); getprocInputHandler.removeProcess(TProcess(sender));
SetCurrentDirUTF8(fRunnerOldCwd);
if proc is TDexedProcess then if proc is TDexedProcess then
dproc := TDexedProcess(proc); dproc := TDexedProcess(proc);
if (proc.ExitStatus <> 0) then if (proc.ExitStatus <> 0) then
begin begin
fMsgs.message(format('error: the process (%s) has returned the status %s', fMsgs.message(format('error: the process (%s) has returned the status %s',

View File

@ -114,7 +114,6 @@ type
fInGroup: boolean; fInGroup: boolean;
fHasLoaded: boolean; fHasLoaded: boolean;
fDubProc: TDexedProcess; fDubProc: TDexedProcess;
fPreCompilePath: string;
fPackageName: string; fPackageName: string;
fFilename: string; fFilename: string;
fModified: boolean; fModified: boolean;
@ -1082,12 +1081,10 @@ begin
[fDubProc.autoKillProcThreshold]), nil, amcProj, amkWarn); [fDubProc.autoKillProcThreshold]), nil, amcProj, amkWarn);
end; end;
subjProjCompiled(fProjectSubject, fAsProjectItf, fCompiled); subjProjCompiled(fProjectSubject, fAsProjectItf, fCompiled);
SetCurrentDirUTF8(fPreCompilePath);
end; end;
procedure TDubProject.executeDub(command: TDubCommand; const runArgs: string = ''); procedure TDubProject.executeDub(command: TDubCommand; const runArgs: string = '');
var var
olddir: string;
prjname: string; prjname: string;
rargs: TStringList; rargs: TStringList;
begin begin
@ -1108,56 +1105,49 @@ begin
fMsgs.clearByData(fAsProjectItf); fMsgs.clearByData(fAsProjectItf);
prjname := shortenPath(fFilename); prjname := shortenPath(fFilename);
fDubProc:= TDexedProcess.Create(nil); fDubProc:= TDexedProcess.Create(nil);
olddir := GetCurrentDir; subjProjCompiling(fProjectSubject, fAsProjectItf);
try fMsgs.message(dubCmd2PreMsg[command] + prjname, fAsProjectItf, amcProj, amkInf);
subjProjCompiling(fProjectSubject, fAsProjectItf); if modified then
fMsgs.message(dubCmd2PreMsg[command] + prjname, fAsProjectItf, amcProj, amkInf); saveToFile(fFilename);
if modified then fDubProc.Executable := 'dub' + exeExt;
saveToFile(fFilename); if not dubBuildOptions.showConsole then
chDir(fFilename.extractFilePath); begin
fDubProc.Executable := 'dub' + exeExt; fDubProc.Options := fDubProc.Options + [poStderrToOutPut, poUsePipes];
if not dubBuildOptions.showConsole then fDubProc.OnReadData:= @dubProcOutput;
begin fDubProc.ShowWindow := swoHIDE;
fDubProc.Options := fDubProc.Options + [poStderrToOutPut, poUsePipes]; end
fDubProc.OnReadData:= @dubProcOutput; else
fDubProc.ShowWindow := swoHIDE; begin
end fDubProc.Options := fDubProc.Options + [poWaitOnExit, poNewConsole];
else
begin
fDubProc.Options := fDubProc.Options + [poWaitOnExit, poNewConsole];
end;
fDubProc.CurrentDirectory := fFilename.extractFilePath;
fDubProc.XTermProgram:=consoleProgram;
fDubProc.Parameters.Add(dubCmd2Arg[command]);
fDubProc.OnTerminate:= @dubProcTerminated;
if (command <> dcTest) or not dubBuildOptions.autoSelectTestConfig then
begin
fDubProc.Parameters.Add('--build=' + fBuildTypes[fBuiltTypeIx]);
if (fConfigs.Count <> 1) and (fConfigs[0] <> DubDefaultConfigName) then
fDubProc.Parameters.Add('--config=' + fConfigs[fConfigIx]);
end;
fDubProc.Parameters.Add('--compiler=' + DubCompilerFilename);
dubBuildOptions.getOpts(fDubProc.Parameters);
if (command <> dcBuild) and runArgs.isNotEmpty then
begin
fDubProc.Parameters.Add('--');
rargs := TStringList.Create;
try
CommandToList(runArgs, rargs);
fDubProc.Parameters.AddStrings(rargs);
finally
rargs.Free;
end;
end;
fDubProc.Execute;
finally
SetCurrentDirUTF8(olddir);
end; end;
fDubProc.CurrentDirectory := fFilename.extractFilePath;
fDubProc.XTermProgram:=consoleProgram;
fDubProc.Parameters.Add(dubCmd2Arg[command]);
fDubProc.OnTerminate:= @dubProcTerminated;
if (command <> dcTest) or not dubBuildOptions.autoSelectTestConfig then
begin
fDubProc.Parameters.Add('--build=' + fBuildTypes[fBuiltTypeIx]);
if (fConfigs.Count <> 1) and (fConfigs[0] <> DubDefaultConfigName) then
fDubProc.Parameters.Add('--config=' + fConfigs[fConfigIx]);
end;
fDubProc.Parameters.Add('--compiler=' + DubCompilerFilename);
dubBuildOptions.getOpts(fDubProc.Parameters);
if (command <> dcBuild) and runArgs.isNotEmpty then
begin
fDubProc.Parameters.Add('--');
rargs := TStringList.Create;
try
CommandToList(runArgs, rargs);
fDubProc.Parameters.AddStrings(rargs);
finally
rargs.Free;
end;
end;
fDubProc.Execute;
end; end;
procedure TDubProject.compile; procedure TDubProject.compile;
begin begin
fPreCompilePath := GetCurrentDirUTF8;
executeDub(dcBuild); executeDub(dcBuild);
end; end;
@ -1716,14 +1706,11 @@ var
str: TStringList; str: TStringList;
jsn: TJSONData; jsn: TJSONData;
prs: TJSONParser; prs: TJSONParser;
old: string;
begin begin
result := nil; result := nil;
dub := TProcess.Create(nil); dub := TProcess.Create(nil);
str := TStringList.Create; str := TStringList.Create;
old := GetCurrentDirUTF8;
try try
SetCurrentDirUTF8(filename.extractFilePath);
dub.Executable := 'dub' + exeExt; dub.Executable := 'dub' + exeExt;
dub.Options := [poUsePipes{$IFDEF WINDOWS}, poNewConsole{$ENDIF}]; dub.Options := [poUsePipes{$IFDEF WINDOWS}, poNewConsole{$ENDIF}];
dub.ShowWindow := swoHIDE; dub.ShowWindow := swoHIDE;
@ -1754,7 +1741,6 @@ begin
result := nil; result := nil;
end; end;
finally finally
SetCurrentDirUTF8(old);
dub.free; dub.free;
str.Free; str.Free;
end; end;

View File

@ -186,7 +186,6 @@ var
arg: string; arg: string;
prm: string; prm: string;
inp: string; inp: string;
old: string;
const const
confSpec = 'Are you sure you want to execute the "%s" tool ?'; confSpec = 'Are you sure you want to execute the "%s" tool ?';
begin begin
@ -203,7 +202,6 @@ begin
if askConfirmation and (dlgOkCancel(format(confSpec, [toolAlias])) <> mrOk) then if askConfirmation and (dlgOkCancel(format(confSpec, [toolAlias])) <> mrOk) then
exit; exit;
old := GetCurrentDirUTF8;
fProcess := TDexedProcess.Create(nil); fProcess := TDexedProcess.Create(nil);
fProcess.OnReadData:= @processOutput; fProcess.OnReadData:= @processOutput;
fProcess.OnTerminate:= @processOutput; fProcess.OnTerminate:= @processOutput;
@ -228,7 +226,7 @@ begin
end; end;
end; end;
ensureNoPipeIfWait(fProcess); ensureNoPipeIfWait(fProcess);
//
if fProcess.Executable.fileExists then if fProcess.Executable.fileExists then
begin begin
fProcess.Execute; fProcess.Execute;
@ -242,8 +240,6 @@ begin
fProcess.CloseInput; fProcess.CloseInput;
end; end;
end; end;
//
SetCurrentDirUTF8(old);
end; end;
procedure TToolItem.processOutput(sender: TObject); procedure TToolItem.processOutput(sender: TObject);