Include generated git version string in executable and generated stub files
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,5 +4,8 @@
|
||||
/Release
|
||||
/*.stackdump
|
||||
|
||||
# /src
|
||||
/src/version.h
|
||||
|
||||
# /.settings/
|
||||
/.settings/*.xml
|
||||
|
21
resources/version.sh
Normal file
21
resources/version.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
createVersion() {
|
||||
local gitVersion=`git describe --long --always --dirty`
|
||||
local versionLoc="../src/version.h"
|
||||
local currentVersion=$(grep -oP '"\K.*(?=")' $versionLoc 2>/dev/null)
|
||||
|
||||
if [ ! -z "$1" ] && [ "$1" == "-d" ]; then
|
||||
gitVersion="${gitVersion}-debug"
|
||||
fi
|
||||
if [ "$gitVersion" == "$currentVersion" ]; then
|
||||
return 0
|
||||
else
|
||||
echo "Creating version header: ${gitVersion}"
|
||||
cat <<VERSION_END > "$versionLoc"
|
||||
#define GITVERSION "${gitVersion}"
|
||||
VERSION_END
|
||||
fi
|
||||
}
|
||||
|
||||
createVersion $*
|
18
src/main.c
18
src/main.c
@@ -15,6 +15,7 @@
|
||||
#include <ftw.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "version.h"
|
||||
#include "xmalloc.h"
|
||||
#include "xregex.h"
|
||||
#include "xtypes.h"
|
||||
@@ -101,11 +102,14 @@ int evaluateDirectoryTree(const char * const dirpath)
|
||||
|
||||
void printUsage(char *aAppName)
|
||||
{
|
||||
printf("%s version: %s\n", aAppName, GITVERSION);
|
||||
printf("Create stub c-files and c-header from c files for CUnit.\n\n");
|
||||
printf("Usage:\n");
|
||||
printf(" %s [options] [source dir] <target dir>\n", aAppName);
|
||||
printf("\nOptions:\n");
|
||||
printf(" -r\tSearch source Dir recursively\n");
|
||||
printf(" -h, --help \tShow usage\n");
|
||||
printf(" -r, --recurse\tSearch source Dir recursively\n");
|
||||
printf(" --version \tShow version\n");
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -139,10 +143,20 @@ int main(int argc, char **argv)
|
||||
// evaluate command line parameter
|
||||
for (i = 1; i < argc && i < 4; ++i)
|
||||
{
|
||||
if (NULL != strstr(argv[i], "-r"))
|
||||
if (NULL != strstr(argv[i], "-r") || NULL != strstr(argv[i], "--recurse"))
|
||||
{
|
||||
main_recurse = true;
|
||||
}
|
||||
else if (NULL != strstr(argv[i], "--version"))
|
||||
{
|
||||
printf("%s version: %s", gnu_basename(argv[0]), GITVERSION);
|
||||
goto l_main_end;
|
||||
}
|
||||
else if (NULL != strstr(argv[i], "-h") || NULL != strstr(argv[i], "--help"))
|
||||
{
|
||||
printUsage(gnu_basename(argv[0]));
|
||||
goto l_main_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
outputDirIndex = i;
|
||||
|
@@ -1,8 +1,7 @@
|
||||
/*!
|
||||
* @file stubser.c
|
||||
* @brief Scan a folder for .c files and generate stubs from function definitions
|
||||
* @attention Using regular expressions to scan c files for function definitions. No 100%
|
||||
* success rate and should be seen as helper. Result must be reviewed manually.
|
||||
* @attention Using regular expressions to scan c files for non static- function definitions and global variables.
|
||||
* @details
|
||||
* Project: stubser\n
|
||||
* Subsystem: \n
|
||||
@@ -25,6 +24,7 @@
|
||||
#include "cfile_parser_if.h"
|
||||
#include "stubser_if.h"
|
||||
#include "stubser_loc.h"
|
||||
#include "../version.h"
|
||||
#include "debug.h"
|
||||
|
||||
STATIC bool isDatatypeVoid(char *aType)
|
||||
@@ -887,7 +887,7 @@ STATIC void createUserFiles(char *aOutput, char *aNoSuffix, bool aVaList)
|
||||
fprintf(fileDesc, "/*! @file %s"NEWLINES, gnu_basename(cHeaderName));
|
||||
fprintf(fileDesc, " * @details"NEWLINES" * This is a user defined stub header.\\n"NEWLINES);
|
||||
fprintf(fileDesc, " * Define subject header needed for compilation of stub (e.g. typedefs, structures, ...).\\n"NEWLINES);
|
||||
fprintf(fileDesc, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||
fprintf(fileDesc, " * - generated by stubser %s -"NEWLINES" */" NEWLINES NEWLINES, GITVERSION);
|
||||
|
||||
fprintf(fileDesc, "#ifndef _STUB_%s_USER_H"NEWLINES, aNoSuffix);
|
||||
fprintf(fileDesc, "#define _STUB_%s_USER_H"NEWLINES, aNoSuffix);
|
||||
@@ -921,7 +921,7 @@ STATIC void createUserFiles(char *aOutput, char *aNoSuffix, bool aVaList)
|
||||
fprintf(fileDesc, "/*! @file %s"NEWLINES, gnu_basename(cFileName));
|
||||
fprintf(fileDesc, " * @details"NEWLINES" * This is a user defined stub.\\n"NEWLINES);
|
||||
fprintf(fileDesc, " * Define additional elements which need to be tested, or helper functions.\\n"NEWLINES);
|
||||
fprintf(fileDesc, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||
fprintf(fileDesc, " * - generated by stubser %s -"NEWLINES" */" NEWLINES NEWLINES, GITVERSION);
|
||||
|
||||
fprintf(fileDesc, "#include <CUnit/CUnit.h>"NEWLINES);
|
||||
fprintf(fileDesc, "#include <stdint.h>"NEWLINES);
|
||||
@@ -981,7 +981,7 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
|
||||
|
||||
fprintf(cfile, "/*! @file %s"NEWLINES, gnu_basename(cFileName));
|
||||
fprintf(cfile, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES);
|
||||
fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||
fprintf(cfile, " * - generated by stubser %s -"NEWLINES" */" NEWLINES NEWLINES, GITVERSION);
|
||||
fprintf(cfile, "#include <CUnit/CUnit.h>"NEWLINES);
|
||||
fprintf(cfile, "#include <stdint.h>"NEWLINES);
|
||||
if(vaListAvailable)
|
||||
@@ -999,7 +999,7 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
|
||||
|
||||
fprintf(cheader, "/*! @file %s"NEWLINES, gnu_basename(cHeaderName));
|
||||
fprintf(cheader, " * @details"NEWLINES" * This is a stub header.\\n"NEWLINES);
|
||||
fprintf(cheader, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||
fprintf(cheader, " * - generated by stubser %s -"NEWLINES" */" NEWLINES NEWLINES, GITVERSION);
|
||||
|
||||
fprintf(cheader, "#ifndef _STUB_%s_H"NEWLINES, aNoSuffix);
|
||||
fprintf(cheader, "#define _STUB_%s_H"NEWLINES NEWLINES, aNoSuffix);
|
||||
|
Reference in New Issue
Block a user