sanggon6107 / static-commit-number-getter-for-cpp-developers

STATIC COMMIT NUMBER GETTER FOR C++ DEVELOPERS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

STATIC COMMIT NUMBER GETTER FOR C++ DEVELOPERS

1. Introduction

This powershell script is made to help C++ developers get the commit number of HEAD at buid time. Please note that this work is done assuming that the user's development environment is Visual studio on Windows.

2. How to use

  1. Put "static_commit_number_getter.ps1" to the directory of the project that you want to use. (See example project)

  2. Revise the relative directory of the project and .git file in the script if neccessary.

    $RelativeGitDir = '..\..\' # Hard-code the RELATIVE path from the project folder to the .git file.
    $RelativeProjectDir = '.\' # Pre-build-event usually put the initial directory to the Project dir.
  3. set the pre-buid event as below. (Project property > Build Events > Pre-build event)

    Powershell -ExecutionPolicy Bypass -File static_commit_number_getter.ps1
  4. Include "CommitNumber.h" from your cpp file as below (See example project) and build the project.

    #include "CommitNumber.h"
    
    #include <iostream>
    
    int main()
    {
        std::wcout << "commit number is " << COMMIT_NUMBER << std::endl;
    }

    The script will automatically make the header file, and the commit number will be defined as "COMMIT_NUMBER" as below.

    #ifndef COMMITNUMBER_H
    #define COMMITNUMBER_H
    #include <tchar.h>
    
    #define COMMIT_NUMBER _T("cecb17b5a3fcbc314e34c39655aa7fb310dbe297") // DO NOT REVISE THIS FILE MANNUALLY. Pre-build event will do it instead of you.
    #endif
  5. "Ta-da!" Now you'll see the commit number that HEAD is located.

    commit number is cecb17b5a3fcbc314e34c39655aa7fb310dbe297
    

About

STATIC COMMIT NUMBER GETTER FOR C++ DEVELOPERS

License:MIT License


Languages

Language:PowerShell 82.6%Language:C 13.6%Language:C++ 3.8%