remove-dependencies (#20)
All checks were successful
Build ptprnt / build (push) Successful in 2m10s
All checks were successful
Build ptprnt / build (push) Successful in 2m10s
Reviewed-on: #20
This commit was merged in pull request #20.
This commit is contained in:
162
scripts/build.sh
Executable file
162
scripts/build.sh
Executable file
@@ -0,0 +1,162 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Build script for ptprnt - simplifies common build configurations
|
||||
# Usage: ./scripts/build.sh [release|debug|clean] [options]
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
PROJECT_ROOT="${SCRIPT_PATH}/.."
|
||||
|
||||
# Color output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
print_usage() {
|
||||
echo "Usage: $0 [build-type] [options]"
|
||||
echo ""
|
||||
echo "Build Types:"
|
||||
echo " release Build optimized release version (default)"
|
||||
echo " debug Build debug version with symbols"
|
||||
echo " clean Clean build directories"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --coverage Enable coverage reporting (debug builds only)"
|
||||
echo " --reconfigure Force reconfiguration"
|
||||
echo " --test Run tests after building"
|
||||
echo " -j N Use N parallel jobs (default: auto)"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 # Build release"
|
||||
echo " $0 debug --test # Build debug and run tests"
|
||||
echo " $0 debug --coverage # Build debug with coverage"
|
||||
echo " $0 clean # Clean all build directories"
|
||||
}
|
||||
|
||||
# Default values
|
||||
BUILD_TYPE="release"
|
||||
BUILDDIR="builddir"
|
||||
COVERAGE=false
|
||||
RECONFIGURE=false
|
||||
RUN_TESTS=false
|
||||
JOBS=""
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
release|debug|clean)
|
||||
BUILD_TYPE="$1"
|
||||
shift
|
||||
;;
|
||||
--coverage)
|
||||
COVERAGE=true
|
||||
shift
|
||||
;;
|
||||
--reconfigure)
|
||||
RECONFIGURE=true
|
||||
shift
|
||||
;;
|
||||
--test)
|
||||
RUN_TESTS=true
|
||||
shift
|
||||
;;
|
||||
-j)
|
||||
JOBS="-j $2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Error: Unknown option: $1${NC}"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
cd "${PROJECT_ROOT}"
|
||||
|
||||
# Handle clean
|
||||
if [[ "${BUILD_TYPE}" == "clean" ]]; then
|
||||
echo -e "${YELLOW}Cleaning build directories...${NC}"
|
||||
rm -rf builddir builddir-debug
|
||||
echo -e "${GREEN}Clean complete!${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Set build directory and options based on build type
|
||||
if [[ "${BUILD_TYPE}" == "debug" ]]; then
|
||||
BUILDDIR="builddir-debug"
|
||||
MESON_OPTS="--buildtype=debug"
|
||||
|
||||
if [[ "${COVERAGE}" == true ]]; then
|
||||
MESON_OPTS="${MESON_OPTS} -Db_coverage=true"
|
||||
echo -e "${BLUE}Building debug with coverage enabled${NC}"
|
||||
else
|
||||
echo -e "${BLUE}Building debug version${NC}"
|
||||
fi
|
||||
else
|
||||
BUILDDIR="builddir"
|
||||
MESON_OPTS="--buildtype=release"
|
||||
|
||||
if [[ "${COVERAGE}" == true ]]; then
|
||||
echo -e "${YELLOW}Warning: Coverage is only supported for debug builds, ignoring --coverage${NC}"
|
||||
fi
|
||||
|
||||
if [[ "${RUN_TESTS}" == true ]]; then
|
||||
echo -e "${YELLOW}Warning: Tests are not built for release builds (use debug build for testing)${NC}"
|
||||
RUN_TESTS=false
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}Building release version (tests disabled)${NC}"
|
||||
fi
|
||||
|
||||
# Setup or reconfigure build directory
|
||||
if [[ ! -d "${BUILDDIR}" ]] || [[ "${RECONFIGURE}" == true ]]; then
|
||||
if [[ "${RECONFIGURE}" == true ]]; then
|
||||
echo -e "${YELLOW}Reconfiguring build...${NC}"
|
||||
meson setup "${BUILDDIR}" ${MESON_OPTS} --wipe --reconfigure
|
||||
else
|
||||
echo -e "${YELLOW}Setting up build directory...${NC}"
|
||||
meson setup "${BUILDDIR}" ${MESON_OPTS}
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build
|
||||
echo -e "${YELLOW}Building...${NC}"
|
||||
ninja -C "${BUILDDIR}" ${JOBS}
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}Build successful!${NC}"
|
||||
echo -e "Binary: ${BUILDDIR}/ptprnt"
|
||||
else
|
||||
echo -e "${RED}Build failed!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run tests if requested
|
||||
if [[ "${RUN_TESTS}" == true ]]; then
|
||||
echo -e "${YELLOW}Running tests...${NC}"
|
||||
ninja -C "${BUILDDIR}" test
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}All tests passed!${NC}"
|
||||
else
|
||||
echo -e "${RED}Tests failed!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Show binary info
|
||||
echo ""
|
||||
echo -e "${BLUE}Build Information:${NC}"
|
||||
echo " Build type: ${BUILD_TYPE}"
|
||||
echo " Build dir: ${BUILDDIR}"
|
||||
echo " Binary: $(ls -lh ${BUILDDIR}/ptprnt | awk '{print $5, $9}')"
|
||||
echo ""
|
||||
echo -e "${GREEN}Done!${NC}"
|
||||
@@ -1,29 +1,195 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Coverage report generator for ptprnt
|
||||
# Usage: ./scripts/generate_coverage.sh [options]
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
PROJECT_ROOT="${SCRIPT_PATH}/.."
|
||||
|
||||
# Output paths
|
||||
HTML_COV_PATH="coverageReport/html"
|
||||
XML_COV_PATH="coverageReport/xml"
|
||||
TEXT_COV_PATH="coverageReport"
|
||||
HTML_START_FILE="index.html"
|
||||
|
||||
echo "Generating Coverage report for ptprnt"
|
||||
# Color output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
cd $SCRIPT_PATH/..
|
||||
# Default values - all formats enabled by default
|
||||
GENERATE_HTML=false
|
||||
GENERATE_XML=false
|
||||
GENERATE_TEXT=false
|
||||
BUILDDIR="builddir-debug"
|
||||
|
||||
ninja -C builddir
|
||||
ninja -C builddir test
|
||||
# Common gcovr options
|
||||
GCOVR_OPTS="--filter src --root ."
|
||||
|
||||
mkdir -p ${HTML_COV_PATH}
|
||||
gcovr --html --html-details --html-syntax-highlighting --filter src --output ${HTML_COV_PATH}/${HTML_START_FILE}
|
||||
print_usage() {
|
||||
echo "Usage: $0 [options]"
|
||||
echo ""
|
||||
echo "Coverage Report Generator - generates coverage reports from existing coverage data"
|
||||
echo ""
|
||||
echo "Prerequisites:"
|
||||
echo " Build with coverage enabled first:"
|
||||
echo " ./scripts/build.sh debug --coverage --test"
|
||||
echo ""
|
||||
echo "Format Options (if none specified, all formats are generated):"
|
||||
echo " --html Generate HTML coverage report"
|
||||
echo " --xml Generate XML coverage report (for CI/CD)"
|
||||
echo " --text Generate text coverage report (terminal output)"
|
||||
echo ""
|
||||
echo "Build Options:"
|
||||
echo " --builddir DIR Use custom build directory (default: builddir-debug)"
|
||||
echo ""
|
||||
echo "Other Options:"
|
||||
echo " -h, --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 # Generate all formats (html, xml, text)"
|
||||
echo " $0 --html # Generate only HTML report"
|
||||
echo " $0 --html --text # Generate HTML and text reports"
|
||||
echo " $0 --xml # Generate XML for CI/CD"
|
||||
echo " $0 --builddir builddir # Use release build directory"
|
||||
}
|
||||
|
||||
mkdir -p ${XML_COV_PATH}
|
||||
gcovr --xml-pretty --filter src --output ${XML_COV_PATH}/cov.xml
|
||||
|
||||
if [ $? ]
|
||||
then
|
||||
echo "Coverage report successful generated!"
|
||||
echo "Open: file://${SCRIPT_PATH}/${HTML_COV_PATH}/${HTML_START_FILE}"
|
||||
else
|
||||
echo "Error generating coverage report!"
|
||||
# Parse arguments
|
||||
# If no format arguments provided, enable all
|
||||
if [[ $# -eq 0 ]]; then
|
||||
GENERATE_HTML=true
|
||||
GENERATE_XML=true
|
||||
GENERATE_TEXT=true
|
||||
fi
|
||||
|
||||
rm *.gcov
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--html)
|
||||
GENERATE_HTML=true
|
||||
shift
|
||||
;;
|
||||
--xml)
|
||||
GENERATE_XML=true
|
||||
shift
|
||||
;;
|
||||
--text)
|
||||
GENERATE_TEXT=true
|
||||
shift
|
||||
;;
|
||||
--builddir)
|
||||
BUILDDIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Error: Unknown option: $1${NC}"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if any format was selected when arguments were provided
|
||||
if [[ $GENERATE_HTML == false && $GENERATE_XML == false && $GENERATE_TEXT == false ]]; then
|
||||
echo -e "${RED}Error: No output format specified. Use --html, --xml, and/or --text${NC}"
|
||||
print_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "${PROJECT_ROOT}"
|
||||
|
||||
# Check if build directory exists
|
||||
if [[ ! -d "${BUILDDIR}" ]]; then
|
||||
echo -e "${RED}Error: Build directory '${BUILDDIR}' does not exist${NC}"
|
||||
echo ""
|
||||
echo "Build with coverage enabled first:"
|
||||
echo " ./scripts/build.sh debug --coverage --test"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if coverage data exists by looking for .gcda files
|
||||
if ! find "${BUILDDIR}" -name "*.gcda" -print -quit | grep -q .; then
|
||||
echo -e "${RED}Error: No coverage data found in '${BUILDDIR}'${NC}"
|
||||
echo ""
|
||||
echo "Make sure you built with coverage enabled and ran the tests:"
|
||||
echo " ./scripts/build.sh debug --coverage --test"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}Generating Coverage report for ptprnt${NC}"
|
||||
echo "Build directory: ${BUILDDIR}"
|
||||
echo "Formats: $(${GENERATE_HTML} && echo -n "html ")$(${GENERATE_XML} && echo -n "xml ")$(${GENERATE_TEXT} && echo -n "text")"
|
||||
echo ""
|
||||
|
||||
# Check if gcovr is available
|
||||
if ! command -v gcovr &> /dev/null; then
|
||||
echo -e "${RED}Error: gcovr is not installed${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${GENERATE_HTML}" == true ]]; then
|
||||
echo -e "${YELLOW}Generating HTML coverage report...${NC}"
|
||||
mkdir -p "${HTML_COV_PATH}"
|
||||
gcovr ${GCOVR_OPTS} \
|
||||
--html --html-details --html-syntax-highlighting \
|
||||
--output "${HTML_COV_PATH}/${HTML_START_FILE}"
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}✓ HTML report generated${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}To view HTML report, open:${NC}"
|
||||
echo " file://${SCRIPT_PATH}/../${HTML_COV_PATH}/${HTML_START_FILE}"
|
||||
|
||||
else
|
||||
echo -e "${RED}✗ HTML report failed${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${GENERATE_XML}" == true ]]; then
|
||||
echo -e "${YELLOW}Generating XML coverage report...${NC}"
|
||||
mkdir -p "${XML_COV_PATH}"
|
||||
gcovr ${GCOVR_OPTS} \
|
||||
--xml-pretty \
|
||||
--output "${XML_COV_PATH}/cov.xml"
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}✓ XML report generated${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}To view XML report, open:${NC}"
|
||||
echo " file://${SCRIPT_PATH}/../${XML_COV_PATH}/cov.xml"
|
||||
else
|
||||
echo -e "${RED}✗ XML report failed${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${GENERATE_TEXT}" == true ]]; then
|
||||
echo -e "${YELLOW}Generating text coverage report...${NC}"
|
||||
mkdir -p "${TEXT_COV_PATH}"
|
||||
|
||||
# Save to file
|
||||
gcovr ${GCOVR_OPTS} --output "${TEXT_COV_PATH}/coverage.txt"
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}✓ Text report generated${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}To view TXT report, open:${NC}"
|
||||
echo "file://${SCRIPT_PATH}/../${TEXT_COV_PATH}/coverage.txt"
|
||||
else
|
||||
echo -e "${RED}✗ Text report failed${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Clean up gcov files
|
||||
rm -f *.gcov 2>/dev/null
|
||||
|
||||
# Summary
|
||||
echo ""
|
||||
echo -e "${GREEN}Coverage reports generated successfully!${NC}"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user