D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12629 - Adjust search path according to module name
Summary: Adjust search path according to module name
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-23 21:26 UTC by Vladimir Panteleev
Modified: 2024-12-13 18:20 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2014-04-23 21:26:39 UTC
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 Andrej Mitrovic 2014-04-24 10:00:16 UTC
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 dlangBugzillaToGithub 2024-12-13 18:20:01 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17654

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB