added symbolic string support to pre/post build processes name. added related example.

This commit is contained in:
Basile Burg 2014-08-25 02:35:14 +02:00
parent 5dd9f2aff4
commit 074a767438
4 changed files with 108 additions and 6 deletions

View File

@ -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 = '<CPP>..\..\cleaner.exe'
preBuildProcess.options = []
preBuildProcess.showWindow = swoNone
postBuildProcess.executable = '<CAP>cleaner.exe'
postBuildProcess.options = [poUsePipes, poStderrToOutPut]
postBuildProcess.parameters.Strings = (
'-r'
'-f'
'<CAP>'
'-e'
'.tmp,.res'
)
postBuildProcess.showWindow = swoHIDE
runOptions.options = []
runOptions.showWindow = swoNone
end>
Sources.Strings = (
'..\src\cleaner.d'
)
ConfigurationIndex = 0
end

View File

@ -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);
}

View File

@ -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

View File

@ -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