Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ SONIC_CONFIG_MAKE_JOBS ?= $(shell nproc)
BMCWEB_HEAD_COMMIT ?= 6926d430
BMCWEB_REPO_URL ?= https://github.com/openbmc/bmcweb.git

# Pinned stdexec SHA. bmcweb's nested sdbusplus pulls stdexec via a wrap
# that defaults to `revision = HEAD`; we override with this fixed SHA so
# builds are reproducible even if upstream moves.
STDEXEC_REVISION ?= fee4d651494014610a277540f209cae56011e47f
STDEXEC_URL ?= https://github.com/NVIDIA/stdexec.git

# Target directory for build artifacts
SONIC_REDFISH_TARGET ?= target/debs/trixie

Expand All @@ -33,6 +39,7 @@ BUILD_DIR := $(REPO_ROOT)/build
TARGET_DIR := $(REPO_ROOT)/$(SONIC_REDFISH_TARGET)
SERIES_FILE := $(PATCHES_DIR)/series
DEBIAN_DIR := $(BMCWEB_DIR)/debian
OEM_EXT_DIR := $(REPO_ROOT)/oem-extension

# Build artifacts
BMCWEB_BINARY := $(BMCWEB_DIR)/build/bmcweb
Expand All @@ -46,7 +53,7 @@ DOCKERFILE_BUILD := $(BUILD_DIR)/Dockerfile.build
MAIN_TARGET := $(BMCWEB_BINARY)
DERIVED_TARGETS := $(BRIDGE_BINARY)

.PHONY: all build clean reset setup-bmcweb copy-patches apply-patches build-bmcweb build-bridge build-bmcweb-native build-bridge-native build-in-docker test unit-test help
.PHONY: all build clean reset setup-bmcweb copy-oem-extension copy-patches apply-patches build-bmcweb build-bridge build-bmcweb-native build-bridge-native build-in-docker test unit-test help

# Recipes in this Makefile share Docker images and the target/ directory, so
# the top-level prereq chain (build → unit-test → test) must run sequentially.
Expand Down Expand Up @@ -136,7 +143,7 @@ build: $(DOCKERFILE_BUILD)

# Build inside Docker (called from Docker container)
# Note: sdbusplus is pre-installed in the Docker image
build-in-docker: setup-bmcweb apply-patches build-bridge-native build-bmcweb-native
build-in-docker: setup-bmcweb copy-oem-extension apply-patches build-bridge-native build-bmcweb-native
@echo " Build inside Docker completed"

# Setup bmcweb source
Expand All @@ -161,14 +168,45 @@ setup-bmcweb:
fi
@echo " bmcweb ready"

# Copy patches to debian/ directory
# Copy OEM extension files into bmcweb source tree before patching.
#
# Path coupling note (do not change one without the other):
# * Headers land in bmcweb/redfish-core/lib/sonic/ — this path is referenced
# by the patch 0003 which #include's "sonic/sonic_oem_redfish.hpp".
# * JSON schemas land in bmcweb/redfish-core/schema/oem/sonic/json-schema/
# — this path, plus the meson.build copied next to it, is referenced by
# the OEM schema registration logic patched into bmcweb's top-level
# meson build. Renaming either side requires updating the patch.
copy-oem-extension: setup-bmcweb
@echo "Copying SONiC OEM extension into bmcweb..."
@mkdir -p $(BMCWEB_DIR)/redfish-core/lib/sonic
@mkdir -p $(BMCWEB_DIR)/redfish-core/schema/oem/sonic/json-schema
@# Use -u (update) so an older OEM file cannot overwrite a newer in-tree
@# copy that a developer may have iterated on inside bmcweb/.
@cp -u $(OEM_EXT_DIR)/sonic/*.hpp $(BMCWEB_DIR)/redfish-core/lib/sonic/
@cp -u $(OEM_EXT_DIR)/schema/json-schema/*.json $(BMCWEB_DIR)/redfish-core/schema/oem/sonic/json-schema/
@cp -u $(OEM_EXT_DIR)/schema/meson.build $(BMCWEB_DIR)/redfish-core/schema/oem/sonic/
@echo " OEM extension files copied"

@# Ensure stdexec.wrap exists in bmcweb subprojects, pinned to a fixed
@# SHA. sdbusplus depends on stdexec but bmcweb does not ship a
@# top-level wrap for it; without this, meson cannot resolve the
@# nested subproject dependency when building from a clean tree.
@# Always overwrite so a stale wrap from a previous build cannot
@# silently keep us on an older / drifting revision.
@echo " Writing pinned stdexec.wrap (revision $(STDEXEC_REVISION))..."
@printf '[wrap-git]\nurl = %s\nrevision = %s\ndepth = 1\n\n[provide]\nstdexec = stdexec_dep\n' \
'$(STDEXEC_URL)' '$(STDEXEC_REVISION)' \
> $(BMCWEB_DIR)/subprojects/stdexec.wrap

# Copy patches to debian/ directory
copy-patches: $(SERIES_FILE)
@echo "Copying patches to debian/ directory ..."
@# Note: Patches will create debian/ directory, so we only copy series file after patches are applied
@echo " Patches will be applied from $(PATCHES_DIR)"

# Apply patches using series file
apply-patches: setup-bmcweb
apply-patches: setup-bmcweb copy-oem-extension
@echo "Applying patches from series file..."
@if [ ! -d "$(BMCWEB_DIR)" ]; then \
echo "Error: bmcweb directory not found"; \
Expand All @@ -195,8 +233,8 @@ apply-patches: setup-bmcweb
fi

# Build bmcweb Debian package
# Dependencies: clean → setup-bmcweb → apply-patches → build-bmcweb
build-bmcweb: clean setup-bmcweb apply-patches
# Dependencies: clean → setup-bmcweb → copy-oem-extension → apply-patches → build-bmcweb
build-bmcweb: clean setup-bmcweb copy-oem-extension apply-patches
@echo "========================================="
@echo "Building bmcweb Debian package"
@echo "========================================="
Expand Down Expand Up @@ -283,7 +321,7 @@ build-bridge: clean
@ls -lh $(TARGET_DIR)/sonic-dbus-bridge* 2>/dev/null || echo " No artifacts found"

# Build bmcweb natively (inside Docker container, no nested Docker)
build-bmcweb-native:
build-bmcweb-native: setup-bmcweb copy-oem-extension apply-patches
@echo "========================================="
@echo "Building bmcweb Debian package (native)"
@echo "========================================="
Expand Down Expand Up @@ -346,7 +384,7 @@ BMCWEB = bmcweb_$(SONIC_REDFISH_VERSION)_$(CONFIGURED_ARCH).deb
BMCWEB_DBG = bmcweb-dbg_$(SONIC_REDFISH_VERSION)_$(CONFIGURED_ARCH).deb

# Main bmcweb package target for sonic-buildimage
$(addprefix $(DEST)/, $(BMCWEB)): $(DEST)/% : setup-bmcweb apply-patches
$(addprefix $(DEST)/, $(BMCWEB)): $(DEST)/% : setup-bmcweb copy-oem-extension apply-patches
# Build bmcweb package using dpkg-buildpackage
pushd $(BMCWEB_DIR)

Expand Down Expand Up @@ -446,9 +484,12 @@ endif
# Unit Tests (C++ / gtest)
# ========================================
# Dumb-and-direct: each tests/unit-tests/<foo>_test.cpp is compiled together
# with sonic-dbus-bridge/src/<foo>.cpp and linked against gtest. Runs inside
# the builder container -- no services, no privileged mode, no new image.
# If libgtest-dev isn't present in the builder image, it's installed on demand.
# with sonic-dbus-bridge/src/<foo>.cpp (when present) and linked against gtest.
# Header-only test targets (no matching src/<foo>.cpp) are compiled standalone
# so they can exercise pure inline / template / declarative-table code.
# Runs inside the builder container -- no services, no privileged mode, no
# new image. If libgtest-dev isn't present in the builder image, it's
# installed on demand.

UNIT_TEST_DIR := $(REPO_ROOT)/tests/unit-tests

Expand All @@ -473,12 +514,16 @@ unit-test:
for t in tests/unit-tests/*_test.cpp; do \
base=\$$(basename \$$t _test.cpp); \
src=sonic-dbus-bridge/src/\$$base.cpp; \
if [ ! -f \$$src ]; then continue; fi; \
if [ -f \$$src ]; then \
extra_src=\$$src; \
else \
extra_src=; \
fi; \
g++ -std=c++20 -Wall -Wextra -g -O0 -pthread \
-I sonic-dbus-bridge/include \
-I /usr/src/googletest/googletest \
-I /usr/src/googletest/googletest/include \
\$$t \$$src \
\$$t \$$extra_src \
/usr/src/googletest/googletest/src/gtest-all.cc \
/usr/src/googletest/googletest/src/gtest_main.cc \
-o /tmp/ut/\$$base || { failed=1; continue; }; \
Expand Down
Loading