# Importada de Alpine aports por `hammer import-alpine` (Etapa G). PUNTO DE PARTIDA — pero
# YA trae los parches de musl de Alpine (lo que un import de nix pierde). Pendiente: el
# sha256 del tarball (el wrapper lo calcula), y adaptar build/install del shell de abuild.
name    = "glab"
version = "1.102.0"

[source]
tarball = "https://gitlab.com/gitlab-org/cli/-/archive/v1.102.0/cli-v1.102.0.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "5015ecee3240514b135b0498183b9a912ad4b4fcdc7b1f06d62777904084aeece14ef585c5fee733b5cf5392a214d9b05fe7053b4c6dd21a38c9a3552e748b17"
sha256  = "40b1ba91634c150c01358bf41dd7878621002a248a40e5d62926bdf64e89709a"
patches = ["no-telemetry.patch"]

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "static"
flags    = []

[build.phases]
# de build() de Alpine (traducido; el lab provee $CBUILD/$CHOST — Etapa G Fase 3; revisá --shared para estático):
compile = '''
_abuild_phase() {
# date seems a little broken to override
	go build -ldflags "
		-X main.debugMode=false
		-X main.version=v1.102.0
		-X main.buildDate=$(date -u "+%Y-%m-%d" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
		-extldflags \"$LDFLAGS\"
		" \
		-o build/bin/glab \
		./cmd/glab/main.go

	go run ./cmd/gen-docs/docs.go --manpage --path ./build/man

	# XXX: When glab is run in fakeroot it segfaults for some reason
	# on ppc64le. By generating the compilation files here we
	# workaround that but we need to investigate why it segfaults in
	# fakeroot eventually.
	mkdir -p build/shell
	build/bin/glab completion --shell bash > build/shell/bash.comp
	build/bin/glab completion --shell zsh > build/shell/zsh.comp
	build/bin/glab completion --shell fish > build/shell/fish.comp
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
install -Dm755 build/bin/glab -t "/out"/usr/bin/

	install -Dm644 build/man/*.1 -t "/out"/usr/share/man/man1/

	install -Dm644 build/shell/bash.comp \
		"/out"/usr/share/bash-completion/completions/glab.bash
	install -Dm644 build/shell/zsh.comp \
		"/out"/usr/share/zsh/site-functions/_glab
	install -Dm644 build/shell/fish.comp \
		"/out"/usr/share/fish/vendor_completions.d/glab.fish
}
_abuild_phase
'''

# depends de runtime de Alpine (NO build-deps): git
