[Issue 1585] Imports should be searched relative to importing file

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 16 11:55:18 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1585





------- Comment #3 from wbaxter at gmail.com  2007-10-16 13:55 -------
The thread in question is here:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=58894

Don Clugston wrote:
"""
There's a more conservative case which is really annoying:

foo/bar.d
    module foo.bar;
    import foo.baz;
foo/baz.d
    module foo.baz;

If compiling from inside foo, it complains that it can't find foo/baz.d, even
though it knows that module foo.bar is found at ../foo/bar.d

But if you have
import baz;
it will work, even though it is probably a bug. (why are foo.bar and baz at the
same level??)

In practice -- this means that when developing a library, you cannot run your
tests from inside the same directory. So you always have to use a nasty -I
hack.

IMHO: If the module aaa.bbb.ccc; is in file ccc.d in the current directory,
then any other files in the aaa.bbb package should also be searched for in the
current directory. But I don't think it should ever look deeper than the
current directory; as Kirk points out, it can lead to ambiguity. 
"""
and later:

"""
Really, the problem is that the compiler is not consistent in its association
of modules with files.

Module names correspond to directories and files in import statements, but they
do not correspond to anything when used in module statements. That's the issue. 
"""

Jakob wrote:
"""
Well, i'm writing a tool which creates makefiles.

And if the compiler would analyze the module name to get the module root, it
would be much simpler for me :P
"""

It sounds like your needs would be served if you just had some tool that took a
.d file as input and gave you a "-I../.." string as output.

That shouldn't be too hard to write as a standalone program if you don't mind
letting some pathological cases slip through the cracks.

Or it could be added as another debug output of the -v compiler switch, to go
with the list of imports printed out.    If it would spit out a line like
"module foo.bar.baz" then that would be trivial to grep for and analyze with an
external tool.


-- 



More information about the Digitalmars-d-bugs mailing list