Skip to content

Commit

Permalink
fix Issue 16798 - Extend -Ipath switch to -Imodule=path so path heira…
Browse files Browse the repository at this point in the history
…rchy doesn't have to match package heirarchy
  • Loading branch information
WalterBright committed Dec 5, 2016
1 parent 46940aa commit 1e77dfa
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/dmodule.d
Expand Up @@ -417,10 +417,42 @@ extern (C++) final class Module : Package
if (packages && packages.dim)
{
OutBuffer buf;
OutBuffer dotmods;
auto ms = global.params.modFileAliasStrings;
const msdim = ms ? ms.dim : 0;

void checkModFileAlias(const(char)* p)
{
/* Check and replace the contents of buf[] with
* an alias string from global.params.modFileAliasStrings[]
*/
dotmods.writestring(p);
Lmain:
for (size_t j = msdim; j--;)
{
const m = (*ms)[j];
const q = strchr(m, '=');
assert(q);
if (dotmods.offset <= q - m && memcmp(dotmods.peekString(), m, q - m) == 0)
{
buf.reset();
auto qlen = strlen(q + 1);
if (qlen && (q[qlen] == '/' || q[qlen] == '\\'))
--qlen; // remove trailing separator
buf.writestring(q[1 .. qlen + 1]);
break Lmain; // last matching entry in ms[] wins
}
}
dotmods.writeByte('.');
}

for (size_t i = 0; i < packages.dim; i++)
{
Identifier pid = (*packages)[i];
buf.writestring(pid.toChars());
const p = pid.toChars();
buf.writestring(p);
if (msdim)
checkModFileAlias(p);
version (Windows)
{
buf.writeByte('\\');
Expand All @@ -431,6 +463,8 @@ extern (C++) final class Module : Package
}
}
buf.writestring(filename);
if (msdim)
checkModFileAlias(filename);
buf.writeByte(0);
filename = buf.extractData();
}
Expand Down
1 change: 1 addition & 0 deletions src/globals.d
Expand Up @@ -120,6 +120,7 @@ struct Param
BOUNDSCHECK useArrayBounds;

const(char)* argv0; // program name
Array!(const(char)*)* modFileAliasStrings; // array of char*'s of -I module filename alias strings
Array!(const(char)*)* imppath; // array of char*'s of where to look for import modules
Array!(const(char)*)* fileImppath; // array of char*'s of where to look for file import modules
const(char)* objdir; // .obj/.lib file output directory
Expand Down
1 change: 1 addition & 0 deletions src/globals.h
Expand Up @@ -102,6 +102,7 @@ struct Param
BOUNDSCHECK useArrayBounds;

const char *argv0; // program name
Array<const char *> *modFileAliasStrings; // array of char*'s of -I module filename alias strings
Array<const char *> *imppath; // array of char*'s of where to look for import modules
Array<const char *> *fileImppath; // array of char*'s of where to look for file import modules
const char *objdir; // .obj/.lib file output directory
Expand Down
12 changes: 12 additions & 0 deletions src/mars.d
Expand Up @@ -149,6 +149,7 @@ Where:
-map generate linker .map file
-mavx use AVX instruction set" ~
"%s" /* placeholder for mscrtlib */ ~ "
-mv=<package.module>=<filespec> use <filespec> as source file for <package.module>
-noboundscheck no array bounds checking (deprecated, use -boundscheck=off)
-O optimize
-o- do not write object file
Expand Down Expand Up @@ -794,6 +795,17 @@ Language changes listed by -transition=id:
global.params.imppath = new Strings();
global.params.imppath.push(p + 2 + (p[2] == '='));
}
else if (p[1] == 'm' && p[2] == 'v' && p[3] == '=')
{
if (p[4] && strchr(p + 5, '='))
{
if (!global.params.modFileAliasStrings)
global.params.modFileAliasStrings = new Strings();
global.params.modFileAliasStrings.push(p + 4);
}
else
goto Lerror;
}
else if (p[1] == 'J')
{
if (!global.params.fileImppath)
Expand Down
4 changes: 4 additions & 0 deletions test/compilable/imports/imp16798.d
@@ -0,0 +1,4 @@

module its.a.dessert.topping;

pragma(msg, "it's a dessert topping");
4 changes: 4 additions & 0 deletions test/compilable/imports/wax16798.d
@@ -0,0 +1,4 @@
module its.a.floorwax.wax16798;

pragma(msg, "it's a floor wax");

13 changes: 13 additions & 0 deletions test/compilable/test16798.d
@@ -0,0 +1,13 @@
/*
REQUIRED_ARGS: -mv=its.a.dessert.topping=imports/imp16798.d -mv=its.a.floorwax=imports/
PERMUTE_ARGS:
TEST_OUTPUT:
---
it's a floor wax
it's a dessert topping
---
*/

import its.a.floorwax.wax16798;
import its.a.dessert.topping;

0 comments on commit 1e77dfa

Please sign in to comment.