diff --git a/.gitignore b/.gitignore index 590eb55..ec58e4e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,8 @@ /Release /*.stackdump +# /src +/src/version.h + # /.settings/ /.settings/*.xml diff --git a/resources/version.sh b/resources/version.sh new file mode 100644 index 0000000..be51904 --- /dev/null +++ b/resources/version.sh @@ -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 < "$versionLoc" +#define GITVERSION "${gitVersion}" +VERSION_END + fi +} + +createVersion $* diff --git a/src/main.c b/src/main.c index 3a132bb..a36a13f 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ #include #include +#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] \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; diff --git a/src/stubser/stubser.c b/src/stubser/stubser.c index 4ca42ab..1b43bd9 100644 --- a/src/stubser/stubser.c +++ b/src/stubser/stubser.c @@ -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 "NEWLINES); fprintf(fileDesc, "#include "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 "NEWLINES); fprintf(cfile, "#include "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);