push git related logic to cmake, now that i know how to do that kind of thing
This commit is contained in:
		@@ -23,6 +23,9 @@ SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/cellar")
 | 
				
			|||||||
# which point to directories outside the build tree to the install RPATH
 | 
					# which point to directories outside the build tree to the install RPATH
 | 
				
			||||||
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 | 
					SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include(Git)
 | 
				
			||||||
 | 
					git_init()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include(Ronn)
 | 
					include(Ronn)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
find_package(PythonInterp)
 | 
					find_package(PythonInterp)
 | 
				
			||||||
@@ -40,7 +43,10 @@ http://tclap.sourceforge.net and put the headers in ./include
 | 
				
			|||||||
(wink, nudge)")
 | 
					(wink, nudge)")
 | 
				
			||||||
endif(NOT TCLAP_FOUND)
 | 
					endif(NOT TCLAP_FOUND)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include_directories(include)
 | 
					include_directories("${CMAKE_SOURCE_DIR}/include")
 | 
				
			||||||
 | 
					configure_file("${CMAKE_SOURCE_DIR}/include/cmake.hpp.in"
 | 
				
			||||||
 | 
					                "${CMAKE_CURRENT_BINARY_DIR}/include/cmake.hpp")
 | 
				
			||||||
 | 
					include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
 | 
				
			||||||
set(src "${CMAKE_SOURCE_DIR}/src")
 | 
					set(src "${CMAKE_SOURCE_DIR}/src")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set(coggedfiles)
 | 
					set(coggedfiles)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										52
									
								
								cmake/Modules/Git.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								cmake/Modules/Git.cmake
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					function(git_init)
 | 
				
			||||||
 | 
					    set(options "")
 | 
				
			||||||
 | 
					    set(oneValueArgs SUBMODULE_DIR)
 | 
				
			||||||
 | 
					    set(multiValueArgs "")
 | 
				
			||||||
 | 
					    cmake_parse_arguments(GIT_INIT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set(GIT_SUBMODULE_DIR "${GIT_INIT_SUBMODULE_DIR}" PARENT_SCOPE)
 | 
				
			||||||
 | 
					    set(GIT_SUBMODULE_DIR_ABS "${CMAKE_SOURCE_DIR}/${GIT_INIT_SUBMODULE_DIR}" PARENT_SCOPE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    execute_process(COMMAND git rev-parse --git-dir
 | 
				
			||||||
 | 
					        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
 | 
				
			||||||
 | 
					        OUTPUT_QUIET
 | 
				
			||||||
 | 
					        RESULT_VARIABLE GIT_REPO_RESULT)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ("${GIT_REPO_RESULT}" STREQUAL "0")
 | 
				
			||||||
 | 
					        set(IS_GIT_REPO TRUE)
 | 
				
			||||||
 | 
					        set(IS_GIT_REPO TRUE PARENT_SCOPE)
 | 
				
			||||||
 | 
					    else("${GIT_REPO_RESULT}" STREQUAL "0")
 | 
				
			||||||
 | 
					        set(IS_GIT_REPO FALSE)
 | 
				
			||||||
 | 
					        set(IS_GIT_REPO FALSE PARENT_SCOPE)
 | 
				
			||||||
 | 
					    endif("${GIT_REPO_RESULT}" STREQUAL "0")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(IS_GIT_REPO)
 | 
				
			||||||
 | 
					        execute_process(COMMAND git log --pretty=format:%H -n 1
 | 
				
			||||||
 | 
					            OUTPUT_VARIABLE GIT_COMMIT_HASH)
 | 
				
			||||||
 | 
					        string(STRIP "${GIT_COMMIT_HASH}" GIT_COMMIT_HASH)
 | 
				
			||||||
 | 
					        set(GIT_COMMIT_HASH ${GIT_COMMIT_HASH} PARENT_SCOPE)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        execute_process(COMMAND git symbolic-ref HEAD
 | 
				
			||||||
 | 
					            COMMAND cut -d/ -f3
 | 
				
			||||||
 | 
					            OUTPUT_VARIABLE GIT_BRANCH)
 | 
				
			||||||
 | 
					        string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
 | 
				
			||||||
 | 
					        set(GIT_BRANCH ${GIT_BRANCH} PARENT_SCOPE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        message(STATUS "commit ${GIT_COMMIT_HASH}, branch ${GIT_BRANCH}")
 | 
				
			||||||
 | 
					    else(IS_GIT_REPO)
 | 
				
			||||||
 | 
					        message(STATUS "This is not a git repo, assuming this tarball actually packaged everything...")
 | 
				
			||||||
 | 
					    endif(IS_GIT_REPO)
 | 
				
			||||||
 | 
					endfunction(git_init)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function(git_submodule)
 | 
				
			||||||
 | 
					    if(IS_GIT_REPO)
 | 
				
			||||||
 | 
					        set(oneValueArgs TARGET REMOTE_URL)
 | 
				
			||||||
 | 
					        set(multiValueArgs "")
 | 
				
			||||||
 | 
					        cmake_parse_arguments(GIT_SUBMODULE "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        execute_process(COMMAND git submodule update --init -- "${GIT_SUBMODULE_DIR}/${GIT_SUBMODULE_TARGET}"
 | 
				
			||||||
 | 
					            WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
 | 
				
			||||||
 | 
					            COMMENT "Updating submodule ${GIT_SUBMODULE_DIR}/${GIT_SUBMODULE_TARGET}"
 | 
				
			||||||
 | 
					            VERBATIM)
 | 
				
			||||||
 | 
					    endif(IS_GIT_REPO)
 | 
				
			||||||
 | 
					endfunction(git_submodule)
 | 
				
			||||||
							
								
								
									
										3
									
								
								cogrc
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								cogrc
									
									
									
									
									
								
							@@ -1,6 +1,5 @@
 | 
				
			|||||||
[version]
 | 
					[version]
 | 
				
			||||||
release=no
 | 
					release_version=0.4
 | 
				
			||||||
release_version=0.3
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
[defaults]
 | 
					[defaults]
 | 
				
			||||||
wine-path=wine
 | 
					wine-path=wine
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,13 @@
 | 
				
			|||||||
// vim: filetype=cpp :
 | 
					// vim: filetype=cpp :
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
 | 
					#ifdef IS_GIT_REPO
 | 
				
			||||||
 | 
					#include <sstream>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "cellar.hpp"
 | 
					#include "cellar.hpp"
 | 
				
			||||||
 | 
					#include "cmake.hpp"
 | 
				
			||||||
#include "internal/core.hpp"
 | 
					#include "internal/core.hpp"
 | 
				
			||||||
#include "commands.hpp"
 | 
					#include "commands.hpp"
 | 
				
			||||||
#include "output.hpp"
 | 
					#include "output.hpp"
 | 
				
			||||||
@@ -24,25 +28,24 @@ string cellar::version::short_version() {
 | 
				
			|||||||
         cparse.read("cogrc")
 | 
					         cparse.read("cogrc")
 | 
				
			||||||
         config = cparse["version"]
 | 
					         config = cparse["version"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if config.getboolean("release"):
 | 
					         cog.outl("return \"version {0}, built {1}\";".format(config["release_version"], str(today)))
 | 
				
			||||||
            outstring = "version {0}, built {1}".format(config["release_version"], str(today))
 | 
					 | 
				
			||||||
         else:
 | 
					 | 
				
			||||||
            try:
 | 
					 | 
				
			||||||
                import subprocess
 | 
					 | 
				
			||||||
                cmdoutput = subprocess.check_output(["git", "symbolic-ref", "HEAD"]).decode().strip()
 | 
					 | 
				
			||||||
                gitbranch = cmdoutput.split("/")[2]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                githash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
 | 
					 | 
				
			||||||
                outstring = "{0} {1}, built {2}".format(gitbranch, githash, str(today))
 | 
					 | 
				
			||||||
            except:
 | 
					 | 
				
			||||||
                outstring = "exception raised when trying to read git data at precompile time"
 | 
					 | 
				
			||||||
                raise
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
         cog.outl("return string(\"{0}\");".format(outstring))
 | 
					 | 
				
			||||||
    ]]]*/
 | 
					    ]]]*/
 | 
				
			||||||
    //[[[end]]]
 | 
					    //[[[end]]]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void cellar::core::print_version(int argc, vector<string> argv) {
 | 
					void cellar::core::print_version(int argc, vector<string> argv) {
 | 
				
			||||||
    cellar::output::statement(short_version());
 | 
					    cellar::output::statement(short_version());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #ifdef IS_GIT_REPO
 | 
				
			||||||
 | 
					    stringstream sstr;
 | 
				
			||||||
 | 
					    sstr << "git commit ";
 | 
				
			||||||
 | 
					    sstr << GIT_COMMIT_HASH;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sstr << " (branch ";
 | 
				
			||||||
 | 
					    sstr << GIT_BRANCH;
 | 
				
			||||||
 | 
					    sstr << ")";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // " >> git commit d34db33fcafe (branch master)"
 | 
				
			||||||
 | 
					    cellar::output::statement(sstr.str());
 | 
				
			||||||
 | 
					    #endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user