libprima / prima

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. PRIMA means Reference Implementation for Powell's methods with Modernization and Amelioration, P for Powell.
http://libprima.net
BSD 3-Clause "New" or "Revised" License
304 stars 40 forks source link

Get the version number using git tags #128

Closed nbelakovski closed 9 months ago

nbelakovski commented 9 months ago

This lets us avoid having a hardcoded file in the repo and having to update it for a release. This way releases can be done simply by tagging the appropriate commit and rebuilding.

This will be useful for when we publish packages, since it lets us publish a package every time we run CI and not have it conflict with or overwrite the latest package.

jschueller commented 9 months ago

this will fail on windows or if we build from the github tarball maybe try this ? https://github.com/antoniovazquezblanco/cmake-gitversiondetect/blob/main/GitVersionDetect.cmake

nbelakovski commented 9 months ago

It works on Windows, I specifically modified the code so that it would. Why would we build from the github tarball?

zaikunzhang commented 9 months ago

@nbelakovski, thank you for proposing this. Ping me when both you and @jschueller think it is ready.

jschueller commented 9 months ago

it wont work on windows without bash support, why not call directly the git command from cmake instead ?

jschueller commented 9 months ago

also it should work from the tarball, macports already uses it, and so will linux distro usually

nbelakovski commented 9 months ago

I changed it to use git describe so that it's not necessary to use a bash script. I had actually initially wanted to use it, but I think I didn't like the default output and so I wanted to make my own but long story short I'd rather keep things simple.

I also learned about export-subst in this process, which lets you write a file in such a way that git archive will substitute certain placeholders in the file with git information, and can even include the output of describe. This should solve the macports case.

I validated that the .git-archival.txt file is set up correctly by performing the following actions on my machine (I obtained the githash from going into the actions and looking at the output of the clone repository action):

$ curl -L https://api.github.com/repos/libprima/prima/tarball/9a0485ea -o myarchive.tgz
$ tar xzf myarchive.tgz
$ cd libprima-prima-9a0485e
$ cat .git-archival.txt
v0.7.2-162-g9a0485ea5

Note that the above commands will return a blank output on forked repos since they do not copy tags by default.

zaikunzhang commented 9 months ago

Hi @nbelakovski and @jschueller , is the PR ready? Thank you.