www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dub and it's build directory

reply Russel Winder <russel winder.org.uk> writes:
Hi,

Given a package X, let us assume it's a library such that X =3D unit-
threaded, we find that in the ~/.dub/packages directory there is:

.dub/packages/unit-threaded-0.7.51/unit-threaded/gen_ut_main*
.dub/packages/unit-threaded-0.7.51/unit-threaded/libunit-threaded.a

These are the compilation products from the last undertaken compilation
and therefore more or less totally useless for anyone using more than
one D compiler.
Fortunately we find that there is a .dub directory with:

unit-threaded-0.7.51/unit-threaded/.dub
=E2=94=9C=E2=94=80=E2=94=80 build
=E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 gen_ut_main-debug-linux.posix-x86_6=
4-dmd_2081-5610CAAD59972DC7A3346FE37EEC66C8
=E2=94=82   =E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 gen_ut_main
=E2=94=82   =E2=94=82   =E2=94=94=E2=94=80=E2=94=80 gen_ut_main.o
=E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 gen_ut_main-debug-linux.posix-x86_6=
4-ldc_2081-02C0EA3AA341F3D071FE5E15E09EC021
=E2=94=82   =E2=94=82   =E2=94=94=E2=94=80=E2=94=80 gen_ut_main
=E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 gen_ut_main-release-linux.posix-x86=
_64-dmd_2081-A8C2C7980309FFAFE08C15D3B29DE3CC
=E2=94=82   =E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 gen_ut_main
=E2=94=82   =E2=94=82   =E2=94=94=E2=94=80=E2=94=80 gen_ut_main.o
=E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 gen_ut_main-release-linux.posix-x86=
_64-ldc_2081-78BBAEC37FCFC878CC8215379A7D854B
=E2=94=82   =E2=94=82   =E2=94=94=E2=94=80=E2=94=80 gen_ut_main
=E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 library-debug-linux.posix-x86_64-dm=
d_2081-5610CAAD59972DC7A3346FE37EEC66C8
=E2=94=82   =E2=94=82   =E2=94=94=E2=94=80=E2=94=80 libunit-threaded.a
=E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 library-debug-linux.posix-x86_64-ld=
c_2081-02C0EA3AA341F3D071FE5E15E09EC021
=E2=94=82   =E2=94=82   =E2=94=94=E2=94=80=E2=94=80 libunit-threaded.a
=E2=94=82   =E2=94=9C=E2=94=80=E2=94=80 library-release-linux.posix-x86_64-=
dmd_2081-A8C2C7980309FFAFE08C15D3B29DE3CC
=E2=94=82   =E2=94=82   =E2=94=94=E2=94=80=E2=94=80 libunit-threaded.a
=E2=94=82   =E2=94=94=E2=94=80=E2=94=80 library-release-linux.posix-x86_64-=
ldc_2081-78BBAEC37FCFC878CC8215379A7D854B
=E2=94=82       =E2=94=94=E2=94=80=E2=94=80 libunit-threaded.a
=E2=94=94=E2=94=80=E2=94=80 dub.json

OK, so this is now actually useful stuff for people using Dub.

Clearly the directory names are dash separated components:

=C2=B7 configuration
=C2=B7 build type
=C2=B7 dot separated platform specification
=C2=B7 architecture
=C2=B7 underscore separated compiler name and major/minor version number
=C2=B7 some bizarre psuedo-random number

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.

2. What is the pseudo-random number, and how is it calculated?
=20
--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk
Aug 20 2018
parent reply Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
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
Aug 21 2018
parent Seb <seb wilzba.ch> writes:
On Tuesday, 21 August 2018 at 12:31:20 UTC, Petar Kirov 
[ZombineDev] wrote:
 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].
FYI: the plan is to use the new JSON interface (e.g. `dmd -Xi=compilerInfo -Xf=-) soon. See also: https://github.com/dlang/dub/pull/1316
Aug 21 2018