digitalmars.D.learn - Passing macros from commandline or enumerating versions
- =?UTF-8?Q?Martin_Dra=c5=a1ar?= via Digitalmars-d-learn (9/9) Mar 07 2017 Hi,
- Adam D. Ruppe (18/18) Mar 07 2017 The way I like to do it is to pass a module on the command line
- =?UTF-8?Q?Martin_Dra=c5=a1ar?= via Digitalmars-d-learn (10/40) Mar 08 2017 Yeah, that's definitely an option, but I expect to have troubles with
- Adam D. Ruppe (12/21) Mar 08 2017 ugh dub really show offer some way to pass individual modules
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 2017
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: --- 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: 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 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: --- 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: 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 2017
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 2017