Dub and it's build directory

Petar Petar
Tue Aug 21 12:31:20 UTC 2018


On Monday, 20 August 2018 at 18:59:23 UTC, Russel Winder wrote:
> Hi,
>
> [...]

Hi Russel,

> So the questions are:
>
> 1. How does Dub find the compiler version number, in this case 
> 2.081, given that neither DMD or LDC seem to have a way of 
> delivering only the version number.

The __VERSION__ [1] special token gives you an integer like 2081 
at compile-time. For DMD, LDC and GDC this is the version of the 
DMD frontend they are based on. Obviously, for other compilers 
(not based on the DMD frontend like SDC) there would be no 
equivalent integer, but since there's no other mature alternative 
D implementations this is not a problem in practice. Since the 
__VERSION__ token is replaced with an integer literal at 
compile-time, it can be used for things like conditional 
compilation (e.g. when you want support multiple versions of a 
dmd+druntime+phobos release, for exmaple: [2]).

What Dub does is what it calls "platform probing" [3]. It creates 
a temporary .d file containing various `pragma (msg, ..)` 
statements that output information to stderr during compilation. 
Of course the question is then: which compiler is used to compile 
the platform probe file? AFAICS, it uses either the one requested 
for on the command-line (via --compiler=... ) or via an internal 
heuristic which is a bit involved [4].

> 2. What is the pseudo-random number, and how is it calculated?

It's an MD5 hash of all the various parameters of a dub build 
(aka the build settings). It's calculated here: [5].

Perhaps some of the information is documented somewhere (if not 
it should be), but I found it easier to search through the code.

Petar

[1]: https://dlang.org/spec/lex.html#specialtokens
[2]: 
https://github.com/dlang/dub/blob/520d527fb11811c8f60b29a0ad15e6f48cf9f9d0/source/dub/internal/utils.d#L263
[3]: 
https://github.com/dlang/dub/blob/1ca0ad263bb364f66f71642152420dd1dce43ce2/source/dub/compilers/compiler.d#L119
[4]: 
https://github.com/dlang/dub/blob/1ca0ad263bb364f66f71642152420dd1dce43ce2/source/dub/dub.d#L1296
[5]: 
https://github.com/dlang/dub/blob/1ca0ad263bb364f66f71642152420dd1dce43ce2/source/dub/generators/build.d#L320


More information about the Digitalmars-d-learn mailing list