Skip to content

Commit

Permalink
make: save commit id and branch name with "git archive"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Oct 14, 2024
1 parent 4fee44e commit 31f264a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/make/.git-archive-export.mk export-subst
36 changes: 28 additions & 8 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
all:
.PHONY: all

# git version
GIT_VERSION = $(shell LANG=C git --version)

# check GNU Make
ifeq ($(.FEATURES),)
$(error Sorry, please use a newer version (3.81 or later) of gmake (GNU Make).)
endif
MAKE_VERSION := $(shell LANG=C $(MAKE) --version | head -1)

# check gawk
GAWK := $(shell which gawk 2>/dev/null || bash -c 'builtin type -P gawk' 2>/dev/null)
Expand All @@ -26,7 +30,7 @@ else
endif
endif

MWGPP:=$(GAWK) -f make/mwg_pp.awk
MWGPP := $(GAWK) -f make/mwg_pp.awk

# Note (#D2058): we had used "cp -p xxx out/xxx" to copy files to the build
# directory, but some filesystem (ecryptfs) has a bug that the subsecond
Expand All @@ -40,21 +44,33 @@ CP := cp

FULLVER := 0.4.0-devel4

BLE_GIT_COMMIT_ID :=
BLE_GIT_BRANCH :=
ifneq ($(wildcard .git),)
BLE_GIT_COMMIT_ID := $(shell git show -s --format=%h)
BLE_GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
else ifneq ($(wildcard make/.git-archive-export.mk),)
ifeq ($(shell grep '\$$Format:.*\$$' make/.git-archive-export.mk),)
include make/.git-archive-export.mk
endif
endif
ifeq ($(BLE_GIT_COMMIT_ID),)
$(error Failed to determine the commit id of the current tree. The .git directory is required to build ble.sh.)
endif

OUTDIR:=out

outdirs += $(OUTDIR)

# Note: the following line is a workaround for the missing
# DEPENDENCIES_PHONY option for mwg_pp in older Makefile
ble-form.sh:

outfiles+=$(OUTDIR)/ble.sh
-include $(OUTDIR)/ble.dep
$(OUTDIR)/ble.sh: ble.pp GNUmakefile | .git $(OUTDIR)
$(OUTDIR)/ble.sh: ble.pp GNUmakefile | $(OUTDIR)
DEPENDENCIES_PHONY=1 DEPENDENCIES_OUTPUT="$(@:%.sh=%.dep)" DEPENDENCIES_TARGET="$@" \
FULLVER=$(FULLVER) \
BUILD_GIT_VERSION="$(shell LANG=C git --version)" \
BUILD_MAKE_VERSION="$(shell LANG=C $(MAKE) --version | head -1)" \
BLE_GIT_COMMIT_ID="$(BLE_GIT_COMMIT_ID)" \
BLE_GIT_BRANCH="$(BLE_GIT_BRANCH)" \
BUILD_GIT_VERSION="$(GIT_VERSION)" \
BUILD_MAKE_VERSION="$(MAKE_VERSION)" \
BUILD_GAWK_VERSION="$(GAWK_VERSION)" \
$(MWGPP) $< >/dev/null
.DELETE_ON_ERROR: $(OUTDIR)/ble.sh
Expand All @@ -71,6 +87,10 @@ src/canvas.emoji.sh:
src/canvas.GraphemeClusterBreak.sh:
$(GENTABLE) GraphemeClusterBreak

# Note: the following line is a workaround for the missing
# DEPENDENCIES_PHONY option for mwg_pp in older Makefile
ble-form.sh:

#------------------------------------------------------------------------------
# lib

Expand Down
19 changes: 13 additions & 6 deletions ble.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function ble/util/print { printf '%s\n' "$1"; }
# check --help or --version

{
#%[commit_hash = system("git show -s --format=%h")]
#%[commit_hash = getenv("BLE_GIT_COMMIT_ID")]
#%[ble_version = getenv("FULLVER") + "+" + commit_hash]
#%expand
##%if commit_hash != ""
Expand Down Expand Up @@ -2061,12 +2061,19 @@ function ble-reload {
source "$_ble_base/ble.sh" "${_ble_local_options[@]}"
}

#%$ pwd=$(pwd) q=\' Q="'\''" bash -c 'echo "_ble_base_repository=$q${pwd//$q/$Q}$q"'
#%$ echo "_ble_base_branch=$(git rev-parse --abbrev-ref HEAD)"
#%[quoted_repository = "'" + getenv("PWD" ).replace("'", "'\\''") + "'"]
#%[quoted_branch = "'" + getenv("BLE_GIT_BRANCH" ).replace("'", "'\\''") + "'"]
#%[quoted_git_version = "'" + getenv("BUILD_GIT_VERSION" ).replace("'", "'\\''") + "'"]
#%[quoted_make_version = "'" + getenv("BUILD_MAKE_VERSION").replace("'", "'\\''") + "'"]
#%[quoted_gawk_version = "'" + getenv("BUILD_GAWK_VERSION").replace("'", "'\\''") + "'"]
#%expand
_ble_base_repository=$"quoted_repository"
_ble_base_branch=$"quoted_branch"
_ble_base_repository_url=https://github.com/akinomyoga/ble.sh
#%$ echo "_ble_base_build_git_version=\"$BUILD_GIT_VERSION\""
#%$ echo "_ble_base_build_make_version=\"$BUILD_MAKE_VERSION\""
#%$ echo "_ble_base_build_gawk_version=\"$BUILD_GAWK_VERSION\""
_ble_base_build_git_version=$"quoted_git_version"
_ble_base_build_make_version=$"quoted_make_version"
_ble_base_build_gawk_version=$"quoted_gawk_version"
#%end.i
function ble-update/.check-install-directory-ownership {
if [[ ! -O $_ble_base ]]; then
ble/util/print 'ble-update: install directory is owned by another user:' >&2
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
- exec: refine the elapsed time resolution `#D2249` 67548656 713c4215
- highlight (`ble/syntax/highlight/vartype`): reference the saved states of variables `#D2268` 063249b4
- complete: attempt pathname expansions of incomplete pattern for `COMPV` (reported by mcepl) `#D2278` 6a426954
- make: save commit id and branch name with `git archive` (requested by LecrisUT, blackteahamburger) `#D2290` xxxxxxxx

## Fixes

Expand Down
4 changes: 4 additions & 0 deletions make/.git-archive-export.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This template is supposed to be instantiated by "git archive".

BLE_GIT_COMMIT_ID := $Format:%h$
BLE_GIT_BRANCH := $(shell echo "$Format:%D$" | sed -n 's/.*HEAD -> \([^,[:space:]]*\).*/\1/p')
15 changes: 10 additions & 5 deletions make_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ function sub:install {
script=$script'\
#\
# Source: /ble.pp'
local file
for file in $(git ls-files src); do
[[ $file == *.sh ]] || continue
script=$script"\\
if [[ -s out/ble.dep ]]; then
script=$script'\
'$(awk 'sub(/^ /, "") { sub(/ \\$/, "\\"); print "# Source: /" $0; }' out/ble.dep)
else
local file
for file in $(git ls-files src); do
[[ $file == *.sh ]] || continue
script=$script"\\
# Source: /$file"
done
done
fi
else
script=$script'\
#\
Expand Down
25 changes: 25 additions & 0 deletions note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7509,6 +7509,31 @@ bash_tips

2024-10-07

* make: .git に依存しない設定のために (requested by LecrisUT, blackteahamburger) [#D2290]
https://github.com/akinomyoga/ble.sh/issues/509

* edit: git archive で .git の代わりに commit-id を埋め込む (requested by LecrisUT)

issue title は git archive が build できないという物だが、提示されている
解決法は部分的な解決でしかない。結局 submodule の中身が含まれないので依然
として build できない。

.git に対する prerequisites は消す事にする。何故なら別に .git を作成する
規則を用意している訳でもないので、別に prerequisites のエラーとして処理し
なければならない必要性もないから。単に $(error ...) でエラーを出色すれば
良いだけの話である。

ble.pp の内部で解決するのも面倒なので GNUmakefile の中でまとめて git 関連
の情報取得を行って、環境変数経由で ble.pp に渡す事にした。

* 元々 git 前提だし git なしでビルドできる様にするのには色々困難があるので、
中途半端に対応しても仕方がないと考えていたが、修正しようとする人が余りに
も多い (しかも何故 .git repository を禁止している package manager がこん
なにもあるのだろうか) ので或る程度修正する事にした。

* ble.sh の依存性を git ls-files を用いて抽出しようとする部分があるが、これ
は out/ble.dep から依存ファイルを抜き出せば良いのでは → 実装した。

* histdb: calendar の着色が消滅している。何故? [#D2289]

これは既定の histdb palette の halloween の指定が誤っている為だった。10月に
Expand Down

0 comments on commit 31f264a

Please sign in to comment.