fix(build): make dev-prod-db honor env KANDEV_DATABASE_PATH / KANDEV_HOME_DIR (#2834)

Co-authored-by: Joao Manso <X363081@bcpcorp.net>
Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
This commit is contained in:
João Manso
2026-08-20 11:08:18 +01:00
committed by GitHub
parent aa9d9fd5f1
commit 84a132399d
2 changed files with 140 additions and 3 deletions
+25 -3
View File
@@ -96,7 +96,7 @@ help:
@echo " dev Run backend + web via the native Go launcher (auto ports)"
@echo " dev PORT=38430 WEB_PORT=37430 PORT beats KANDEV_BACKEND_PORT/KANDEV_PORT, WEB_PORT beats KANDEV_WEB_PORT"
@echo " dev DEV_ARGS='--verbose' Pass extra flags through to the native launcher"
@echo " dev-prod-db Run dev mode against the production db at ~/.kandev"
@echo " dev-prod-db Run dev mode against the production db (KANDEV_DATABASE_PATH, else KANDEV_HOME_DIR, else ~/.kandev)"
@echo " dev-backend Run backend in development mode (port 38429)"
@echo " dev-web Run web app in development mode (port 37429)"
@echo " desktop-dev Run macOS Tauri app in dev mode with bundled runtime"
@@ -201,9 +201,30 @@ dev: doctor
@exec $(BACKEND_DIR)/bin/kandev-launcher$(EXE) dev $(DEV_FLAGS)
.PHONY: dev-prod-db
dev-prod-db: export KANDEV_DATABASE_PATH := $(HOME)/.kandev/data/kandev.db
# Resolve the production db the way the launcher would
# (resolveDatabasePath/resolveHomeDir in apps/backend/internal/launcher/constants.go):
# an environment KANDEV_DATABASE_PATH wins, then KANDEV_HOME_DIR, then
# $HOME/.kandev. A plain makefile assignment outranks the environment in GNU
# Make, so the earlier `:=` of the $HOME default ignored a relocated install and
# ran dev mode against the wrong db while the launcher still reported backing up
# the production one.
#
# `?=` does not express this either: Make counts a variable the shell exported
# blank as defined, so `?=` would forward that blank onward and the launcher —
# which trims before testing for empty — would quietly fall back to the isolated
# .kandev-dev db while this target announced production.
#
# $(if $(strip …),…) tests emptiness on the trimmed value but substitutes the
# original, so a blank falls through to the next source while a real path keeps
# the internal spaces $(strip …) would otherwise collapse. Export the Make
# variable so both environment and command-line assignments reach $(shell).
# Trim only the outer padding before the database suffix is appended.
export KANDEV_HOME_DIR
KANDEV_PROD_HOME_DIR := $(if $(strip $(KANDEV_HOME_DIR)),$(shell printf '%s' "$$KANDEV_HOME_DIR" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$$//'),$(HOME)/.kandev)
KANDEV_PROD_DB_PATH := $(if $(strip $(KANDEV_DATABASE_PATH)),$(KANDEV_DATABASE_PATH),$(KANDEV_PROD_HOME_DIR)/data/kandev.db)
dev-prod-db: export KANDEV_DATABASE_PATH := $(KANDEV_PROD_DB_PATH)
dev-prod-db:
@echo "⚠ dev mode against PRODUCTION db at $(KANDEV_DATABASE_PATH)"
@echo "⚠ dev mode against PRODUCTION db at $(KANDEV_PROD_DB_PATH)"
@$(MAKE) dev
.PHONY: dev-backend
@@ -540,6 +561,7 @@ test-scripts:
@python3 .github/scripts/lint-action-pinning_test.py
@bash scripts/pr-state.test.sh
@bash scripts/run-quiet.test.sh
@bash scripts/dev-prod-db-path.test.sh
@bash scripts/opencode-code-review.test.sh
@python3 scripts/opencode-code-review.test.py
@python3 scripts/lint-harness-files.test.py