Skip to content

Commit

Permalink
Merge pull request #122 from leandro-lucarella-sociomantic/rdmd-exe-t…
Browse files Browse the repository at this point in the history
…arget

Fix  rdmd --makedep(end|file) (issues 12351 and 12354)
  • Loading branch information
andralex committed Mar 19, 2014
2 parents e41a32b + 07553e1 commit 09aaa09
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
34 changes: 29 additions & 5 deletions rdmd.d
Expand Up @@ -139,6 +139,21 @@ int main(string[] args)
if (bailout) return 0;
if (dryRun) chatty = true; // dry-run implies chatty

/* Only -of is supported because Make is very susceptible to file names, and
* it doesn't do a good job resolving them. One option would be to use
* std.path.buildNormalizedPath(), but some corner cases will break, so it
* has been decided to only allow -of for now.
* To see the full discussion please refer to:
* https://github.com/D-Programming-Language/tools/pull/122
*/
if ((makeDepend || makeDepFile) && (!exe || exe.endsWith(dirSeparator)))
{
stderr.write(helpString);
stderr.writeln();
stderr.writeln("Missing option: --makedepend and --makedepfile need -of");
return 1;
}

if (preserveOutputPaths)
{
argsBeforeProgram = argsBeforeProgram[0] ~ ["-op"] ~ argsBeforeProgram[1 .. $];
Expand Down Expand Up @@ -210,7 +225,7 @@ int main(string[] args)
// --makedepend mode. Just print dependencies and exit.
if (makeDepend)
{
writeDeps(root, myDeps, stdout);
writeDeps(exe, root, myDeps, stdout);
return 0;
}

Expand All @@ -221,7 +236,7 @@ int main(string[] args)
// prog:
// rdmd --makedepfile=.deps.mak --build-only prog.d
if (makeDepFile !is null)
writeDeps(root, myDeps, File(makeDepFile, "w"));
writeDeps(exe, root, myDeps, File(makeDepFile, "w"));

// Compute executable name, check for freshness, rebuild
/*
Expand Down Expand Up @@ -300,14 +315,21 @@ size_t indexOfProgram(string[] args)
return args.length;
}

void writeDeps(string root, in string[string] myDeps, File fo)
void writeDeps(string exe, string root, in string[string] myDeps, File fo)
{
fo.write(root, " :");
fo.writeln(exe, r": \");
fo.writeln(" ", root, r" \");
foreach (mod, _; myDeps)
{
fo.write(' ', mod);
fo.writeln(" ", mod, r" \");
}
fo.writeln();
fo.writeln(root, ":");
foreach (mod, _; myDeps)
{
fo.writeln();
fo.writeln(mod, ":");
}
}

bool inALibrary(string source, string object)
Expand Down Expand Up @@ -753,7 +775,9 @@ addition to compiler options, rdmd recognizes the following options:
--loop assume \"foreach (line; stdin.byLine()) { ... }\" for eval
--main add a stub main program to the mix (e.g. for unittesting)
--makedepend print dependencies in makefile format and exit
(needs dmd's option `-of` to be present)
--makedepfile=file print dependencies in makefile format to file and continue
(needs dmd's option `-of` to be present)
--man open web browser on manual page
--shebang rdmd is in a shebang line (put as first argument)
".format(defaultCompiler);
Expand Down
19 changes: 13 additions & 6 deletions rdmd_test.d
Expand Up @@ -201,24 +201,31 @@ void runTests()
string depMod = packRoot.buildPath("depMod_.d");
std.file.write(depMod, "module depMod_; import dsubpack.submod; void main() { }");

res = execute([rdmdApp, compilerSwitch, "-I" ~ packRoot, "--makedepend", depMod]);
res = execute([rdmdApp, compilerSwitch, "-I" ~ packRoot, "--makedepend",
"-of" ~ depMod[0..$-2], depMod]);
// simplistic checks
assert(res.output.canFind("depMod_.d : "));
assert(res.output.replace(r"\", "/").canFind("dsubpack/submod.d"));
assert(res.output.canFind(depMod[0..$-2] ~ ": \\\n"));
assert(res.output.canFind("\n " ~ depMod ~ " \\\n"));
assert(res.output.canFind("\n " ~ subModSrc ~ " \\\n"));
assert(res.output.canFind("\n" ~ subModSrc ~ ":\n"));

/* Test --makedepfile. */

string depModFail = packRoot.buildPath("depModFail_.d");
std.file.write(depModFail, "module depMod_; import dsubpack.submod; void main() { assert(0); }");

string depMak = packRoot.buildPath("depMak_.mak");
res = execute([rdmdApp, compilerSwitch, "--force", "--build-only", "-I" ~ packRoot, "--makedepfile=" ~ depMak, depModFail]);
res = execute([rdmdApp, compilerSwitch, "--force", "--build-only",
"-I" ~ packRoot, "--makedepfile=" ~ depMak,
"-of" ~ depModFail[0..$-2], depModFail]);
scope (exit) std.file.remove(depMak);

string output = std.file.readText(depMak);
// simplistic checks
assert(output.canFind("depModFail_.d : "));
assert(output.replace(r"\", "/").canFind("dsubpack/submod.d"));
assert(output.canFind(depModFail[0..$-2] ~ ": \\\n"));
assert(output.canFind("\n " ~ depModFail ~ " \\\n"));
assert(output.canFind("\n " ~ subModSrc ~ " \\\n"));
assert(output.canFind("\n" ~ subModSrc ~ ":\n"));
assert(res.status == 0, res.output); // only built, assert(0) not called.

/* Test signal propagation through exit codes */
Expand Down

0 comments on commit 09aaa09

Please sign in to comment.