Skip to content

Commit 5f3275d

Browse files
committed
refactor: build hierarchy for codec
- Separate codec build Makefile and README instructions into the j2735codec folder. - Update CI build process to reflet new structure.
1 parent 0b03626 commit 5f3275d

File tree

5 files changed

+402
-417
lines changed

5 files changed

+402
-417
lines changed

.github/workflows/ci-release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ jobs:
4141
- name: Compile
4242
run: |
4343
source emsdk/emsdk_env.sh
44+
cd j2735codec
4445
make wasm
4546
# Create __init__.py files
46-
touch j2735codec/bindings/python/src/j2735codec/generated/__init__.py
47-
touch j2735codec/bindings/python/src/j2735codec/protobuf/__init__.py
47+
touch bindings/python/src/j2735codec/generated/__init__.py
48+
touch bindings/python/src/j2735codec/protobuf/__init__.py
4849
4950
- name: Upload Python Artifacts
5051
uses: actions/upload-artifact@v4

Makefile

Lines changed: 5 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -1,228 +1,8 @@
1-
# SPDX-FileCopyrightText: 2025 Verizon
2-
# SPDX-License-Identifier: Apache-2.0
3-
4-
# --- Colors and Styles ---
5-
ifeq ($(shell tput colors 2>/dev/null), 256)
6-
RED := $(shell tput setaf 1)
7-
YELLOW := $(shell tput setaf 3)
8-
GREEN := $(shell tput setaf 2)
9-
BOLD := $(shell tput bold)
10-
RESET := $(shell tput sgr0)
11-
else
12-
RED := ""
13-
YELLOW := ""
14-
GREEN := ""
15-
BOLD := ""
16-
RESET := ""
17-
endif
18-
19-
# --- Detection ---
20-
PYTHON_CMD := $(shell which python3 || which python)
21-
ifeq ($(PYTHON_CMD),)
22-
PYTHON_INSTALLED := false
23-
else
24-
PYTHON_INSTALLED := true
25-
PYTHON := $(PYTHON_CMD)
26-
IS_VENV := $(shell $(PYTHON) -c 'import sys; print("true" if sys.prefix != sys.base_prefix else "false")')
27-
endif
28-
29-
NPM := $(shell which npm)
30-
CMAKE := $(shell which cmake)
31-
UV := $(shell which uv)
32-
33-
# --- Variables ---
34-
PROJECT_ROOT := $(shell pwd)
35-
BUILD_DIR_NATIVE = j2735codec/build_native
36-
BUILD_DIR_WASM = j2735codec/build_wasm
37-
38-
DIST_DIR = j2735codec/dist
39-
40-
BINDING_PY = j2735codec/bindings/python
41-
PY_DIST_DIR = $(BINDING_PY)/dist
42-
43-
BINDING_JS = j2735codec/bindings/node
44-
JS_DIST_DIR = $(BINDING_JS)/dist
45-
46-
J2735_REV ?= j2735_202409
47-
THREADS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
48-
49-
SAMPLE_PY = etx/examples/python
50-
51-
SAMPLE_JS = etx/examples/node
52-
53-
VERSION ?= $(shell cat VERSION 2>/dev/null || echo "0.1.0")
54-
55-
# --- Targets ---
56-
57-
.PHONY: all setup native wasm purge help \
58-
setup-py build-py install-py test-py clean-py uninstall-py \
59-
setup-js build-js install-js test-js clean-js sync-version
60-
61-
help:
62-
@echo "$(BOLD)ETX Starter Kit Management:$(RESET)"
63-
@echo " $(BOLD)make setup$(RESET) - Sync all dependencies (Frozen/Locked)"
64-
@echo " $(BOLD)make install-py$(RESET) - Full Python lifecycle (Build -> Test Wheel)"
65-
@echo " $(BOLD)make install-js$(RESET) - Full Node.js lifecycle (Build -> Test Tarball)"
66-
@echo " $(BOLD)make native$(RESET) - Build native C library"
67-
@echo " $(BOLD)make wasm$(RESET) - Build WASM & Generate Enums"
68-
@echo " $(BOLD)make purge$(RESET) - Hard reset of all artifacts and lockfiles"
69-
70-
all: sync-version setup native wasm build-py build-js
71-
72-
setup: setup-py setup-js
73-
74-
# --- Environment Guard ---
75-
76-
check-env:
77-
ifeq ($(PYTHON_INSTALLED), false)
78-
@echo "$(RED)$(BOLD)❌ ERROR: Python not found!$(RESET)"; exit 1
79-
endif
80-
ifeq ($(NPM),)
81-
@echo "$(RED)$(BOLD)❌ ERROR: npm not found!$(RESET)"; exit 1
82-
endif
83-
84-
# --- Python Workflow ---
85-
86-
setup-py: check-env
87-
@echo "🛠️ Syncing Python dependencies (Frozen)..."
88-
ifdef UV
89-
$(UV) sync --all-packages --frozen --quiet
90-
else
91-
$(PYTHON) -m pip install --upgrade pip build pytest psutil
92-
$(PYTHON) -m pip install -e $(BINDING_PY)
93-
endif
94-
95-
uninstall-py:
96-
@echo "🗑️ Uninstalling j2735codec package..."
97-
@if [ -d ".venv" ]; then \
98-
if [ -n "$(UV)" ]; then $(UV) pip uninstall j2735codec 2>/dev/null || true; \
99-
else $(PYTHON) -m pip uninstall -y j2735codec 2>/dev/null || true; fi \
100-
fi
101-
102-
build-py: wasm setup-py
103-
@echo "📦 Packaging Python Wheel..."
104-
ifdef UV
105-
$(UV) build --package j2735codec --wheel --out-dir $(PY_DIST_DIR)
106-
else
107-
$(PYTHON) -m build $(BINDING_PY) --outdir $(PY_DIST_DIR)
108-
endif
109-
110-
test-py: setup-py
111-
@echo "🧪 Running pytest..."
112-
ifdef UV
113-
$(UV) run python -m pytest $(BINDING_PY)/tests -s
114-
else
115-
$(PYTHON) -m pytest $(BINDING_PY)/tests -s
116-
endif
117-
118-
install-py: uninstall-py clean-py wasm
119-
@echo "$(BOLD)🧪 Phase 1: Testing Local Source...$(RESET)"
120-
@$(MAKE) test-py
121-
@echo "$(BOLD)🔨 Phase 2: Building Wheel...$(RESET)"
122-
@$(MAKE) build-py
123-
@WHEEL_PATH=$$(ls $(PY_DIST_DIR)/*.whl | head -n 1); \
124-
echo "$(BOLD)📦 Phase 3: Installing $$WHEEL_PATH...$(RESET)"; \
125-
if [ -n "$(UV)" ]; then $(UV) pip install $$WHEEL_PATH; \
126-
else $(PYTHON) -m pip install $$WHEEL_PATH; fi
127-
@echo "$(BOLD)🧪 Phase 4: Integration Test (Clean-Room)...$(RESET)"
128-
@TEMP_DIR=$$(mktemp -d); \
129-
echo "Temp Test Directory: $$TEMP_DIR"; \
130-
cp -r $(BINDING_PY)/tests $$TEMP_DIR/tests; \
131-
mkdir -p $$TEMP_DIR/tests/samples; \
132-
cp -r $(PROJECT_ROOT)/j2735codec/core/$(J2735_REV)/samples/jer/* $$TEMP_DIR/tests/samples/; \
133-
cd $$TEMP_DIR; \
134-
echo "Contents of temp directory:"; \
135-
ls -R; \
136-
if [ -n "$(UV)" ]; then \
137-
$(UV) init; \
138-
$(UV) venv; \
139-
WHEEL_PATH=$$(realpath $(PROJECT_ROOT)/$(BINDING_PY)/dist/*.whl | head -n1); \
140-
$(UV) pip install --upgrade pip pytest psutil $$WHEEL_PATH; \
141-
$(UV) run python -m pytest tests -s; \
142-
else \
143-
$(PYTHON) -m pip install --upgrade pip pytest; \
144-
$(PYTHON) -m pytest tests -s; \
145-
fi; \
146-
rm -rf $$TEMP_DIR; \
147-
echo "$(GREEN)$(BOLD)✅ Success: Python Wheel verified in isolation.$(RESET)"
148-
149-
clean-py:
150-
rm -rf $(PY_DIST_DIR) $(BINDING_PY)/*.egg-info
151-
find $(BINDING_PY) -type d -name "__pycache__" -exec rm -rf {} +
152-
153-
# --- Node Workflow ---
154-
155-
setup-js: check-env
156-
@echo "📦 Syncing Node.js workspaces (Frozen/ci)..."
157-
@$(NPM) ci
158-
159-
build-js: wasm setup-js
160-
@echo "🔨 Building Node Bindings..."
161-
@$(NPM) run build -w j2735codec
162-
163-
test-js: setup-js
164-
@echo "🧪 Running Vitest..."
165-
@$(NPM) test -w j2735codec
166-
167-
clean-js:
168-
@echo "🧹 Cleaning Node artifacts..."
169-
@rm -rf $(JS_DIST_DIR)
170-
@find $(BINDING_JS) -name "*.tgz" -delete
171-
@find . -type d -name "node_modules" -exec rm -rf {} +
172-
173-
install-js: clean-js build-js
174-
@echo "$(BOLD)🧪 Phase 1: Local Source Test...$(RESET)"
175-
@$(MAKE) test-js
176-
@echo "$(BOLD)🔨 Phase 2: Packaging Tarball...$(RESET)"
177-
@cd $(BINDING_JS) && $(NPM) pack > /dev/null
178-
@echo "$(BOLD)📦 Phase 3: Isolated Integration Test...$(RESET)"
179-
@TARBALL_PATH=$$(ls $(BINDING_JS)/*.tgz | head -n 1); \
180-
FULL_TARBALL_PATH=$$(pwd)/$$TARBALL_PATH; \
181-
TEMP_DIR=$$(mktemp -d); \
182-
echo "Temp Test Directory: $$TEMP_DIR"; \
183-
( \
184-
cd $$TEMP_DIR && \
185-
$(NPM) init -y > /dev/null && \
186-
echo "📦 Installing tarball..." && \
187-
$(NPM) install $$FULL_TARBALL_PATH > /dev/null && \
188-
$(NPM) install vitest --no-save > /dev/null && \
189-
cp -r $(PROJECT_ROOT)/$(BINDING_JS)/tests ./tests && \
190-
mkdir -p samples && \
191-
cp -r $(PROJECT_ROOT)/j2735codec/core/$(J2735_REV)/samples/jer/* ./samples/ && \
192-
echo "$(BOLD)🚀 Verifying tarball in isolation...$(RESET)" && \
193-
$(NPM) exec vitest run -- --environment node --dir ./tests \
194-
) || (rm -rf $$TEMP_DIR && exit 1); \
195-
rm -rf $$TEMP_DIR; \
196-
echo "$(GREEN)$(BOLD)✅ Success: Node Tarball verified.$(RESET)"
197-
198-
# --- C++ / WASM Logic ---
199-
200-
native:
201-
$(CMAKE) -B $(BUILD_DIR_NATIVE) -S j2735codec -DBUILD_NATIVE_LIB=ON
202-
$(CMAKE) --build $(BUILD_DIR_NATIVE) -j $(THREADS)
203-
204-
wasm:
205-
emcmake $(CMAKE) -B $(BUILD_DIR_WASM) -S j2735codec -DJ2735_REV=$(J2735_REV)
206-
$(CMAKE) --build $(BUILD_DIR_WASM) -j $(THREADS)
207-
208-
purge: uninstall-py clean-py clean-js
209-
@echo "🔥 Hard purging all artifacts and lockfiles..."
210-
# 1. Remove specific known directories
211-
rm -rf $(BUILD_DIR_NATIVE) $(BUILD_DIR_WASM) node_modules $(DIST_DIR)
212-
rm -rf $(BINDING_PY)/src/j2735codec/generated
213-
rm -rf $(BINDING_JS)/src/generated
214-
215-
# 2. Find and remove all .venv directories in the project
216-
find . -type d -name ".venv" -exec rm -rf {} +
217-
218-
# 3. Find and remove other common python artifacts
219-
find . -type d -name "build" -not -path "*/emsdk/*" -exec rm -rf {} +
220-
find . -type d -name "*.egg-info" -exec rm -rf {} +
221-
find . -type d -name ".pytest_cache" -exec rm -rf {} +
222-
223-
@echo "✨ Purged. Use 'make setup' to recreate environment."
224-
225-
# --- Versioning Logic ---
1+
BINDING_PY = j2735codec/bindings/python
2+
BINDING_JS = j2735codec/bindings/node
3+
SAMPLE_PY = etx/examples/python
4+
SAMPLE_JS = etx/examples/node
5+
VERSION ?= $(shell cat VERSION 2>/dev/null || echo "0.1.0")
2266

2277
sync-version:
2288
@echo "🔄 Syncing version $(VERSION) to manifests..."

0 commit comments

Comments
 (0)