Comment #0 by dlang-bugzilla — 2014-04-23T21:26:39Z
Consider a project with the following structure:
a/b/foo.d:
module a.b.foo;
a/b/bar.d:
module a.b.bar;
import a.b.foo;
If you run:
~ $ cd a/b
~/a/b $ dmd bar.d
DMD will fail to compile, because it will not look for "a/b/foo.d" from the project root.
I propose the following enhancement:
Implicitly add the package root, according to the module declaration, to the search path.
For example, if the file contains the line "module a.b.foo;", add "../.." to the search path.
This will allow to compile modules or run D programs located in packages by simply associating .d files with the compiler, with no further configuration.
Comment #1 by andrej.mitrovich — 2014-04-24T10:00:16Z
Only thing to be careful about is the implementation. IOW in this case:
// unrelated file or module
a/c/foo.d:
// actual module we want
some/other/a/c/foo.d
module a.c.foo;
a/b/bar.d:
module a.b.bar;
import a.c.foo;
If you run:
$ cd a/b
$ dmd -Isome/other bar.d
The explicit import path should be favored over the implicit one. IOW, only if the module hasn't been found in existing imports should the compiler try and search in paths based on the module name.
Comment #2 by robert.schadek — 2024-12-13T18:20:01Z