added simpleCOmmands to ce proj format + improve UTF8 compat

This commit is contained in:
Basile Burg 2016-01-25 03:48:13 +01:00
parent cfd3e788ef
commit 097875dd59
4 changed files with 85 additions and 41 deletions

View File

@ -257,17 +257,20 @@ type
fOptions: TProcessOptions; fOptions: TProcessOptions;
fParameters: TStringList; fParameters: TStringList;
fShowWin: TShowWindowOptions; fShowWin: TShowWindowOptions;
fCommands: TStringList;
procedure setExecutable(const aValue: TCEFilename); procedure setExecutable(const aValue: TCEFilename);
procedure setWorkDir(const aValue: TCEPathname); procedure setWorkDir(const aValue: TCEPathname);
procedure setOptions(const aValue: TProcessOptions); procedure setOptions(const aValue: TProcessOptions);
procedure setParameters(aValue: TStringList); procedure setParameters(aValue: TStringList);
procedure setShowWin(const aValue: TShowWindowOptions); procedure setShowWin(const aValue: TShowWindowOptions);
procedure setCommands(aValue: TStringList);
protected protected
property executable: TCEFilename read fExecutable write setExecutable; property executable: TCEFilename read fExecutable write setExecutable;
property workingDirectory: TCEPathname read fWorkDir write setWorkDir; property workingDirectory: TCEPathname read fWorkDir write setWorkDir;
property options: TProcessOptions read fOptions write setOptions default []; property options: TProcessOptions read fOptions write setOptions default [];
property parameters: TStringList read fParameters write setParameters; property parameters: TStringList read fParameters write setParameters;
property showWindow: TShowWindowOptions read fShowWin write setShowWin default swoNone; property showWindow: TShowWindowOptions read fShowWin write setShowWin default swoNone;
property simpleCommands: TStringList read fCommands write setCommands;
public public
constructor create; constructor create;
destructor destroy; override; destructor destroy; override;
@ -292,6 +295,7 @@ type
property options default []; property options default [];
property parameters; property parameters;
property showWindow default swoNone; property showWindow default swoNone;
property simpleCommands;
end; end;
(***************************************************************************** (*****************************************************************************
@ -1167,11 +1171,13 @@ end;
constructor TCustomProcOptions.create; constructor TCustomProcOptions.create;
begin begin
fParameters := TStringList.Create; fParameters := TStringList.Create;
fCommands := TStringList.Create;
end; end;
destructor TCustomProcOptions.destroy; destructor TCustomProcOptions.destroy;
begin begin
fParameters.Free; fParameters.Free;
fCommands.Free;
inherited; inherited;
end; end;
@ -1267,6 +1273,12 @@ begin
doChanged; doChanged;
end; end;
procedure TCustomProcOptions.setCommands(aValue: TStringList);
begin
fCommands.Assign(aValue);
doChanged;
end;
procedure TCustomProcOptions.setShowWin(const aValue: TShowWindowOptions); procedure TCustomProcOptions.setShowWin(const aValue: TShowWindowOptions);
begin begin
if fShowWin = aValue then exit; if fShowWin = aValue then exit;

View File

@ -283,7 +283,7 @@ var
fname: string; fname: string;
begin begin
fname := aFilename; fname := aFilename;
if fileExists(fname) then if fname.fileExists then
fname := ExtractRelativepath(fBasePath, fname); fname := ExtractRelativepath(fBasePath, fname);
result := fSrcs.IndexOf(fname) <> -1; result := fSrcs.IndexOf(fname) <> -1;
end; end;
@ -303,7 +303,7 @@ var
fname: string; fname: string;
begin begin
fname := fSrcs.Strings[index]; fname := fSrcs.Strings[index];
if FileExists(fname) then if fname.fileExists then
result := fname result := fname
else else
result := expandFilenameEx(fBasePath, fname); result := expandFilenameEx(fBasePath, fname);
@ -373,7 +373,7 @@ var
msgs: ICEMessagesDisplay; msgs: ICEMessagesDisplay;
begin begin
result := false; result := false;
if not FileExists(fFilename) then if not fFilename.fileExists then
begin begin
dlgOkInfo('The DUB project must be saved before being compiled or run !'); dlgOkInfo('The DUB project must be saved before being compiled or run !');
exit; exit;
@ -824,7 +824,7 @@ begin
gdc: DubCompilerFilename := exeFullName('gdc' + exeExt); gdc: DubCompilerFilename := exeFullName('gdc' + exeExt);
ldc: DubCompilerFilename := exeFullName('ldc2' + exeExt); ldc: DubCompilerFilename := exeFullName('ldc2' + exeExt);
end; end;
if (not fileExists(DubCompilerFilename)) or DubCompilerFilename.isEmpty then if (not DubCompilerFilename.fileExists) or DubCompilerFilename.isEmpty then
begin begin
value := dmd; value := dmd;
DubCompilerFilename:= 'dmd' + exeExt; DubCompilerFilename:= 'dmd' + exeExt;

View File

@ -12,7 +12,7 @@ uses
ce_dialogs, ce_dialogs,
{$ENDIF} {$ENDIF}
Classes, SysUtils, process, strUtils, ce_common, ce_writableComponent, Classes, SysUtils, process, strUtils, ce_common, ce_writableComponent,
ce_dmdwrap, ce_observer, ce_interfaces, ce_processes; ce_dmdwrap, ce_observer, ce_interfaces, ce_processes, LazFileUtils;
type type
@ -131,7 +131,7 @@ constructor TCENativeProject.create(aOwner: TComponent);
begin begin
inherited create(aOwner); inherited create(aOwner);
// //
fRunnerOldCwd := GetCurrentDir; fRunnerOldCwd := GetCurrentDirUTF8;
fProjectSubject := TCEProjectSubject.create; fProjectSubject := TCEProjectSubject.create;
// //
fLibAliases := TStringList.Create; fLibAliases := TStringList.Create;
@ -400,7 +400,7 @@ begin
begin begin
str := symbolExpander.get(currentConfiguration.pathsOptions.exclusions.Strings[i]); str := symbolExpander.get(currentConfiguration.pathsOptions.exclusions.Strings[i]);
rel := expandFilenameEx(fBasePath, currentConfiguration.pathsOptions.exclusions.Strings[i]); rel := expandFilenameEx(fBasePath, currentConfiguration.pathsOptions.exclusions.Strings[i]);
if fileExists(str) then if str.fileExists then
ex_files.Add(str) ex_files.Add(str)
else if str.dirExists then else if str.dirExists then
ex_folds.Add(str); ex_folds.Add(str);
@ -482,7 +482,7 @@ var
if fSrcs.Count = 0 then exit; if fSrcs.Count = 0 then exit;
allMissing := true; allMissing := true;
for i:= 0 to fSrcs.Count-1 do for i:= 0 to fSrcs.Count-1 do
if fileExists(sourceAbsolute(i)) then if sourceAbsolute(i).fileExists then
allMissing := false; allMissing := false;
if not allMissing then exit; if not allMissing then exit;
if dlgOkCancel( 'The project source(s) are all missing. ' + LineEnding + if dlgOkCancel( 'The project source(s) are all missing. ' + LineEnding +
@ -516,7 +516,7 @@ var
for i:= fSrcs.Count-1 downto 0 do for i:= fSrcs.Count-1 downto 0 do
begin begin
oldsrc := sourceAbsolute(i); oldsrc := sourceAbsolute(i);
if fileExists(oldsrc) then continue; if oldsrc.fileExists then continue;
if dlgOkCancel(format('a particular project source file ("%s") is missing. ' if dlgOkCancel(format('a particular project source file ("%s") is missing. '
+ LineEnding + 'This happends if a source file has been moved, renamed ' + + LineEnding + 'This happends if a source file has been moved, renamed ' +
'or deleted.' + LineEnding + LineEnding + 'or deleted.' + LineEnding + LineEnding +
@ -642,41 +642,69 @@ begin
// //
fCanBeRun := false; fCanBeRun := false;
if currentConfiguration.outputOptions.binaryKind = executable then if currentConfiguration.outputOptions.binaryKind = executable then
fCanBeRun := fileExists(fOutputFilename); fCanBeRun := fOutputFilename.fileExists;
end; end;
function TCENativeProject.runPrePostProcess(const processInfo: TCompileProcOptions): Boolean; function TCENativeProject.runPrePostProcess(const processInfo: TCompileProcOptions): Boolean;
var var
process: TProcess; lst: TStringList;
com: boolean;
proc: TProcess;
pname: string; pname: string;
i, j: integer; i, j: integer;
begin begin
//
for i := 0 to processInfo.simpleCommands.Count-1 do
begin
pname := symbolExpander.get(processInfo.simpleCommands.Strings[i]);
proc := TProcess.Create(nil);
lst := TStringList.Create;
try
CommandToList(pname, lst);
proc.Executable := lst.Strings[0];
proc.Options:= [poUsePipes, poStderrToOutPut];
lst.Delete(0);
proc.Parameters.Assign(lst);
proc.Execute;
com := proc.ExitCode = 0;
lst.Clear;
ce_common.processOutputToStrings(proc, lst);
for j := 0 to lst.Count -1 do
getMessageDisplay.message(lst.Strings[j], self as ICECommonProject, amcProj, amkAuto);
finally
proc.Free;
lst.Free;
end;
if not com then
exit(false);
end;
//
pname := symbolExpander.get(processInfo.executable); pname := symbolExpander.get(processInfo.executable);
if (not exeInSysPath(pname)) and pname.isNotEmpty then if (not exeInSysPath(pname)) and pname.isNotEmpty then
exit(false) exit(false)
else if pname.isEmpty then else if pname.isEmpty then
exit(true); exit(true);
// //
process := TProcess.Create(nil); proc := TProcess.Create(nil);
try try
processInfo.setProcess(process); processInfo.setProcess(proc);
process.Executable := exeFullName(pname); proc.Executable := exeFullName(pname);
j := process.Parameters.Count-1; j := proc.Parameters.Count-1;
for i:= 0 to j do for i:= 0 to j do
process.Parameters.AddText(symbolExpander.get(process.Parameters.Strings[i])); proc.Parameters.AddText(symbolExpander.get(proc.Parameters.Strings[i]));
for i:= 0 to j do for i:= 0 to j do
process.Parameters.Delete(0); proc.Parameters.Delete(0);
if process.CurrentDirectory.isNotEmpty then if proc.CurrentDirectory.isNotEmpty then
process.CurrentDirectory := symbolExpander.get(process.CurrentDirectory); proc.CurrentDirectory := symbolExpander.get(proc.CurrentDirectory);
// else cwd is set to project dir in compile() // else cwd is set to project dir in compile()
ensureNoPipeIfWait(process); ensureNoPipeIfWait(proc);
process.Execute; proc.Execute;
while process.Running do while proc.Running do
if poUsePipes in process.Options then if poUsePipes in proc.Options then
runProcOutput(process); runProcOutput(proc);
finally finally
result := process.ExitStatus = 0; result := proc.ExitStatus = 0;
process.Free; proc.Free;
end; end;
end; end;
@ -702,17 +730,17 @@ begin
subjProjCompiling(fProjectSubject, Self); subjProjCompiling(fProjectSubject, Self);
// //
prjpath := fFileName.extractFilePath; prjpath := fFileName.extractFilePath;
oldCwd := GetCurrentDir; oldCwd := GetCurrentDirUTF8;
SetCurrentDir(prjpath); SetCurrentDirUTF8(prjpath);
// //
if not runPrePostProcess(config.preBuildProcess) then if not runPrePostProcess(config.preBuildProcess) then
msgs.message('project warning: the pre-compilation process has not been properly executed', msgs.message('warning: pre-compilation process or commands not properly executed',
self as ICECommonProject, amcProj, amkWarn); self as ICECommonProject, amcProj, amkWarn);
SetCurrentDir(prjpath); SetCurrentDirUTF8(prjpath);
// //
if (Sources.Count = 0) and (config.pathsOptions.extraSources.Count = 0) then if (Sources.Count = 0) and (config.pathsOptions.extraSources.Count = 0) then
begin begin
SetCurrentDir(oldCwd); SetCurrentDirUTF8(oldCwd);
exit; exit;
end; end;
// //
@ -745,12 +773,12 @@ begin
updateOutFilename; updateOutFilename;
compilproc.Free; compilproc.Free;
end; end;
SetCurrentDir(prjpath); SetCurrentDirUTF8(prjpath);
// //
if not runPrePostProcess(config.PostBuildProcess) then if not runPrePostProcess(config.PostBuildProcess) then
msgs.message( 'project warning: the post-compilation process has not been properly executed', msgs.message( 'warning: post-compilation process or commands not properly executed',
self as ICECommonProject, amcProj, amkWarn); self as ICECommonProject, amcProj, amkWarn);
SetCurrentDir(oldCwd); SetCurrentDirUTF8(oldCwd);
end; end;
function TCENativeProject.run(const runArgs: string = ''): Boolean; function TCENativeProject.run(const runArgs: string = ''): Boolean;
@ -778,7 +806,7 @@ begin
until prm = ''; until prm = '';
end; end;
// //
if not fileExists(outputFilename) then if not outputFilename.fileExists then
begin begin
getMessageDisplay.message('output executable missing: ' + shortenPath(outputFilename, 25), getMessageDisplay.message('output executable missing: ' + shortenPath(outputFilename, 25),
self as ICECommonProject, amcProj, amkErr); self as ICECommonProject, amcProj, amkErr);
@ -788,7 +816,7 @@ begin
fRunner.Executable := outputFilename; fRunner.Executable := outputFilename;
if fRunner.CurrentDirectory.isEmpty then if fRunner.CurrentDirectory.isEmpty then
begin begin
fRunnerOldCwd := GetCurrentDir; fRunnerOldCwd := GetCurrentDirUTF8;
cwd := fRunner.Executable.extractFilePath; cwd := fRunner.Executable.extractFilePath;
chDir(cwd); chDir(cwd);
fRunner.CurrentDirectory := cwd; fRunner.CurrentDirectory := cwd;
@ -858,7 +886,7 @@ var
i: integer; i: integer;
begin begin
result := false; result := false;
if not FileExists(fOutputFilename) then exit; if not fOutputFilename.fileExists then exit;
dt := FileAge(fOutputFilename); dt := FileAge(fOutputFilename);
for i := 0 to fSrcs.Count-1 do for i := 0 to fSrcs.Count-1 do
if fileAge(sourceAbsolute(i)) > dt then exit; if fileAge(sourceAbsolute(i)) > dt then exit;
@ -941,7 +969,7 @@ var
fname: string; fname: string;
begin begin
fname := fSrcs.Strings[index]; fname := fSrcs.Strings[index];
if FileExists(fname) then if fname.fileExists then
result := fname result := fname
else else
result := expandFilenameEx(fBasePath, fname); result := expandFilenameEx(fBasePath, fname);
@ -990,7 +1018,7 @@ begin
gdc: NativeProjectCompilerFilename := exeFullName('cegdcldc' + exeExt); gdc: NativeProjectCompilerFilename := exeFullName('cegdcldc' + exeExt);
ldc: NativeProjectCompilerFilename := exeFullName('ldmd2' + exeExt); ldc: NativeProjectCompilerFilename := exeFullName('ldmd2' + exeExt);
end; end;
if (not fileExists(NativeProjectCompilerFilename)) if (not NativeProjectCompilerFilename.fileExists)
or NativeProjectCompilerFilename.isEmpty then or NativeProjectCompilerFilename.isEmpty then
begin begin
value := dmd; value := dmd;

View File

@ -191,12 +191,14 @@ procedure TCEToolItem.execute(previous: TCEToolItem);
var var
prm: string; prm: string;
inp: string; inp: string;
old: string;
begin begin
ce_processes.killProcess(fProcess); ce_processes.killProcess(fProcess);
// //
if fClearMessages then if fClearMessages then
getMessageDisplay(fMsgs).clearByContext(amcMisc); getMessageDisplay(fMsgs).clearByContext(amcMisc);
// //
old := GetCurrentDirUTF8;
fProcess := TCEProcess.Create(nil); fProcess := TCEProcess.Create(nil);
fProcess.OnReadData:= @processOutput; fProcess.OnReadData:= @processOutput;
fProcess.OnTerminate:= @processOutput; fProcess.OnTerminate:= @processOutput;
@ -214,7 +216,7 @@ begin
end; end;
ensureNoPipeIfWait(fProcess); ensureNoPipeIfWait(fProcess);
// //
if FileExists(fProcess.Executable) then if fProcess.Executable.fileExists then
begin begin
fProcess.Execute; fProcess.Execute;
if previous.isNotNil and previous.outputToNext if previous.isNotNil and previous.outputToNext
@ -227,6 +229,8 @@ begin
fProcess.CloseInput; fProcess.CloseInput;
end; end;
end; end;
//
SetCurrentDirUTF8(old);
end; end;
procedure TCEToolItem.processOutput(sender: TObject); procedure TCEToolItem.processOutput(sender: TObject);