D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12797 - RDMD tries to compile imports inside traits(compiles,...)
Summary: RDMD tries to compile imports inside traits(compiles,...)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: tools (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-25 01:10 UTC by Nick Sabalausky
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nick Sabalausky 2014-05-25 01:10:33 UTC
// 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 basile-z 2017-11-15 18:38:37 UTC
RDMD still uses -v but DMD -v doesn't include it anymore so it works now