digitalmars.D.learn - What's the D way of application version numbers?
- Russel Winder (17/17) Jan 12 2014 With C++ and Python, it is idiomatic to put the application version
- John Colvin (4/22) Jan 12 2014 Unless I'm misunderstanding you, this is what the -version and
- Russel Winder (16/19) Jan 12 2014 I think I may not have explained correctly: version blocks are the way
- Adam D. Ruppe (6/9) Jan 12 2014 That's the way I do it in D too:
- Rikki Cattermole (3/12) Jan 12 2014 I was gonna suggest this but with using dub to generate it off of
- Russel Winder (14/17) Jan 13 2014 Calling a string an enum seemed discordant, and version is sort of a
- Dejan Lekic (16/34) Jan 13 2014 I simply define version in my main module (module which contains
- Russel Winder (14/29) Jan 13 2014 For the version number to be available to SCons it cannot be embedded in
- Meta (29/56) Jan 13 2014 template DeclareVersion(T...)
With C++ and Python, it is idiomatic to put the application version number in a separate file that can then be processed by the build system. For C++ a config file is constructed defining a macro that is then used in the rest of the course. For Python the file is read at runtime to define a variable. The build system itself uses the version number for creating deb, RPM, egg, wheel, etc. packages. D has no macro processing so C++ idioms are not useful. D does create a standalone executable and so the Python approach of reading the file at initialization time seems inappropriate. Is there a known D idiom for this? Thanks. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jan 12 2014
On Sunday, 12 January 2014 at 18:36:19 UTC, Russel Winder wrote:With C++ and Python, it is idiomatic to put the application version number in a separate file that can then be processed by the build system. For C++ a config file is constructed defining a macro that is then used in the rest of the course. For Python the file is read at runtime to define a variable. The build system itself uses the version number for creating deb, RPM, egg, wheel, etc. packages. D has no macro processing so C++ idioms are not useful. D does create a standalone executable and so the Python approach of reading the file at initialization time seems inappropriate. Is there a known D idiom for this? Thanks.Unless I'm misunderstanding you, this is what the -version and verion(){} blocks are for. Past that it's really a matter of choice depending on your build system.
Jan 12 2014
On Sun, 2014-01-12 at 18:59 +0000, John Colvin wrote: […]Unless I'm misunderstanding you, this is what the -version and verion(){} blocks are for. Past that it's really a matter of choice depending on your build system.I think I may not have explained correctly: version blocks are the way of dealing with platform specific features, basically a compilation switch on Windows, Linux OSX, etc. My problem is about embedding the application version number in the application. E.g 0.0.0-SNAPSHOT being in the executable and available to the build system to create the packages. If I create a D variable this is fine for the D executable but not accessible to the build system. (I may have consumed my pre-supper Ricard to quickly… :-) -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jan 12 2014
On Sunday, 12 January 2014 at 18:36:19 UTC, Russel Winder wrote:With C++ and Python, it is idiomatic to put the application version number in a separate file that can then be processed by the build system.That's the way I do it in D too: file VERSION says "1.0" dmd -J. myfile.d enum version = import("VERSION"); // use it now like any other string in D
Jan 12 2014
On Sunday, 12 January 2014 at 19:11:12 UTC, Adam D. Ruppe wrote:On Sunday, 12 January 2014 at 18:36:19 UTC, Russel Winder wrote:I was gonna suggest this but with using dub to generate it off of e.g. git tag pre compile.With C++ and Python, it is idiomatic to put the application version number in a separate file that can then be processed by the build system.That's the way I do it in D too: file VERSION says "1.0" dmd -J. myfile.d enum version = import("VERSION"); // use it now like any other string in D
Jan 12 2014
On Sun, 2014-01-12 at 19:11 +0000, Adam D. Ruppe wrote: […]enum version = import("VERSION"); // use it now like any other string in DCalling a string an enum seemed discordant, and version is sort of a reserved word (at least as far as Emacs D-Mode colorizing is concerned) so in the end I went with: immutable auto versionNumber = strip(import("VERSION")); which seems to do the job very nicely. Thanks for your response to my original question, most helpful. :-) -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jan 13 2014
On Monday, 13 January 2014 at 11:39:02 UTC, Russel Winder wrote:Calling a string an enum seemed discordantSlightly off-topic but I should mention that in D enums are not just enumerations but any compile-time constants and used idiomatically that way.
Jan 13 2014
On Monday, 13 January 2014 at 11:39:02 UTC, Russel Winder wrote:immutable auto versionNumber = strip(import("VERSION"));The "auto" doesn't do anything in this case, as immutable is a storage class and hence implies auto. It might be better to write: static immutable versionNumber = ...
Jan 13 2014
On Sunday, 12 January 2014 at 18:36:19 UTC, Russel Winder wrote:With C++ and Python, it is idiomatic to put the application version number in a separate file that can then be processed by the build system. For C++ a config file is constructed defining a macro that is then used in the rest of the course. For Python the file is read at runtime to define a variable. The build system itself uses the version number for creating deb, RPM, egg, wheel, etc. packages. D has no macro processing so C++ idioms are not useful. D does create a standalone executable and so the Python approach of reading the file at initialization time seems inappropriate. Is there a known D idiom for this? Thanks.I simply define version in my main module (module which contains the main() function). I am planning to submit a DIP about something that is related to this. - I think we really need a way to specify version of package, and maybe even version of a module (similar to how the new Java module system works - see project Jigsaw). D does not offer this. I humbly believe it should be part of the language as it could be used also for building versions of dynamic libraries. Anyway, back to the topic. Say my main() function is in the org.dlang.myapp module. If I want to have information about version of the artifact, my myapp.d starts with the following two lines of D code: module org.dlang.myapp; version = 1_3_21_4; // major_minor_micro_qualifier Naturally, build tool looks for the version line when I need it.
Jan 13 2014
On Mon, 2014-01-13 at 15:05 +0000, Dejan Lekic wrote: […]I simply define version in my main module (module which contains the main() function). I am planning to submit a DIP about something that is related to this. - I think we really need a way to specify version of package, and maybe even version of a module (similar to how the new Java module system works - see project Jigsaw). D does not offer this. I humbly believe it should be part of the language as it could be used also for building versions of dynamic libraries.For the version number to be available to SCons it cannot be embedded in the D source code. (Unless I am missing some really useful trick. :-)Anyway, back to the topic. Say my main() function is in the org.dlang.myapp module. If I want to have information about version of the artifact, my myapp.d starts with the following two lines of D code: module org.dlang.myapp; version = 1_3_21_4; // major_minor_micro_qualifierPython uses a tuple: (<major>, <minor>, <bugfix>, <annotation>) which seems to work very well: it needs very little reprocessing to be used in most contexts.Naturally, build tool looks for the version line when I need it.-- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jan 13 2014
On Monday, 13 January 2014 at 19:18:17 UTC, Russel Winder wrote:On Mon, 2014-01-13 at 15:05 +0000, Dejan Lekic wrote: […]template DeclareVersion(T...) { static if (T.length == 4) { alias Version = T; } else { static assert(false, "Version declaration must be of the form Version!(major, minor, bugfix, annotation)"); } } enum Version { major = 0, minor = 1, bugfix = 2, annotation = 3, } //main.d alias AppVersion = DeclareVersion!("1", "3", "21", "4"); import std.stdio; void main() { writeln(AppVersion[Version.major]); } Kind of neat, it's even accessible at compile time and gets compiled into the source.I simply define version in my main module (module which contains the main() function). I am planning to submit a DIP about something that is related to this. - I think we really need a way to specify version of package, and maybe even version of a module (similar to how the new Java module system works - see project Jigsaw). D does not offer this. I humbly believe it should be part of the language as it could be used also for building versions of dynamic libraries.For the version number to be available to SCons it cannot be embedded in the D source code. (Unless I am missing some really useful trick. :-)Anyway, back to the topic. Say my main() function is in the org.dlang.myapp module. If I want to have information about version of the artifact, my myapp.d starts with the following two lines of D code: module org.dlang.myapp; version = 1_3_21_4; // major_minor_micro_qualifierPython uses a tuple: (<major>, <minor>, <bugfix>, <annotation>) which seems to work very well: it needs very little reprocessing to be used in most contexts.Naturally, build tool looks for the version line when I need it.
Jan 13 2014