Skip to content

Commit

Permalink
Merge pull request #204 from aG0aep6G/16966
Browse files Browse the repository at this point in the history
fix issue 16966 - rdmd: AssertError@rdmd.d(489): should have been cre…
  • Loading branch information
andralex committed Dec 22, 2016
2 parents 184f5e6 + 2026a50 commit 3353e63
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 33 deletions.
77 changes: 44 additions & 33 deletions rdmd.d
Expand Up @@ -243,26 +243,6 @@ int main(string[] args)
objDir = exe.dirName;
}

// Fetch dependencies
const myDeps = compileRootAndGetDeps(root, workDir, objDir, compilerFlags,
addStubMain);

// --makedepend mode. Just print dependencies and exit.
if (makeDepend)
{
writeDeps(exe, root, myDeps, stdout);
return 0;
}

// --makedepfile mode. Print dependencies to a file and continue.
// This is similar to GCC's -MF option, very useful to update the
// dependencies file and compile in one go:
// -include .deps.mak
// prog:
// rdmd --makedepfile=.deps.mak --build-only prog.d
if (makeDepFile !is null)
writeDeps(exe, root, myDeps, File(makeDepFile, "w"));

// Compute executable name, check for freshness, rebuild
/*
We need to be careful about using -o. Normally the generated
Expand Down Expand Up @@ -299,6 +279,26 @@ int main(string[] args)
lastBuildTime = buildWitness.timeLastModified(SysTime.min);
}

// Fetch dependencies
const myDeps = compileRootAndGetDeps(root, workDir, objDir, compilerFlags,
addStubMain, lastBuildTime);

// --makedepend mode. Just print dependencies and exit.
if (makeDepend)
{
writeDeps(exe, root, myDeps, stdout);
return 0;
}

// --makedepfile mode. Print dependencies to a file and continue.
// This is similar to GCC's -MF option, very useful to update the
// dependencies file and compile in one go:
// -include .deps.mak
// prog:
// rdmd --makedepfile=.deps.mak --build-only prog.d
if (makeDepFile !is null)
writeDeps(exe, root, myDeps, File(makeDepFile, "w"));

// Have at it
if (chain(root.only, myDeps.byKey).anyNewerThan(lastBuildTime))
{
Expand Down Expand Up @@ -563,7 +563,7 @@ private int rebuild(string root, string fullExe,
// Run a program optionally writing the command line first
// If "replace" is true and the OS supports it, replace the current process.

private int run(string[] args, string output = null, bool replace = false)
private int run(const string[] args, string output = null, bool replace = false)
{
import std.conv;
yap(replace ? "exec " : "spawn ", args.text);
Expand Down Expand Up @@ -601,10 +601,10 @@ private int exec(string[] args)
// rootModule.

private string[string] compileRootAndGetDeps(string rootModule, string workDir,
string objDir, string[] compilerFlags, bool addStubMain)
string objDir, string[] compilerFlags, bool addStubMain,
SysTime lastBuildTime)
{
immutable depsFilename = buildPath(workDir, "rdmd.deps");

string[string] readDepsFile()
{
string d2obj(string dfile)
Expand Down Expand Up @@ -695,6 +695,14 @@ private string[string] compileRootAndGetDeps(string rootModule, string workDir,
return result;
}

immutable rootDir = dirName(rootModule);
const compileCmd = [ compiler ] ~ compilerFlags ~ [
"-c",
"-of" ~ buildPath(objDir, rootModule.baseName(".d") ~ objExt),
rootModule,
"-I" ~ rootDir
];

// Check if the old dependency file is fine
if (!force)
{
Expand All @@ -708,23 +716,26 @@ private string[string] compileRootAndGetDeps(string rootModule, string workDir,
bool mustRebuildDeps = allDeps.anyNewerThan(depsT);
if (!mustRebuildDeps)
{
// Cool, we're in good shape
/* Cool, we're in good shape. Don't need to read dependencies.
Still may have to compile the root module. This can happen
when the user deletes the executable. */
if (lastBuildTime < depsT)
{
immutable exitCode = run(compileCmd);
if (exitCode)
{
stderr.writefln("Failed: %s", compileCmd);
exit(exitCode);
}
}
return deps;
}
// Fall through to rebuilding the deps file
}
}

immutable rootDir = dirName(rootModule);

// Collect dependencies
auto depsGetter = [ compiler ] ~ compilerFlags ~ [
"-v",
"-c",
"-of" ~ buildPath(objDir, rootModule.baseName(".d") ~ objExt),
rootModule,
"-I" ~ rootDir
];
auto depsGetter = compileCmd ~ "-v";

// Need to add void main(){}?
if (addStubMain)
Expand Down
10 changes: 10 additions & 0 deletions rdmd_test.d
Expand Up @@ -373,6 +373,16 @@ void runTests()
res = execute([rdmdApp, compilerSwitch, "--tmpdir=" ~ tmpdir, forceSrc, "--build-only"]);
assert(res.status == 0, res.output);
assert(res.output.canFind("compile_force_src"));

/* issue 16966 */
immutable voidMainExe = setExtension(voidMain, binExt);
res = execute([rdmdApp, compilerSwitch, voidMain]);
assert(res.status == 0, res.output);
assert(!exists(voidMainExe));
res = execute([rdmdApp, compilerSwitch, "--build-only", voidMain]);
assert(res.status == 0, res.output);
assert(exists(voidMainExe));
remove(voidMainExe);
}

void runConcurrencyTest()
Expand Down

0 comments on commit 3353e63

Please sign in to comment.