www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a way to adjust lookup paths for modules during compilation?

reply Andrey Zherikov <andrey.zherikov gmail.com> writes:
I want my program to add some directories into module lookup 
process (like adding -I dmd options). List of directories is 
known at compile time but the choice of what exact directories to 
add depends on `-version` parameter.
Is there a way to achieve this in code?

I can actually do this by creating scripts like 'build-version1', 
'build-version2' but I'm looking for a way to avoid this.
Jul 31 2019
next sibling parent reply bauss <jj_1337 live.dk> writes:
On Wednesday, 31 July 2019 at 17:29:58 UTC, Andrey Zherikov wrote:
 I want my program to add some directories into module lookup 
 process (like adding -I dmd options). List of directories is 
 known at compile time but the choice of what exact directories 
 to add depends on `-version` parameter.
 Is there a way to achieve this in code?

 I can actually do this by creating scripts like 
 'build-version1', 'build-version2' but I'm looking for a way to 
 avoid this.
Your best bet is actually not relying on CTFE since IO is very restricted at CTFE in D. Ex. you can only import files that are specified by you. The best thing you can do is have a file that lists every file you need to be able to read at CTFE.
Jul 31 2019
parent Andrey Zherikov <andrey.zherikov gmail.com> writes:
On Wednesday, 31 July 2019 at 17:59:00 UTC, bauss wrote:
 Your best bet is actually not relying on CTFE since IO is very 
 restricted at CTFE in D.

 Ex. you can only import files that are specified by you.

 The best thing you can do is have a file that lists every file 
 you need to be able to read at CTFE.
I'm not doing IO. I'm looking for something like this: version(version1) { add_import_path("location1"); } else version(version2) { add_import_path("location2"); } And dozens of other modules that do simple 'import somemodule' will get this module from either location1 or location2.
Jul 31 2019
prev sibling next sibling parent reply Andrey Zherikov <andrey.zherikov gmail.com> writes:
I found a function that seems could be used for adding import 
paths: dmd.frontend.addImport 
(https://dlang.org/phobos/dmd_frontend.html#.addImport). But it's 
not clear how can I use it: dmd directory is not added to lookup 
by default and trying adding it gives errors:

 dmd.exe -i -Ic:\D\dmd-2.086.1\src\dmd\ main.d
c:\D\dmd-2.086.1\src\dmd\dmd\dsymbol.d(231): Error: undefined identifier Symbol, did you mean class Dsymbol? c:\D\dmd-2.086.1\src\dmd\dmd\dsymbol.d(232): Error: undefined identifier Symbol, did you mean class Dsymbol? c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(105): Error: function `dmd.dimport.Import.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(110): Error: function `dmd.dimport.Import.prot` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(210): Error: function `dmd.dimport.Import.importAll` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(270): Error: function `dmd.dimport.Import.setScope` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(313): Error: function `dmd.dimport.Import.isImport` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(318): Error: function `dmd.dimport.Import.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\staticassert.d(56): Error: function `dmd.staticassert.StaticAssert.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\staticassert.d(61): Error: function `dmd.staticassert.StaticAssert.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\statement.d(2414): Error: function `dmd.statement.LabelDsymbol.isLabel` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\statement.d(2419): Error: function `dmd.statement.LabelDsymbol.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\statement.d(2454): Error: undefined identifier code, did you mean import core? c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(54): Error: function `dmd.dversion.DebugSymbol.toChars` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(103): Error: function `dmd.dversion.DebugSymbol.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(108): Error: function `dmd.dversion.DebugSymbol.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(142): Error: function `dmd.dversion.VersionSymbol.toChars` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(192): Error: function `dmd.dversion.VersionSymbol.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(197): Error: function `dmd.dversion.VersionSymbol.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\doc.d(360): Error: need -J switch to import text file default_ddoc_theme.ddoc Any ideas?
Jul 31 2019
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Jul 31, 2019 at 08:09:29PM +0000, Andrey Zherikov via
Digitalmars-d-learn wrote:
 I found a function that seems could be used for adding import paths:
 dmd.frontend.addImport
 (https://dlang.org/phobos/dmd_frontend.html#.addImport). But it's not clear
 how can I use it: dmd directory is not added to lookup by default and trying
 adding it gives errors:
[...] That's because you can only call that function from inside dmd code. It's not available for user code to call. T -- Those who don't understand Unix are condemned to reinvent it, poorly.
Jul 31 2019
parent reply Andrey Zherikov <andrey.zherikov gmail.com> writes:
On Wednesday, 31 July 2019 at 20:16:01 UTC, H. S. Teoh wrote:
 On Wed, Jul 31, 2019 at 08:09:29PM +0000, Andrey Zherikov via 
 Digitalmars-d-learn wrote:
 I found a function that seems could be used for adding import 
 paths: dmd.frontend.addImport 
 (https://dlang.org/phobos/dmd_frontend.html#.addImport). But 
 it's not clear how can I use it: dmd directory is not added to 
 lookup by default and trying adding it gives errors:
[...] That's because you can only call that function from inside dmd code. It's not available for user code to call. T
I even suspect that dmd package which (I guess) is supposed to be "DMD as a library" doesn't interact with DMD instance that is compiling the code.
Jul 31 2019
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Jul 31, 2019 at 08:47:42PM +0000, Andrey Zherikov via
Digitalmars-d-learn wrote:
 On Wednesday, 31 July 2019 at 20:16:01 UTC, H. S. Teoh wrote:
 On Wed, Jul 31, 2019 at 08:09:29PM +0000, Andrey Zherikov via
 Digitalmars-d-learn wrote:
 I found a function that seems could be used for adding import paths:
 dmd.frontend.addImport
 (https://dlang.org/phobos/dmd_frontend.html#.addImport). But it's
 not clear how can I use it: dmd directory is not added to lookup by
 default and trying adding it gives errors:
[...] That's because you can only call that function from inside dmd code. It's not available for user code to call. T
I even suspect that dmd package which (I guess) is supposed to be "DMD as a library" doesn't interact with DMD instance that is compiling the code.
The dmd package is supposed to be for your application to compile D code at runtime. It has nothing to do with compile-time features like CTFE when compiling your application's own code. T -- What doesn't kill me makes me stranger.
Jul 31 2019
prev sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 07/31/2019 10:29 AM, Andrey Zherikov wrote:
 I want my program to add some directories into module lookup process 
 (like adding -I dmd options). List of directories is known at compile 
 time but the choice of what exact directories to add depends on 
 `-version` parameter.
 Is there a way to achieve this in code?
 
 I can actually do this by creating scripts like 'build-version1', 
 'build-version2' but I'm looking for a way to avoid this.
This seems to be a task for the build system: whatever is setting the -version switch should set the -I switch as well. Ali
Jul 31 2019
parent Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 31 July 2019 at 20:25:44 UTC, Ali Çehreli wrote:
 On 07/31/2019 10:29 AM, Andrey Zherikov wrote:
 I want my program to add some directories into module lookup 
 process (like adding -I dmd options). List of directories is 
 known at compile time but the choice of what exact directories 
 to add depends on `-version` parameter.
 Is there a way to achieve this in code?
 
 I can actually do this by creating scripts like 
 'build-version1', 'build-version2' but I'm looking for a way 
 to avoid this.
This seems to be a task for the build system: whatever is setting the -version switch should set the -I switch as well. Ali
Yes, in dub you can create configurations for your dub project. Each configuration can define it's own versions and import paths. While executing dub, you would then pass the configuration to be build as command line arg: dub build -c myconfig1. (First config is the default config) https://dub.pm/package-format-json.html Kind regards Andre
Jul 31 2019