Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Sep 2022 16:30:20 GMT
From:      Adam Weinberger <adamw@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 25057f927b52 - main - www/caddy: Provide a version string
Message-ID:  <202209221630.28MGUKZ2070801@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by adamw:

URL: https://cgit.FreeBSD.org/ports/commit/?id=25057f927b52736d34e6d4e0c4cb43f47907b5de

commit 25057f927b52736d34e6d4e0c4cb43f47907b5de
Author:     Adam Weinberger <adamw@FreeBSD.org>
AuthorDate: 2022-09-22 16:24:03 +0000
Commit:     Adam Weinberger <adamw@FreeBSD.org>
CommitDate: 2022-09-22 16:30:14 +0000

    www/caddy: Provide a version string
    
    When build from ports, `caddy version` returns an empty string.
    
    Upstream likes caddy to be built from their xcaddy command, for which
    FreeBSD has a port (www/xcaddy) and a package (pkg install xcaddy).
    However, our package builders cannot use xcaddy itself, as it needs
    external network access. Caddy itself contains no ability to set the
    version without the extensive patching that xcaddy performs.
    
    This commit adds a version string to allow the version to be set.
    When built with xcaddy, the version string can contain a checksum of
    some sort, but we are just using ${DISTVERSIONFULL} here (e.g. v2.6.1).
    
    The lack of a version string has been brought up a number of times to
    me, so I'm happy to put this issue to bed.
    
    See https://github.com/caddyserver/caddy/issues/5065 for the latest
    discussion about it.
---
 www/caddy/Makefile             |  3 +++
 www/caddy/files/patch-caddy.go | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/www/caddy/Makefile b/www/caddy/Makefile
index 0e1e3bde8cfe..58338dfa1f1d 100644
--- a/www/caddy/Makefile
+++ b/www/caddy/Makefile
@@ -1,6 +1,7 @@
 PORTNAME=	caddy
 DISTVERSIONPREFIX=	v
 DISTVERSION=	2.6.1
+PORTREVISION=	1
 CATEGORIES=	www
 DIST_SUBDIR=	caddy
 
@@ -20,6 +21,8 @@ SUB_FILES=	Caddyfile.sample caddy pkg-message
 PLIST_FILES=	bin/${PORTNAME} \
 		"@sample ${ETCDIR_REL}/Caddyfile.sample"
 
+GO_BUILDFLAGS+=	-ldflags='-X github.com/caddyserver/caddy/v2.VersionString=${DISTVERSIONFULL}'
+
 GO_TARGET=	./cmd/caddy
 # If go.mod is sufficient:
 GO_MODULE=	github.com/caddyserver/caddy/v2
diff --git a/www/caddy/files/patch-caddy.go b/www/caddy/files/patch-caddy.go
new file mode 100644
index 000000000000..bc79644ad6b7
--- /dev/null
+++ b/www/caddy/files/patch-caddy.go
@@ -0,0 +1,25 @@
+--- caddy.go.orig	2022-09-22 16:12:41 UTC
++++ caddy.go
+@@ -824,6 +824,10 @@ func InstanceID() (uuid.UUID, error) {
+ 	return uuid.ParseBytes(uuidFileBytes)
+ }
+ 
++// VersionString uses a predefined version string to short-circuit
++// the Version() function below, to simplify vendor packaging.
++var VersionString string
++
+ // Version returns the Caddy version in a simple/short form, and
+ // a full version string. The short form will not have spaces and
+ // is intended for User-Agent strings and similar, but may be
+@@ -841,6 +845,11 @@ func InstanceID() (uuid.UUID, error) {
+ //
+ // This function is experimental and subject to change or removal.
+ func Version() (simple, full string) {
++	// Use VersionString if provided (eg. through -ldflags -X)
++	if VersionString != "" {
++		return VersionString, VersionString
++	}
++
+ 	// the currently-recommended way to build Caddy involves
+ 	// building it as a dependency so we can extract version
+ 	// information from go.mod tooling; once the upstream



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202209221630.28MGUKZ2070801>