Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust search path according to module name #17654

Open
dlangBugzillaToGithub opened this issue Apr 23, 2014 · 1 comment
Open

Adjust search path according to module name #17654

dlangBugzillaToGithub opened this issue Apr 23, 2014 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

Vladimir Panteleev (@CyberShadow) reported this on 2014-04-23T21:26:39Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=12629

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

andrej.mitrovich (@AndrejMitrovic) commented on 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant