Skip to content

Commit

Permalink
Fix issue 12351: rdmd --makedep(end|file) uses the source file as the…
Browse files Browse the repository at this point in the history
… target

Having the source file as the target for the dependencies on a Makefile
is useless, as there is no rule to rebuild the source file, Make can't
use that information at all.

To a have a meaningful target name, now --makedep* options require -of
to be present too.
  • Loading branch information
leandro-lucarella-sociomantic committed Mar 19, 2014
1 parent e41a32b commit 12e73a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 21 additions & 4 deletions rdmd.d
Original file line number Diff line number Diff line change
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,9 +315,9 @@ 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.write(exe, " : ", root);
foreach (mod, _; myDeps)
{
fo.write(' ', mod);
Expand Down Expand Up @@ -753,7 +768,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
13 changes: 9 additions & 4 deletions rdmd_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ 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.canFind("depMod_ : "));
assert(res.output.canFind("depMod_.d"));
assert(res.output.replace(r"\", "/").canFind("dsubpack/submod.d"));

/* Test --makedepfile. */
Expand All @@ -212,12 +214,15 @@ void runTests()
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.canFind("depModFail_ : "));
assert(output.canFind("depModFail_.d"));
assert(output.replace(r"\", "/").canFind("dsubpack/submod.d"));
assert(res.status == 0, res.output); // only built, assert(0) not called.

Expand Down

0 comments on commit 12e73a2

Please sign in to comment.