Author Topic: Find Revision In Subversion  (Read 8494 times)

Capn_Fish

  • Hero Member
  • *****
  • Posts: 2342
    • View Profile
    • http://
Find Revision In Subversion
« on: December 26, 2008, 11:45:29 pm »
I've been working on some stuff, and have it in a local subversion repo. Since I've got a client and a server, I'd like to have my code check to ensure that both are using the same version. I thought that, for at least testing, using the revision number would be a good way to go (I could throw in some compile-time options to have an actual number if stuff ever gets to that point).

My problem is that I have yet to figure out a way to find the revision number. I've got a script that builds binaries, and thought it would be as easy as doing something like:

Code: [Select]
g++ -o mytestprogram src/*.cpp -DVERSION=`cat .svn/version` -lMYLIBS
(sorry about the likely poor syntax with the "-D..." part. I've never tried to actually define something as a string, just as existing or not, plus it's been a long day)

Anyway, I didn't see the revision anywhere in the .svn dirs. Could somebody help me out (once again, sorry if this is obvious, I'm tired)?

Thanks.
« Last Edit: December 28, 2008, 05:58:11 pm by speculatrix »
SL-C750- pdaXrom beta 1 (mostly unused)
Current distro: Gentoo

dhns

  • Hero Member
  • *****
  • Posts: 699
    • View Profile
    • http://www.goldelico.com
Find Revision In Subversion
« Reply #1 on: December 27, 2008, 03:43:24 am »
Code: [Select]
/usr/bin/svnversionhttp://svnbook.red-bean.com/en/1.1/re57.html
The result has to be processed a little since it tells the version in the repository and the local version (if they are not the same).

-- hns
« Last Edit: December 27, 2008, 03:44:32 am by dhns »
SL5500G, C860, C3100, WLAN, RTM8000, Powerbook G4, and others...
http://www.handheld-linux.com
http://www.quantum-step.com

Capn_Fish

  • Hero Member
  • *****
  • Posts: 2342
    • View Profile
    • http://
Find Revision In Subversion
« Reply #2 on: December 28, 2008, 02:30:52 pm »
Thanks! Now I've got another question:

How can I define something to have a value (instead of just being defined or not)? Something like:

Code: [Select]
g++ -o foo foo.cpp -DBAR="bar"
The above obviously doesn't work, though...

Thanks in advance.
SL-C750- pdaXrom beta 1 (mostly unused)
Current distro: Gentoo

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Find Revision In Subversion
« Reply #3 on: December 28, 2008, 06:00:26 pm »
I'd have thought a makefile macro would be the best way

1/ using make will make life easier for repeatable command sequence
2/ make allows you to do some clever macros which will allow derivation of versions
3/ profit!
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

Capn_Fish

  • Hero Member
  • *****
  • Posts: 2342
    • View Profile
    • http://
Find Revision In Subversion
« Reply #4 on: December 28, 2008, 10:22:43 pm »
I've been meaning to get autotools working with this project, but haven't found a good how-to, and I haven't looked into Makefiles. I guess I should.

Thanks!

EDIT: Well, the Makefile helps, but I still can't figure out how to do this defining stuff. All I want is a way to #define a version number...

EDIT2: It looks like most examples just echo the version to a file and then delete said file when doing a "make clean." There's got to be a better way.
« Last Edit: December 28, 2008, 11:28:12 pm by Capn_Fish »
SL-C750- pdaXrom beta 1 (mostly unused)
Current distro: Gentoo

sdjf

  • Sr. Member
  • ****
  • Posts: 447
    • View Profile
    • http://www.sdjf.wordpress.com and http://www.sdjf.esmartdesign.com
Find Revision In Subversion
« Reply #5 on: December 30, 2008, 12:51:59 am »
There probably is a way to use bash to extract the original version number and then use the "expr" command to add one to it, but the code would be quite complex.  Quickening has helped me do some stuff like this with modifying a string I wanted to use as a file name, but it would take a lot of trial and error to get it working.

It's a question for a bash coding expert (which I am not)!  There may be a better way to do it, but I would save your file with a temporary file name, and then have a script that you call which gives it a spiffy new name that meets your specs.

Can you cope with that approach?  I don't want to waste time playing around with the code if it isn't how you would consider handling it.

Also, if interested, please show me what the file name would look like before and after, I don't understand the C++ stuff at all.

sdjf
http://www.sdjf.esmartdesign.com
http://www.sdjf.wordpress.com
-----------------
sl5500 running Sharp ROM 2.38 (dead batteries)
sl6000L running Sharp ROM 1.12 (still working)
Opera 7.25 and 7.30
Socket CF 56k modem
3Com USB Ethernet Adapter
Toshiba, Lexar and Kingston SD cards
Lexar, Kingston and Transcend CF cards

Capn_Fish

  • Hero Member
  • *****
  • Posts: 2342
    • View Profile
    • http://
Find Revision In Subversion
« Reply #6 on: December 30, 2008, 07:56:05 pm »
I don't want to rename anything, just get a version number into the build. I'm guessing that most autotools apps create a "config.h" file that has all of the options in it, as it appears to be impossible to do

Code: [Select]
g++ -o foobar foo.cpp -DBAR="BAR"
Anyway, thanks for the help (I'm currently just echoing

Code: [Select]
#define VERSION x.y.z
to a file called version.hpp and then deleting it upon cleanup, FWIW.
SL-C750- pdaXrom beta 1 (mostly unused)
Current distro: Gentoo