www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Passing macros from commandline or enumerating versions

reply =?UTF-8?Q?Martin_Dra=c5=a1ar?= via Digitalmars-d-learn writes:
Hi,

I was wondering, if there is a way to pass a macro with value to the
compiled program, i.e., something like -Dfoo="bar". And if that is not
possible, if there is a way to enumerate all set versions.

I want my application built with different string imported
configurations and I have no idea how to tell compiler which
configuration to choose, other than hardcoding it.

Thanks,
Martin
Mar 07
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
The way I like to do it is to pass a module on the command line 
that contains the custom config. So in the app:

---
import myapp.config;

// use the variables defined in there like normal
---


Now, to define a config file, you do something like:


myconfiguration.d # note that the file name can be anything!
---
module myapp.config; // but each must use this same module config

enum some_key = "some_value";
// and so on
---

Now, when you compile, you build it with a particular config by 
passing one of those files to the compile:

dmd myapp.d myconfiguration.d # or whatever single config you want



Then you can define as much as you want in the config module, and 
have as many of them as you want too.
Mar 07
parent reply =?UTF-8?Q?Martin_Dra=c5=a1ar?= via Digitalmars-d-learn writes:
Dne 7.3.2017 v 22:36 Adam D. Ruppe via Digitalmars-d-learn napsal(a):
 The way I like to do it is to pass a module on the command line that
 contains the custom config. So in the app:
 
 ---
 import myapp.config;
 
 // use the variables defined in there like normal
 ---
 
 
 Now, to define a config file, you do something like:
 
 
 myconfiguration.d # note that the file name can be anything!
 ---
 module myapp.config; // but each must use this same module config
 
 enum some_key = "some_value";
 // and so on
 ---
 
 Now, when you compile, you build it with a particular config by passing
 one of those files to the compile:
 
 dmd myapp.d myconfiguration.d # or whatever single config you want
 
 
 
 Then you can define as much as you want in the config module, and have
 as many of them as you want too.
Yeah, that's definitely an option, but I expect to have troubles with DUB if I use this approach. Also, I need these files to be json, not a D code, because the same configuration mechanism can be used during runtime and I need to parse these files easily. So far, I incline to have a build script run separate builds and copying different configuration files to one predefined and hardcode its name into a string import, thus sidestepping the problem. Anyway, thanks for an idea. Martin
Mar 08
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 8 March 2017 at 12:00:40 UTC, Martin DraĊĦar wrote:
 Yeah, that's definitely an option, but I expect to have 
 troubles with DUB if I use this approach.
ugh dub really show offer some way to pass individual modules too. Maybe we can request a `--passthrough something_to_pass_to_dmd_unmodified` feature.
 Also, I need these files to be json, not a D code, because the 
 same configuration mechanism can be used during runtime and I 
 need to parse these files easily.
You could use the string import feature which is basically the same deal on dmd, just do `-Jpath/to/specific/config/directory`... but again, not sure if dub's command line will let you do that. I know its config file will though, "stringImportPaths". But it would have to be a directory regardless, can't do individual files from the command line for string imports.
 So far, I incline to have a build script run separate builds 
 and copying different configuration files to one predefined and 
 hardcode its name into a string import, thus sidestepping the 
 problem.
Yeah, that works too.
Mar 08