Wednesday, October 09, 2019

Get SVN revision and write to header file

I am creating a C++ dll file from a MATLAB Simulink model. The simulink model repository is hosted on subversion. I needed a way to embed simulink model subversion revision to dll so that the dll could return that revision via an interface method to interested clients. I wrote the following batch file to fetch revision from SVN and write to a header file:
rem Create C/C++ header file that contains SVN revision definition.
rem Prerequisite: TortoiseSVN command line client tools must be installed.
rem https://stackoverflow.com/a/23400262/51358
rem https://stackoverflow.com/a/25798034/51358
set simulinkSVNPath=<enter SVN repo path>
set svnSimulinkRevision=unknown
FOR /F "tokens=4" %%i IN ('svn info %simulinkSVNPath%^|FINDSTR /C: "Last Changed Revision:"') DO (SET svnSimulinkRevision=%%i)
rem Note that "Last Changed Revision:" returns revision of full URL while "Revision:" would return revision of root (with tokens=2).
set outputFileName=svnRevisionSimulink.h
(
echo;#pragma once
echo;#define SVN_PATH_SIMULINK "%simulinkSVNPath%"
echo;#define SVN_REVISION_SIMULINK %svnSimulinkRevision%
)>%outputFileName%
@echo Simulink SVN head revision %svnSimulinkRevision% written to %outputFileName%

No comments: