www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - gen-package-version v0.9.0: New: Auto-generate version/timestamp

reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
This was kind of taken from a cool trick I saw in dub's buildscript, but 
I figured it would be useful to have generalized in a convenient 
package, no messing with shell scripts or anything.

https://github.com/Abscissa/gen-package-version

gen-package-version: Automatically generate a D module with version and 
timestamp information (detected from git) every time your program or 
library is built.

Additionally. all your in-between builds will automatically have their 
own git-generated version number, including the git commit hash (for 
example: v1.2.0-1-g78f5cf9). So there's never any confusion as to which 
"version" of v1.2.0 you're running!

Full usage and instructions are at the link above, but here's a brief 
primer for those using it with dub:

To use:
=======

Add this to your dub.json:

-----------------------------------------------------
"dependencies": {
     "gen-package-version": "~>0.9.0"
},
"preGenerateCommands":
     ["dub run gen-package-version -- package.name --src=path/to/src"]
-----------------------------------------------------

It'll generate "path/to/src/package/name/packageVersion.d".

Then just import that and use:

-----------------------------------------------------
module package.name.main;

import std.stdio;
import package.name.packageVersion;

void main()
{
     writeln("My Cool Program ", packageVersion);
     writeln("Built on ", packageTimestamp);
}
-----------------------------------------------------
Jun 13 2015
next sibling parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
A couple fixes in v0.9.2:

https://github.com/Abscissa/gen-package-version/blob/master/CHANGELOG.md

- Fixed: helper/gen_version.sh isn't set as executable when checked out 
through dub, preventing successful build on Posix.

- Fixed: The old recommeded "preGenerateCommands" led to problems 
(project dependencies that use gen-package-version would run it from the 
wrong directory).

So...this is the correction on what you should include in your dub.json 
(if using gen-package-version through dub):

-----------------------------------------------------
"dependencies": {
     "gen-package-version": "~>0.9.2"
},
"preGenerateCommands":
["cd $PACKAGE_DIR && dub run gen-package-version -- your.package.name 
--src=path/to/src"]
-----------------------------------------------------
Jun 14 2015
prev sibling next sibling parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
One more followup, gen-package-version v0.9.3:

https://github.com/Abscissa/gen-package-version/blob/master/CHANGELOG.md

- Enhancement: If detecting the version number via git fails, attempt to 
detect it via the currect directory name (ex, 
~/.dub/packages/[project-name]-[version-tag]).

- Enhancement: Don't bother running git if there's no .git directory.

- Enhancement: Bootstraps itself, so gen-package-version itself enjoys 
the following fix:

- Fixed: Fails to detect version number for packages fetched by dub 
(since they lack .git).
Jun 15 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 16/06/2015 12:45 p.m., Nick Sabalausky wrote:
 One more followup, gen-package-version v0.9.3:

 https://github.com/Abscissa/gen-package-version/blob/master/CHANGELOG.md

 - Enhancement: If detecting the version number via git fails, attempt to
 detect it via the currect directory name (ex,
 ~/.dub/packages/[project-name]-[version-tag]).

 - Enhancement: Don't bother running git if there's no .git directory.

 - Enhancement: Bootstraps itself, so gen-package-version itself enjoys
 the following fix:

 - Fixed: Fails to detect version number for packages fetched by dub
 (since they lack .git).
Will it support hg in future?
Jun 15 2015
next sibling parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On 06/16/2015 12:40 AM, Rikki Cattermole wrote:
 On 16/06/2015 12:45 p.m., Nick Sabalausky wrote:
 One more followup, gen-package-version v0.9.3:

 https://github.com/Abscissa/gen-package-version/blob/master/CHANGELOG.md

 - Enhancement: If detecting the version number via git fails, attempt to
 detect it via the currect directory name (ex,
 ~/.dub/packages/[project-name]-[version-tag]).

 - Enhancement: Don't bother running git if there's no .git directory.

 - Enhancement: Bootstraps itself, so gen-package-version itself enjoys
 the following fix:

 - Fixed: Fails to detect version number for packages fetched by dub
 (since they lack .git).
Will it support hg in future?
Possibly. All I'd need is an hg equivalent to "git describe". Looks like there's one listed here: http://stackoverflow.com/questions/6693209/is-there-an-equivalent-to-gits-describe-function-for-mercurial But I haven't really been using hg so I don't really have any hg projects handy, and I've kinda forgotten even the basics. Could you post a hg command that will clone for me an OSS project I could use to test?
Jun 15 2015
parent reply "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Tuesday, 16 June 2015 at 06:35:47 UTC, Nick Sabalausky wrote:
 On 06/16/2015 12:40 AM, Rikki Cattermole wrote:
 On 16/06/2015 12:45 p.m., Nick Sabalausky wrote:
 [...]
Will it support hg in future?
Possibly. All I'd need is an hg equivalent to "git describe". Looks like there's one listed here: http://stackoverflow.com/questions/6693209/is-there-an-equivalent-to-gits-describe-function-for-mercurial But I haven't really been using hg so I don't really have any hg projects handy, and I've kinda forgotten even the basics. Could you post a hg command that will clone for me an OSS project I could use to test?
It's not a D project, but it does have tags and branches. https://bitbucket.org/sdorra/scm-manager/wiki/Home $ hg clone ssh://hg bitbucket.org/sdorra/scm-manager Example tag 1.12 $ hg up 1.12 should switch to it.
Jun 15 2015
parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On 06/16/2015 02:51 AM, Rikki Cattermole wrote:
 On Tuesday, 16 June 2015 at 06:35:47 UTC, Nick Sabalausky wrote:
 On 06/16/2015 12:40 AM, Rikki Cattermole wrote:
 On 16/06/2015 12:45 p.m., Nick Sabalausky wrote:
 [...]
Will it support hg in future?
Possibly. All I'd need is an hg equivalent to "git describe". Looks like there's one listed here: http://stackoverflow.com/questions/6693209/is-there-an-equivalent-to-gits-describe-function-for-mercurial But I haven't really been using hg so I don't really have any hg projects handy, and I've kinda forgotten even the basics. Could you post a hg command that will clone for me an OSS project I could use to test?
It's not a D project, but it does have tags and branches. https://bitbucket.org/sdorra/scm-manager/wiki/Home $ hg clone ssh://hg bitbucket.org/sdorra/scm-manager Example tag 1.12 $ hg up 1.12 should switch to it.
Cool. Just checked it out, looks like that command on the stackoverflow link should work well.
Jun 16 2015
parent "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Tuesday, 16 June 2015 at 07:14:35 UTC, Nick Sabalausky wrote:
 On 06/16/2015 02:51 AM, Rikki Cattermole wrote:
 On Tuesday, 16 June 2015 at 06:35:47 UTC, Nick Sabalausky 
 wrote:
 [...]
It's not a D project, but it does have tags and branches. https://bitbucket.org/sdorra/scm-manager/wiki/Home $ hg clone ssh://hg bitbucket.org/sdorra/scm-manager Example tag 1.12 $ hg up 1.12 should switch to it.
Cool. Just checked it out, looks like that command on the stackoverflow link should work well.
Thanks, will be appreciated. Mostly for the purpose of keeping dub repo as the base support level for e.g. Github vs Bitbucket.
Jun 16 2015
prev sibling parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On 06/16/2015 12:40 AM, Rikki Cattermole wrote:
 Will it support hg in future?
Ask and ye shall receive ;) Now in gen-package-version's ~master: https://github.com/Abscissa/gen-package-version/commit/a6b0aa8536c4080a5ee56f14f62aae9495a8c180 I'll add .hgignore support and then tag a new release soon, maybe tomorrow.
Jun 16 2015
parent "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Tuesday, 16 June 2015 at 07:26:34 UTC, Nick Sabalausky wrote:
 On 06/16/2015 12:40 AM, Rikki Cattermole wrote:
 Will it support hg in future?
Ask and ye shall receive ;) Now in gen-package-version's ~master: https://github.com/Abscissa/gen-package-version/commit/a6b0aa8536c4080a5ee56f14f62aae9495a8c180 I'll add .hgignore support and then tag a new release soon, maybe tomorrow.
Awesome thanks! Now I need to start working on my web server again to take advantage of it! (even though it is on Github). Although it looks more like a web application server then a web server right now.
Jun 16 2015
prev sibling parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On 06/14/2015 01:24 AM, Nick Sabalausky wrote:
 https://github.com/Abscissa/gen-package-version

 gen-package-version: Automatically generate a D module with version and
 timestamp information (detected from git) every time your program or
 library is built.
By request, Mercurial (hg) support now added in gen-package-version v0.9.4: https://github.com/Abscissa/gen-package-version/blob/master/CHANGELOG.md - Enhancement: Support detecting the version number via Mercurial (hg). - Enhancement: Support .hgignore for Mercurial working directories.
Jun 16 2015