Skip to content

Commit

Permalink
Fix Issue 14296 - RDMD fails at building a lib when the source is in …
Browse files Browse the repository at this point in the history
…a subdir
  • Loading branch information
CyberShadow committed Dec 17, 2016
1 parent ea3c967 commit e245e29
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
13 changes: 8 additions & 5 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ int main(string[] args)

if (lib)
{
// When building libraries, DMD does not generate object files.
// Instead, it uses the -od parameter as the location for the library file.
// Thus, override objDir (which is normally a temporary directory)
// to be the target output directory.
objDir = exe.dirName;
// When using -lib, the behavior of the DMD -of switch
// changes: instead of being relative to the current
// directory, it becomes relative to the output directory.
// When building libraries, DMD does not generate any object
// files; thus, we can override objDir (which is normally a
// temporary directory) to be the current directory, so that
// the relative -of path becomes correct.
objDir = ".";
}

// Fetch dependencies
Expand Down
40 changes: 40 additions & 0 deletions rdmd_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ version (Posix)
{
enum objExt = ".o";
enum binExt = "";
enum libExt = ".a";
}
else version (Windows)
{
enum objExt = ".obj";
enum binExt = ".exe";
enum libExt = ".lib";
}
else
{
Expand Down Expand Up @@ -385,6 +387,44 @@ void runTests()
assert(res.status == 0, res.output);
assert(res.output.canFind("compile_force_src"));
}

/* RDMD fails at building a lib when the source is in a subdir: https://issues.dlang.org/show_bug.cgi?id=14296 */
{
TmpDir srcDir = "rdmdTest";
string srcName = srcDir.buildPath("test.d");
std.file.write(srcName, `void fun() {}`);

res = execute([rdmdApp, compilerSwitch, "--build-only", "--force", "-lib", srcName]);
assert(res.status == 0, res.output);
assert(exists(srcDir.buildPath("test" ~ libExt)));
}

// Test with -od
{
TmpDir srcDir = "rdmdTestSrc";
TmpDir libDir = "rdmdTestLib";

string srcName = srcDir.buildPath("test.d");
std.file.write(srcName, `void fun() {}`);

res = execute([rdmdApp, compilerSwitch, "--build-only", "--force", "-lib", "-od" ~ libDir, srcName]);
assert(res.status == 0, res.output);
assert(exists(libDir.buildPath("test" ~ libExt)));
}

// Test with -of
{
TmpDir srcDir = "rdmdTestSrc";
TmpDir libDir = "rdmdTestLib";

string srcName = srcDir.buildPath("test.d");
std.file.write(srcName, `void fun() {}`);
string libName = libDir.buildPath("libtest" ~ libExt);

res = execute([rdmdApp, compilerSwitch, "--build-only", "--force", "-lib", "-of" ~ libName, srcName]);
assert(res.status == 0, res.output);
assert(exists(libName));
}
}

void runConcurrencyTest()
Expand Down

0 comments on commit e245e29

Please sign in to comment.