Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for setting git version externally #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

G-M0N3Y-2503
Copy link

This to help when building from source snapshots that typically don't have an entire repository.

@krallin
Copy link
Owner

krallin commented Nov 14, 2020

I'd rather make override the whole TINI_VERSION. As-is, it seems a little surprising that we have a TINI_COMMIT variable that actually overrides the whole variable if set (including the dirty check, so not just the commit), and it's a bit wasteful that we run git to check what the commit & dirty flag is, even if we're not going to use it.

How about something like this:

if (NOT "${TINI_VERSION_GIT}" STREQUAL "")
	# Version was set by the user directly
	set(tini_VERSION_GIT " - ${TINI_VERSION_GIT}")
else()
	# Extract git version and dirty-ness
	execute_process (
	  COMMAND git --git-dir "${PROJECT_SOURCE_DIR}/.git" --work-tree "${PROJECT_SOURCE_DIR}" log -n 1 --date=local --pretty=format:%h
	  WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
	  RESULT_VARIABLE git_version_check_ret
	  OUTPUT_VARIABLE tini_VERSION_GIT
	)

	execute_process(
	  COMMAND git --git-dir "${PROJECT_SOURCE_DIR}/.git" --work-tree "${PROJECT_SOURCE_DIR}" status --porcelain --untracked-files=no
	  WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
	  OUTPUT_VARIABLE git_dirty_check_out
	)

	if("${git_version_check_ret}" EQUAL 0)
	  set(tini_VERSION_GIT " - git.${tini_VERSION_GIT}")
	  if(NOT "${git_dirty_check_out}" STREQUAL "")
	    set(tini_VERSION_GIT "${tini_VERSION_GIT}-dirty")
	  endif()
	else()
	  set(tini_VERSION_GIT "")
	endif()
endif()

* This to help when building from source snapshots
  that don't have the .git file structure.
@G-M0N3Y-2503
Copy link
Author

I was trying for a minimal diff, But it looks like you wouldn't mind more if it was better.
I largely followed your suggestion except kept the setting of the formatted result after this block and also conditionally run the dirty check only if the first git command works.

The intention of the patch is to facilitate the same build output (In this case the version string) when building a source snapshot. (like https://github.com/krallin/tini/archive/v0.19.0.tar.gz as it will produce a different version since the git commands will fail)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants