From 2c5ad59d63c5ba97acafd4980f8b95a1b54fcecb Mon Sep 17 00:00:00 2001 From: ketmar Date: Tue, 26 Aug 2014 08:30:39 +0300 Subject: [PATCH] better(?) "-I." and "-J." --- rgdc.d | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/rgdc.d b/rgdc.d index cd71896..c9a778a 100644 --- a/rgdc.d +++ b/rgdc.d @@ -230,8 +230,8 @@ private int rebuild (string root, string fullExe, auto todo = compilerFlags~ ["-o", outExe]~ - ["-I"~dirName(root)]~ - ["-J"~dirName(root)]~ + //["-I"~dirName(root)]~ + //["-J"~dirName(root)]~ includeDirs~ importDirs/*~ [root]*/; @@ -451,8 +451,8 @@ private string[string] getDependencies (string rootModule, string workDir, strin "-o", "/dev/null", "-fdeps="~depsFilename, rootModule, - "-I"~rootDir, - "-J"~rootDir + //"-I"~rootDir, + //"-J"~rootDir ]~includeDirs~importDirs; scope(failure) { @@ -591,7 +591,7 @@ private size_t indexOfProgram (string[] args) { int main(string[] args) { - string[] convertSomeOptions (string[] args) { + string[] convertSomeOptions (string[] args, string root) { string[string] simpleReplace; simpleReplace["-unittest"] = "-funittest"; simpleReplace["-main"] = "--main"; @@ -599,10 +599,17 @@ int main(string[] args) { simpleReplace["-boundscheck=off"] = "-fno-bounds-check"; simpleReplace["-boundscheck=on"] = "-fbounds-check"; + bool hasIDot, hasJDot; + int idxI = -1, idxJ = -1; + string rootDir = root.dirName.buildNormalizedPath; + if (rootDir.length == 0) rootDir ~= "."; + string ourI = "-I"~rootDir; + string ourJ = "-J"~rootDir; + debug writeln("before: ", args); string[] res; res ~= args[0]; - foreach (arg; args[1..$]) { + foreach (int i, arg; args[1..$]) { auto sr = arg in simpleReplace; if (sr !is null) { res ~= *sr; continue; } if (arg.startsWith("-debug") || @@ -611,9 +618,21 @@ int main(string[] args) { continue; } if (arg == "-inline") { res ~= ["-finline-small-functions", "-finline-functions"]; continue; } + if (arg == ourI) hasIDot = true; + else if (arg == ourJ) hasJDot = true; + if (idxI < 0 && arg.startsWith("-I")) idxI = i; + else if (idxJ < 0 && arg.startsWith("-J")) idxJ = i; res ~= arg; } if (!res.canFind("-g") && !res.canFind("-s")) res = res~"-s"; + if (!hasIDot) { + if (idxI < 0) idxI = res.length; + res = res[0..idxI]~[ourI]~res[idxI..$]; + } + if (!hasJDot) { + if (idxJ < 0) idxJ = res.length; + res = res[0..idxJ]~[ourJ]~res[idxJ..$]; + } debug writeln("after: ", res); return res; } @@ -628,7 +647,7 @@ int main(string[] args) { // Continue parsing the command line; now get rgdc's own arguments auto programPos = indexOfProgram(args); assert(programPos > 0); - auto argsBeforeProgram = convertSomeOptions(args[0..programPos]); + auto argsBeforeProgram = convertSomeOptions(args[0..programPos], (programPos < args.length ? args[programPos] : null)); bool bailout; // bailout set by functions called in getopt if program should exit bool addStubMain; // set by --main @@ -665,6 +684,7 @@ int main(string[] args) { assert(argsBeforeProgram.length >= 1); auto compilerFlags = argsBeforeProgram[1..$]; + //TODO bool lib = compilerFlags.canFind("-lib"); string outExt = (lib ? libExt : binExt); -- 2.11.4.GIT