Re: What's the D way of application version numbers?

2014-01-13 Thread Russel Winder
On Sun, 2014-01-12 at 19:11 +, Adam D. Ruppe wrote:
[…]
 
 enum version = import(VERSION);
 // use it now like any other string in D

Calling 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.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



Re: What's the D way of application version numbers?

2014-01-13 Thread Dicebot

On Monday, 13 January 2014 at 11:39:02 UTC, Russel Winder wrote:

Calling a string an enum seemed discordant


Slightly off-topic but I should mention that in D enums are not 
just enumerations but any compile-time constants and used 
idiomatically that way.


Re: What's the D way of application version numbers?

2014-01-13 Thread Meta

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 = ...


Re: What's the D way of application version numbers?

2014-01-13 Thread Dejan Lekic

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.


Re: What's the D way of application version numbers?

2014-01-13 Thread Russel Winder
On Mon, 2014-01-13 at 15:05 +, 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_qualifier

Python 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.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



Re: What's the D way of application version numbers?

2014-01-13 Thread Meta

On Monday, 13 January 2014 at 19:18:17 UTC, Russel Winder wrote:

On Mon, 2014-01-13 at 15:05 +, 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_qualifier


Python 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.


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.


What's the D way of application version numbers?

2014-01-12 Thread Russel Winder
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.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



Re: What's the D way of application version numbers?

2014-01-12 Thread John Colvin

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.


Re: What's the D way of application version numbers?

2014-01-12 Thread Russel Winder
On Sun, 2014-01-12 at 18:59 +, 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.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



Re: What's the D way of application version numbers?

2014-01-12 Thread Adam D. Ruppe

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


Re: What's the D way of application version numbers?

2014-01-12 Thread Rikki Cattermole

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:
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


I was gonna suggest this but with using dub to generate it off of 
e.g. git tag pre compile.