www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Global version/debug statements in file?

reply cc <cc nevernet.com> writes:
Is there some way to globally declare version= or debug= 
statements in a file and have them apply to the entire project 
being compiled?  As the documentation says these only apply to 
the module scope they exist in, and need to be added to the 
command line otherwise.  It would be a bit easier for me to 
maintain a separate .d source file when I want to add/comment out 
statements for testing than to keep updating the build command 
line.  I tried using a mixin, such as:

// constants.d
module constants;
enum VERSIONS = q{
	version=Compress;
};

// main.d
import constants;
mixin(VERSIONS);
void main() {
	version(Compress)
		writeln("Compress it!");
	version(Decompress)
		writeln("Decompress it!");
}

This does seem to work inside function bodies, but not at module 
scope in the importing file.  e.g.:

// main.d
import constants;
mixin(VERSIONS)
version(Compress) {
	...
}

Gives: Error: version `Compress` defined after use
Feb 12 2020
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Wednesday, 12 February 2020 at 08:44:24 UTC, cc wrote:
 Is there some way to globally declare version= or debug= 
 statements in a file and have them apply to the entire project 
 being compiled?  As the documentation says these only apply to 
 the module scope they exist in, and need to be added to the 
 command line otherwise.  It would be a bit easier for me to 
 maintain a separate .d source file when I want to add/comment 
 out statements for testing than to keep updating the build 
 command line.
https://dlang.org/dmd-windows.html#switches specifies that DMD may be passed a file on the command line that contains compiler arguments and switches. This may be freely combined with regular command line arguments if you so wish. So, you could have a file called 'versions' containing this: -version=Compress and feed it to dmd like so: dmd -w -wi -g versions -main foo.d -- Simen
Feb 12 2020
parent cc <cc nevernet.com> writes:
On Wednesday, 12 February 2020 at 09:28:15 UTC, Simen Kjærås 
wrote:
 https://dlang.org/dmd-windows.html#switches

 specifies that DMD may be passed a file on the command line 
 that contains compiler arguments and switches. This may be 
 freely combined with regular command line arguments if you so 
 wish.

 So, you could have a file called 'versions' containing this:


 -version=Compress




 and feed it to dmd like so:

     dmd -w -wi -g  versions -main foo.d

 --
   Simen
Ahh missed that, that should do it, thanks!
Feb 12 2020