Skip to content

Commit 7f214db

Browse files
fix: use build flags for startup log version (#2551)
1 parent 93951f6 commit 7f214db

9 files changed

Lines changed: 41 additions & 75 deletions

File tree

caddy/app.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var (
2525
optionsMU sync.RWMutex
2626
)
2727

28-
const appBaseOptionCapacity = 8
28+
const appBaseOptionCapacity = 7
2929

3030
// EXPERIMENTAL: RegisterWorkers provides a way for extensions to register frankenphp.Workers
3131
func RegisterWorkers(name, fileName string, num int, wo ...frankenphp.WorkerOption) frankenphp.Workers {
@@ -180,7 +180,6 @@ func (f *FrankenPHPApp) Start() error {
180180
f.opts = append(f.opts,
181181
frankenphp.WithContext(f.ctx),
182182
frankenphp.WithLogger(f.logger),
183-
frankenphp.WithFrankenPHPVersion(frankenPHPVersionFromCaddyCustomVersion(caddy.CustomVersion)),
184183
frankenphp.WithNumThreads(f.NumThreads),
185184
frankenphp.WithMaxThreads(f.MaxThreads),
186185
frankenphp.WithMetrics(f.metrics),

caddy/version.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

caddy/version_test.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

frankenphp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ frankenphp_version frankenphp_get_version() {
8787
};
8888
}
8989

90+
const char *frankenphp_get_frankenphp_version() {
91+
return TOSTRING(FRANKENPHP_VERSION);
92+
}
93+
9094
frankenphp_config frankenphp_get_config() {
9195
return (frankenphp_config){
9296
#ifdef ZTS

frankenphp.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ func Version() PHPVersion {
145145
}
146146
}
147147

148+
func frankenPHPVersion() string {
149+
return C.GoString(C.frankenphp_get_frankenphp_version())
150+
}
151+
148152
func Config() PHPConfig {
149153
cConfig := C.frankenphp_get_config()
150154

@@ -342,7 +346,7 @@ func Init(options ...Option) error {
342346
initAutoScaling(mainThread)
343347

344348
if globalLogger.Enabled(globalCtx, slog.LevelInfo) {
345-
globalLogger.LogAttrs(globalCtx, slog.LevelInfo, startupLogMessage, startupLogAttrs(opt.frankenPHPVersion, Version().Version, mainThread.numThreads, mainThread.maxThreads, maxRequestsPerThread)...)
349+
globalLogger.LogAttrs(globalCtx, slog.LevelInfo, startupLogMessage, startupLogAttrs(Version().Version, mainThread.numThreads, mainThread.maxThreads, maxRequestsPerThread)...)
346350

347351
if EmbeddedAppPath != "" {
348352
globalLogger.LogAttrs(globalCtx, slog.LevelInfo, "embedded PHP app 📦", slog.String("path", EmbeddedAppPath))

frankenphp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ typedef struct frankenphp_version {
179179
unsigned long version_id;
180180
} frankenphp_version;
181181
frankenphp_version frankenphp_get_version();
182+
const char *frankenphp_get_frankenphp_version();
182183

183184
typedef struct frankenphp_config {
184185
bool zts;

options.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ type WorkerOption func(*workerOpt) error
2222
type opt struct {
2323
hotReloadOpt
2424

25-
ctx context.Context
26-
numThreads int
27-
maxThreads int
28-
workers []workerOpt
29-
logger *slog.Logger
30-
frankenPHPVersion string
31-
metrics Metrics
32-
phpIni map[string]string
33-
maxWaitTime time.Duration
34-
maxIdleTime time.Duration
35-
maxRequests int
25+
ctx context.Context
26+
numThreads int
27+
maxThreads int
28+
workers []workerOpt
29+
logger *slog.Logger
30+
metrics Metrics
31+
phpIni map[string]string
32+
maxWaitTime time.Duration
33+
maxIdleTime time.Duration
34+
maxRequests int
3635
}
3736

3837
type workerOpt struct {
@@ -142,15 +141,6 @@ func WithLogger(l *slog.Logger) Option {
142141
}
143142
}
144143

145-
// WithFrankenPHPVersion configures the FrankenPHP version exposed in startup logs.
146-
func WithFrankenPHPVersion(version string) Option {
147-
return func(o *opt) error {
148-
o.frankenPHPVersion = version
149-
150-
return nil
151-
}
152-
}
153-
154144
// WithPhpIni configures user defined PHP ini settings.
155145
func WithPhpIni(overrides map[string]string) Option {
156146
return func(o *opt) error {

startup_log.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const (
1212
startupLogAttrCapacity = 5
1313
)
1414

15-
func startupLogAttrs(frankenPHPVersion string, phpVersion string, numThreads int, maxThreads int, maxRequests int) []slog.Attr {
15+
func startupLogAttrs(phpVersion string, numThreads int, maxThreads int, maxRequests int) []slog.Attr {
1616
attrs := make([]slog.Attr, 0, startupLogAttrCapacity)
17-
if frankenPHPVersion != "" {
18-
attrs = append(attrs, slog.String(startupLogAttrVersion, frankenPHPVersion))
17+
if version := frankenPHPVersion(); version != "" {
18+
attrs = append(attrs, slog.String(startupLogAttrVersion, version))
1919
}
2020

2121
return append(attrs,

startup_log_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package frankenphp
22

3-
import "testing"
3+
import (
4+
"os"
5+
"testing"
6+
)
47

5-
func TestStartupLogAttrsIncludeConfiguredFrankenPHPVersion(t *testing.T) {
8+
const startupLogTestExpectedVersionEnv = "FRANKENPHP_EXPECT_VERSION"
9+
10+
func TestStartupLogAttrsIncludeFrankenPHPVersion(t *testing.T) {
611
const (
7-
expectedFrankenPHPVersion = "1.12.4-test"
8-
testPHPVersion = "8.2.31"
9-
testNumThreads = 4
10-
testMaxThreads = 8
11-
testMaxRequests = 0
12+
testPHPVersion = "8.2.31"
13+
testNumThreads = 4
14+
testMaxThreads = 8
15+
testMaxRequests = 0
1216
)
1317

14-
attrs := startupLogAttrs(expectedFrankenPHPVersion, testPHPVersion, testNumThreads, testMaxThreads, testMaxRequests)
18+
expectedFrankenPHPVersion := os.Getenv(startupLogTestExpectedVersionEnv)
19+
if expectedFrankenPHPVersion == "" {
20+
expectedFrankenPHPVersion = frankenPHPVersion()
21+
}
22+
23+
attrs := startupLogAttrs(testPHPVersion, testNumThreads, testMaxThreads, testMaxRequests)
1524
if len(attrs) == 0 {
1625
t.Fatal("expected startup log attrs")
1726
}

0 commit comments

Comments
 (0)