Passing macros from commandline or enumerating versions
Martin DraĊĦar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 8 04:00:40 PST 2017
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
More information about the Digitalmars-d-learn
mailing list