Bug 12797 – RDMD tries to compile imports inside traits(compiles,...)
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
tools
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2014-05-25T01:10:33Z
Last change time
2020-03-21T03:56:38Z
Assigned to
No Owner
Creator
Nick Sabalausky
Comments
Comment #0 by bus_dbugzilla — 2014-05-25T01:10:33Z
// test.d
enum x = __traits(compiles, (){ import doesNotExist; });
DMD works:
> dmd -c test.d
RDMD fails:
> rdmd -c test.d
Error: cannot read file doesNotExist.d
The problem is RDMD gets dependencies by reading DMD's -v output, which always includes doesNotExist (since DMD *does* attempt to import it). Since RDMD sees doesNotExist in the -v output, it mistakenly tries to build it.
This prevents optional imports from working with RDMD:
static if( __traits(compiles, (){ import foobar; }) )
{ import foobar; }
else
/+ do something else +/
It might be better for RDMD to read the -deps output instead, and omit the files listed with "(???)" as the filename.
Comment #1 by b2.temp — 2017-11-15T18:38:37Z
RDMD still uses -v but DMD -v doesn't include it anymore so it works now