diff --git a/lazproj/test/coeditproj/cleaner.coedit b/lazproj/test/coeditproj/cleaner.coedit new file mode 100644 index 00000000..07ff3ab0 --- /dev/null +++ b/lazproj/test/coeditproj/cleaner.coedit @@ -0,0 +1,30 @@ +object CurrentProject: TCEProject + OptionsCollection = < + item + name = 'release' + outputOptions.inlining = True + outputOptions.noBoundsCheck = False + outputOptions.boundsCheck = offAlways + outputOptions.optimizations = True + outputOptions.release = True + pathsOptions.outputFilename = '..\..\cleaner.exe' + preBuildProcess.options = [] + preBuildProcess.showWindow = swoNone + postBuildProcess.executable = 'cleaner.exe' + postBuildProcess.options = [poUsePipes, poStderrToOutPut] + postBuildProcess.parameters.Strings = ( + '-r' + '-f' + '' + '-e' + '.tmp,.res' + ) + postBuildProcess.showWindow = swoHIDE + runOptions.options = [] + runOptions.showWindow = swoNone + end> + Sources.Strings = ( + '..\src\cleaner.d' + ) + ConfigurationIndex = 0 +end diff --git a/lazproj/test/src/cleaner.d b/lazproj/test/src/cleaner.d new file mode 100644 index 00000000..1d395d72 --- /dev/null +++ b/lazproj/test/src/cleaner.d @@ -0,0 +1,65 @@ +module cleaner; + +import std.stdio; +import std.path; +import std.file; +import std.getopt; +import std.array; + +//as a runnable: -f "dir" -r -e ".ext1,.ext2" + +/* +as a post-build process, parameter list: +-f +pathtoclean (w/o dbl quotes) +-r +-e +.a,.b,.c +*/ +void main(string args[]) +{ + bool recursive; + string root; + string userexts; + string exts[]; + + exts ~= [".obj", ".o"]; + + getopt(args, config.passThrough, + "f|from", &root, + "r|recursive", &recursive, + "e|ext", &userexts + ); + + if (!exists(root) || root.length == 0) + return; + + if (userexts.length != 0) + { + auto itms = split(userexts, ','); + foreach(itm; itms) + if (itm.length > 1 && itm[0] == '.') + exts ~= itm; + } + + void clean(in string currroot) + { + DirIterator entries = dirEntries(currroot, SpanMode.shallow); + + foreach(entry; entries) + { + scope(failure){} + + if (!isDir(entry)) + { + foreach(trg_ext; exts) + if (entry.extension == trg_ext) + std.file.remove(entry); + } + else if (recursive) + clean(entry); + } + } + + clean(root); +} diff --git a/src/ce_common.pas b/src/ce_common.pas index 49dd64e1..adc4d611 100644 --- a/src/ce_common.pas +++ b/src/ce_common.pas @@ -646,7 +646,10 @@ begin ext := extractFileExt(anExeName); if ext <> exeExt then anExeName += exeExt; - exit(ExeSearch(anExeName, '') <> ''); + if FileExists(anExeName) then + exit(true) + else + exit(ExeSearch(anExeName, '') <> ''); end; initialization diff --git a/src/ce_main.pas b/src/ce_main.pas index eed86963..a44277f1 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -1259,7 +1259,7 @@ procedure TCEMainForm.compileProject(const aProject: TCEProject); var dmdproc: TProcess; ppproc: TProcess; - olddir, prjpath: string; + olddir, prjpath, ppname: string; i: NativeInt; begin @@ -1267,12 +1267,14 @@ begin with fProject.currentConfiguration do begin - if preBuildProcess.executable <> '' then - if exeInSysPath(preBuildProcess.executable) then + ppname := expandSymbolicString(preBuildProcess.executable); + if ppname <> '``' then + if exeInSysPath(ppname) then begin ppproc := TProcess.Create(nil); try preBuildProcess.setProcess(ppproc); + ppproc.Executable := ppname; for i:= 0 to ppproc.Parameters.Count-1 do ppproc.Parameters.Strings[i] := expandSymbolicString(ppproc.Parameters.Strings[i]); if ppproc.CurrentDirectory = '' then @@ -1324,12 +1326,14 @@ begin with fProject.currentConfiguration do begin - if postBuildProcess.executable <> '' then - if exeInSysPath(postBuildProcess.executable) then + ppname := expandSymbolicString(postBuildProcess.executable); + if ppname <> '``' then + if exeInSysPath(ppname) then begin ppproc := TProcess.Create(nil); try postBuildProcess.setProcess(ppproc); + ppproc.Executable := ppname; for i:= 0 to ppproc.Parameters.Count-1 do ppproc.Parameters.Strings[i] := expandSymbolicString(ppproc.Parameters.Strings[i]); if ppproc.CurrentDirectory = '' then