Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
168 lines (156 loc) · 9.84 KB
/
Copy pathMakefile
File metadata and controls
168 lines (156 loc) · 9.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# KiroCrew — public build targets (pip + npm/vite + pytest).
# Common flow: `make` runs build (frontend + backend) then tests.
#
# Standalone distribution targets:
# make wheel — self-contained pip wheel (dashboard bundled)
# make backend-bin — standalone backend tree (bundled interpreter, no system Python)
# make desktop — double-clickable desktop app (universal DMG on macOS / AppImage on Linux)
# All three take EDITION=oss|enterprise (else $KIROCREW_BUILD_EDITION, else oss).
.PHONY: all build frontend backend test clean wheel backend-bin desktop check-edition
PY ?= python3
# Edition stamped into the built package (src/kiro_crew/edition.py). The
# packaging targets pass it to setup.py's build_py as KIROCREW_BUILD_EDITION;
# the source tree always stays oss. Keep EDITIONS equal to edition.EDITIONS.
# EDITION comes from `EDITION=`, else from KIROCREW_BUILD_EDITION, else oss, so
# `KIROCREW_BUILD_EDITION=enterprise make wheel` cannot quietly build oss.
# check-edition refuses the two when both are set and differ.
# `override` on each edition variable: under `make -e` (or `e` in MAKEFLAGS)
# an environment variable of the same name beats a plain assignment, which
# would let an ambient EDITION, EDITIONS or helper pick or widen the edition.
override EDITIONS := oss enterprise
override _EDITION_ENV := $(strip $(KIROCREW_BUILD_EDITION))
# Only a command-line EDITION= counts: an exported shell EDITION is a generic
# name something else may have set, so it is ignored.
ifneq ($(origin EDITION),command line)
override EDITION := $(if $(_EDITION_ENV),$(_EDITION_ENV),oss)
endif
# Exact string equality; findstring has no % wildcard, unlike filter.
override _edition_eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
VENV := .venv
PIP := $(VENV)/bin/pip
# Build the venv under a umask that masks group/other WRITE so bin/kirocrew is
# born non-group-writable -- `kirocrew service install` refuses to attach its
# AppArmor profile to a group/world-writable launcher (see cli.sh). Caller umask
# OR 022: only ever ADDS write-mask bits, a stricter umask is preserved.
TIGHT_UMASK := umask "$$(printf '%03o' "$$(( $$(umask) | 022 ))")"
PYTEST := $(VENV)/bin/pytest
# Stage website/dist as the served src/kiro_crew/static/dist with the package's
# own stager, through the venv `backend` installed it into: it links
# static/dist to website/dist, keeps that link, or points it at a fresh copy --
# never rm + cp under a running gateway. Not part of `frontend`, so
# `backend-bin` (which copies website/dist itself) needs no Python for it.
STAGE_DIST := $(VENV)/bin/python -m kiro_crew.frontend stage .
all: test
# Build the frontend (npm/vite), install the backend into a local venv, then
# stage the dashboard into the package.
build: frontend backend
$(STAGE_DIST)
frontend:
bash ensure-node.sh || true
# `cat ... || true`, not `cat ... &&`: on a first run where ensure-node.sh
# could not record a bin dir (no network, unsupported platform, or node
# already fine on PATH but the write failed), the marker file is absent and
# `cat` exits 1. With `&&` chaining that non-zero exit aborts the whole
# recipe line, so the target fails before npm is ever reached. An absent
# marker must degrade to "use whatever node is on PATH", not stop the build.
# website/electron is its own npm package (website/package.json declares no
# `workspaces`), so the website/ install in this recipe never reaches it --
# and `npm test` / `npm run check` in website/ then die with MODULE_NOT_FOUND
# on its missing deps. Install it in the same shell, so it reuses the
# node-bin-dir PATH handling, and AFTER `npm run build`, so the desktop-only
# dependency tree cannot block building the dashboard itself (#7226).
cd website && \
NBD="$$(cat "$${KIROCREW_HOME:-$$HOME/.kiro/crew}/node-bin-dir" 2>/dev/null || true)"; \
{ [ -z "$$NBD" ] || export PATH="$$NBD:$$PATH"; }; \
if ! command -v npm >/dev/null 2>&1; then \
echo "ERROR: npm not found. Install Node >= 18 (see ensure-node.sh) and re-run." >&2; \
exit 1; \
fi; \
if [ -f package-lock.json ]; then npm ci --no-audit --no-fund; else npm install --no-audit --no-fund; fi && \
npm run build && \
( cd electron && \
if [ -f package-lock.json ]; then npm ci --no-audit --no-fund; else npm install --no-audit --no-fund; fi )
backend:
bash ensure-python.sh || true
# Same `|| true` reasoning as the frontend target: an absent marker file must
# fall back to $(PY), not abort the recipe. A non-empty `PY=` on the make
# command line is the caller's explicit choice and skips the marker, which
# would otherwise keep winning and make `make backend PY=python3.12` a silent
# no-op -- the same precedence make.ps1 gives `-Py`.
PY="$(if $(and $(filter command line,$(origin PY)),$(strip $(PY))),,$$(cat "$${KIROCREW_HOME:-$$HOME/.kiro/crew}/python-bin" 2>/dev/null || true))"; [ -n "$$PY" ] || PY="$(PY)"; \
if [ -x $(VENV)/bin/python ] && ! $(VENV)/bin/python -c 'import sys; sys.exit(0 if sys.version_info >= (3,12) else 1)'; then \
echo " → recreating $(VENV) (existing interpreter < 3.12)"; rm -rf $(VENV); fi; \
if ! "$$PY" -c 'import sys; sys.exit(0 if sys.version_info >= (3,12) else 1)' 2>/dev/null; then \
echo "ERROR: '$$PY' is not Python >= 3.12 (package requires-python is >=3.12)." >&2; \
echo " Without this gate the venv is built from a too-old interpreter, the" >&2; \
echo " version guard above deletes it on every run, and the install either" >&2; \
echo " backtracks forever or crashes at import. Provision 3.12+ first:" >&2; \
echo " bash ensure-python.sh # or: make backend PY=python3.12" >&2; \
exit 1; \
fi; \
if [ -d $(VENV) ] && [ -n "$$(find $(VENV) $(VENV)/bin -prune \( -perm -g+w -o -perm -o+w \) -print 2>/dev/null)" ]; then \
echo " → recreating $(VENV) (existing tree is group/world-writable)"; rm -rf $(VENV); fi; \
test -x $(VENV)/bin/python || { $(TIGHT_UMASK) && "$$PY" -m venv $(VENV); }
$(TIGHT_UMASK) && $(PIP) install --upgrade pip setuptools wheel
# --prefer-binary: on hosts below the modern manylinux baseline (e.g. Amazon
# Linux 2, glibc 2.26) the newest release of a compiled dep may ship only a
# manylinux_2_28 wheel + an sdist. Without this flag pip picks the newest
# version and builds the sdist from source, which fails (no toolchain / old
# GCC / missing -dev headers). --prefer-binary makes pip take an older
# prebuilt wheel instead. No-op where the newest deps already have a usable
# wheel (macOS, AL2023).
$(TIGHT_UMASK) && KIROCREW_SKIP_FRONTEND=1 $(PIP) install --prefer-binary -e ".[dev]"
# CI parity: also install the PEP 735 dev dependency-group (pins
# jsonschema so the config-validation guard tests actually run).
$(TIGHT_UMASK) && $(PIP) install --group dev
bash packaging/resign-macos-libs.sh $(VENV)/bin/python
test: build
$(PYTEST) -q
# --- Standalone distribution -------------------------------------------------
# Self-contained pip wheel: builds + stages the dashboard, then produces a
# wheel that bundles the SPA (see setup.py BuildWithFrontend + MANIFEST.in).
#
# Runs through the venv the `backend` target provisions rather than a bare
# `$(PY) -m pip install --upgrade build`: on hosts whose system python3 is older
# than 3.12 (Amazon Linux 2023 ships 3.9) that bare form installs `build` into
# the *system* interpreter — mutating it without a venv, and tripping PEP 668
# "externally-managed-environment" where the marker exists. Depending on
# `backend` guarantees a >= 3.12 venv exists first.
wheel: check-edition frontend backend
$(STAGE_DIST)
$(PIP) install --upgrade build
KIROCREW_BUILD_EDITION=$(EDITION) $(VENV)/bin/python -m build --wheel
# Refuse an unknown or conflicting EDITION before any slow build step runs.
# EDITION is the TEXT and EDITIONS the patterns, so `EDITION=%` matches nothing.
# setup.py checks the value again, so a direct `python -m build` or
# build-desktop.sh run is covered too.
check-edition:
$(if $(and $(_EDITION_ENV),$(if $(call _edition_eq,$(_EDITION_ENV),$(EDITION)),,x)),$(error EDITION '$(EDITION)' conflicts with KIROCREW_BUILD_EDITION '$(_EDITION_ENV)'; set one, or set both the same))
$(if $(and $(filter 1,$(words $(EDITION))),$(filter $(EDITIONS),$(EDITION))),,$(error unknown EDITION '$(EDITION)' (want one of: $(EDITIONS))))
@echo "edition: $(EDITION)"
# Standalone backend tree on a bundled python-build-standalone interpreter (no
# system Python needed). Builds the dashboard first; build-desktop.sh embeds
# website/dist in the bundle itself. Host-arch only (UNIVERSAL=0): the standalone backend is a
# local-machine artifact, not a distributable app.
backend-bin: check-edition frontend
KIROCREW_BUILD_EDITION=$(EDITION) UNIVERSAL=0 SKIP_FRONTEND=1 SKIP_ELECTRON=1 bash packaging/build-desktop.sh
# Full double-clickable desktop app. macOS: ONE universal DMG (arm64 + x86_64,
# needs an Apple-Silicon host with Rosetta 2 — see docs/build/desktop-app.md;
# UNIVERSAL=0 for a faster host-arch-only build). Linux: AppImage (host arch).
#
# build-desktop.sh runs `npm ci` / `npm run build` itself, so it needs node on
# PATH. It provisions its own uv + PBS interpreter but NOT node, so bootstrap
# node here — otherwise a first `make desktop` on a node-less host dies at the
# script's npm step instead of installing it like every other target does.
desktop: check-edition
bash ensure-node.sh || true
NBD="$$(cat "$${KIROCREW_HOME:-$$HOME/.kiro/crew}/node-bin-dir" 2>/dev/null || true)"; \
{ [ -z "$$NBD" ] || export PATH="$$NBD:$$PATH"; }; \
KIROCREW_BUILD_EDITION=$(EDITION) bash packaging/build-desktop.sh
clean:
rm -rf build dist *.egg-info src/*.egg-info \
src/kiro_crew/static/dist src/kiro_crew/static/.dist.* website/dist \
website/.dist*.next-* website/.dist*.ready-* website/.dist*.prev-* \
website/electron/backend-dist website/electron/dist \
.pytest_cache .mypy_cache
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true