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
15 changes: 10 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build and Test

on:
push:
branches: [ main ]
branches: [ master ]
pull_request:
branches: [ main ]
branches: [ master ]

jobs:
build:
Expand All @@ -23,6 +23,7 @@ jobs:
cxxflags: "-g -O0 -Wall -Wextra -m64 -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings -fprofile-arcs -ftest-coverage"
ldflags: "-fprofile-arcs -ftest-coverage -lgcov"
bldprefix: coverage
interprocedural_optimization: "ON"
bname: system_gcc
with_coverage: "ON"
with_memcheck: "OFF"
Expand All @@ -49,6 +50,8 @@ jobs:
cxxflags: ""
ldflags: ""
bldprefix: use_prefix
interprocedural_optimization: "ON"
package_prefix: "test_"
bname: system_gcc
with_coverage: "OFF"
with_memcheck: "OFF"
Expand All @@ -68,13 +71,14 @@ jobs:
shell_tests: "ON"

- name: rel-clang-macos
os: macos-11
os: macos-latest
compiler: clang
scanbuild: ""
cflags: "-O3 -Wall -Wextra -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings"
cxxflags: "-O3 -Wall -Wextra -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings"
ldflags: ""
bldprefix: rel
interprocedural_optimization: "ON"
bname: osx_clang
with_coverage: "OFF"
with_memcheck: "OFF"
Expand All @@ -86,7 +90,7 @@ jobs:
AGENT_BUILDDIRECTORY: ${{ github.workspace }}/NIFTIworkspace
BUILD_SOURCESDIRECTORY: ${{ github.workspace }}
SYSTEM_PULLREQUEST_SOURCEBRANCH: ${{ github.head_ref }}
BUILD_SOURCEBRANCHNAME: ${{ github.head_ref }}
BUILD_SOURCEBRANCHNAME: ${{ github.head_ref || github.ref_name }}
Comment thread
hjmjohnson marked this conversation as resolved.
Resolved
BUILD_BUILDID: ${{ github.run_id }}
SYSTEM_PULLREQUEST_PULLREQUESTNUMBER: ${{ github.event.pull_request.number }}
CTEST_SCRIPT_DIRECTORY: ${{ github.workspace }}/cmake
Expand Down Expand Up @@ -118,6 +122,7 @@ jobs:
echo "WITH_COVERAGE=${{ matrix.with_coverage }}" >> $GITHUB_ENV
echo "WITH_MEMCHECK=${{ matrix.with_memcheck }}" >> $GITHUB_ENV
echo "NIFTI_SHELL_SCRIPT_TESTS=${{ matrix.shell_tests }}" >> $GITHUB_ENV
echo "NIFTI_PACKAGE_PREFIX=${{ matrix.package_prefix }}" >> $GITHUB_ENV
echo "SCANBUILD_EXE=${{ matrix.scanbuild }}" >> $GITHUB_ENV

- name: Show Environment Info
Expand All @@ -131,5 +136,5 @@ jobs:

- name: Run CTest
run: |
eval $SCANBUILD_EXE ctest -S ${CTEST_SCRIPT_DIRECTORY}/travis_dashboard.cmake -V -j 4
eval $SCANBUILD_EXE ctest -S ${CTEST_SCRIPT_DIRECTORY}/github_dashboard.cmake -V -j 4

167 changes: 136 additions & 31 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
# Per-PR build and test matrix; one line per axis:
# os / c_compiler GNU, Clang, and AppleClang (macOS gcc is a clang shim).
# shared BUILD_SHARED_LIBS=ON also enables the install and export test.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Google Carbon] Heads-up on two coverage gaps in this matrix:

  1. install_linking (enabled by shared=ON) currently does not actually test the installed NIFTIConfig.cmake: install_linking_test.sh:37 passes -DCMAKE_MODULE_PATH=../installed/usr/local/share (wrong path) and GIT_REPO_VERSION is 0.0.0.0 (no tags on this repo), so find_package(NIFTI 3) fails in minimal_example_of_downstream_usage and silently falls back to FetchContent git clone-ing upstream NIFTI-Imaging/nifti_clib over the network!
  2. Removing options: [default, all] means no CI job builds the default out-of-the-box cmake -B build configuration (USE_NIFTI2_CODE=ON, USE_NIFTICDF_CODE=ON, USE_CIFTI_CODE=OFF, USE_FSL_CODE=OFF).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4a0d3e0: the matrix now checks out tags (fetch-depth: 0), since the shallow checkout gave version 0.0.0.0 and find_package(NIFTI 3) rejected it; the module path was not the cause, as the installed bin on PATH lets find_package locate the config (locally NIFTI_DIR resolves to the installed tree). A new default job builds a plain cmake -B build with no options.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: the version half is not fixed. This repository has no tags, so fetch-depth: 0 still gives git describe nothing and version 0.0.0.0; the fix is either pushing the upstream release tags here or changing how the version is derived, which needs a maintainer decision. The new default job does cover the plain cmake -B build configuration.

# fslstyle -DFSLSTYLE changes behavior and on-disk output, so both values run.
# build_type one static Debug leg makes the library's assert() sites live.

name: CMake on multiple platforms

on:
Expand All @@ -10,73 +14,174 @@ on:

jobs:
build:
name: ${{ matrix.os }} ${{ matrix.c_compiler }} ${{ matrix.build_type }} shared=${{ matrix.shared }} fslstyle=${{ matrix.fslstyle }}
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, macos-latest]
build_type: [Release]
c_compiler: [gcc, clang]
# 'default' is what a consumer gets with no options; 'all' turns on
# the optional libraries and the FSL parity defines, which are the
# code paths no workflow compiled before.
options: [default, all]
build_type: [Release]
shared: ["OFF", "ON"]
fslstyle: ["OFF", "ON"]
include:
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
# Single Debug leg; FSLSTYLE=ON reaches the asserts behind those defines.
- os: ubuntu-latest
c_compiler: cl
c_compiler: gcc
cpp_compiler: g++
build_type: Debug
shared: "OFF"
fslstyle: "ON"
exclude:
# /usr/bin/gcc on macOS is a clang shim, so this would duplicate the clang leg.
- os: macos-latest
c_compiler: gcc

steps:
- uses: actions/checkout@v4
with:
# Tags set the version that install_linking's find_package(NIFTI 3) checks.
fetch-depth: 0

- name: Install optional dependencies
# cifti needs expat; only the 'all' configuration builds it.
if: runner.os == 'Linux' && matrix.options == 'all'
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libexpat1-dev zlib1g-dev

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
${{ matrix.options == 'all' && '-DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON -DFSLSTYLE=ON' || '' }}
-DBUILD_SHARED_LIBS=${{ matrix.shared }}
-DUSE_CIFTI_CODE=ON
-DUSE_FSL_CODE=ON
-DFSLSTYLE=${{ matrix.fslstyle }}
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }} --output-on-failure

default:
# What a consumer gets from a plain "cmake -B build" with no options.
name: default configuration (no options)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure CMake
run: cmake -B ${{ github.workspace }}/build -S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ github.workspace }}/build
- name: Test
working-directory: ${{ github.workspace }}/build
run: ctest --output-on-failure

minimal:
# The core-reader-only configuration a vendoring project selects.
name: minimal configuration (znzlib + niftilib only)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure CMake
run: >
cmake -B ${{ github.workspace }}/build
-DCMAKE_BUILD_TYPE=Release
-DUSE_NIFTI2_CODE=OFF
-DUSE_NIFTICDF_CODE=OFF
-DUSE_CIFTI_CODE=OFF
-DUSE_FSL_CODE=OFF
-DNIFTI_BUILD_APPLICATIONS=OFF
-DDOWNLOAD_TEST_DATA=OFF
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ github.workspace }}/build
- name: Test
working-directory: ${{ github.workspace }}/build
# No tests are registered without the applications; the job checks configure and build.
run: ctest --output-on-failure --no-tests=ignore

oldest-cmake:
# Builds with the cmake_minimum_required release; the data tests need FetchContent (3.11).
name: oldest supported CMake (3.10.2, tests without data)
runs-on: ubuntu-24.04
env:
CMAKE_OLDEST: 3.10.2
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libexpat1-dev zlib1g-dev
- name: Install CMake ${{ env.CMAKE_OLDEST }}
run: |
curl -sSfL -o "$RUNNER_TEMP/cmake.tar.gz" \
"https://github.com/Kitware/CMake/releases/download/v${CMAKE_OLDEST}/cmake-${CMAKE_OLDEST}-Linux-x86_64.tar.gz"
tar -xzf "$RUNNER_TEMP/cmake.tar.gz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/cmake-${CMAKE_OLDEST}-Linux-x86_64/bin" >> "$GITHUB_PATH"
- name: Show CMake version
run: cmake --version | grep -F "cmake version ${CMAKE_OLDEST}"
- name: Configure CMake
run: >
cmake -B${{ github.workspace }}/build
-H${{ github.workspace }}
-DCMAKE_BUILD_TYPE=Release
-DUSE_CIFTI_CODE=ON
-DUSE_FSL_CODE=ON
-DDOWNLOAD_TEST_DATA=OFF
- name: Build
run: cmake --build ${{ github.workspace }}/build -- -j4
- name: Test
working-directory: ${{ github.workspace }}/build
run: ctest --output-on-failure -LE NEEDS_DATA

exported-symbols:
# An intended ABI change updates the baseline in the same commit, so review sees it.
name: exported symbol baseline
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libexpat1-dev zlib1g-dev ninja-build
- name: Configure CMake
run: >
cmake -G Ninja -B ${{ github.workspace }}/build
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=ON
-DUSE_CIFTI_CODE=ON
-DUSE_FSL_CODE=ON
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ github.workspace }}/build
- name: Collect exported symbols
run: |
sh cmake/collect_exported_symbols.sh \
"${{ github.workspace }}/build" \
/tmp/exported_symbols.txt
- name: Compare against the committed baseline
run: |
if ! diff -u cmake/exported_symbols_linux.txt /tmp/exported_symbols.txt; then
echo ""
echo "The exported symbol set changed."
echo "If that is intended, update cmake/exported_symbols_linux.txt"
echo "in this commit so the ABI change is visible in review:"
echo " sh cmake/collect_exported_symbols.sh <build-dir> cmake/exported_symbols_linux.txt"
exit 1
fi
echo "Exported symbols match the baseline."
2 changes: 2 additions & 0 deletions cifti/afni_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ int axml_free_xlist(afni_xml_list * axlist);

char * axml_attr_value(afni_xml_t * ax, const char * name);
int axml_recur(int(*func)(FILE*,afni_xml_t*,int), afni_xml_t * ax);
afni_xml_t * axml_recur_find_xml(int (*func)(afni_xml_t *, int), afni_xml_t * ax,
int depth, int max_depth);


/* control API */
Expand Down
60 changes: 60 additions & 0 deletions cmake/collect_exported_symbols.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
# Collect the dynamic symbols exported by the built shared libraries.
# Linux/ELF only: it reads lib*.so with GNU nm -D.
#
# collect_exported_symbols.sh <build-dir> <output-file>
#
# The output is sorted "<library> <symbol>" lines, so a diff against the
# committed baseline names both the library and the symbol that moved.
#
# The library name is reported with any version suffix stripped, so a
# SOVERSION bump does not rewrite every line of the baseline:
# libniftiio.so.3.0.0 is reported as libniftiio.so.
#
# Regenerate the baseline after an intended ABI change:
# cmake -B build -DBUILD_SHARED_LIBS=ON -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
# cmake --build build
# sh cmake/collect_exported_symbols.sh build cmake/exported_symbols_linux.txt

set -eu

if [ $# -ne 2 ]; then
echo "usage: $0 <build-dir> <output-file>" >&2
exit 2
fi

build_dir=$1
output=$2

if [ ! -d "$build_dir" ]; then
echo "$0: no such build directory: $build_dir" >&2
exit 1
fi

# Match versioned sonames too (libfoo.so.3.0.0), and resolve symlinks so
# libfoo.so -> libfoo.so.3.0.0 is not counted twice.
find "$build_dir" -name 'lib*.so*' -exec readlink -f {} \; \
| LC_ALL=C sort -u > "$output.libs"

if [ ! -s "$output.libs" ]; then
rm -f "$output.libs"
echo "$0: no shared libraries under $build_dir;" \
"configure with -DBUILD_SHARED_LIBS=ON" >&2
exit 1
fi

: > "$output.tmp"

# nm writes to a file, not a pipe, so set -e sees its exit status.
while IFS= read -r lib; do
name=$(basename "$lib" | sed -E 's/\.so(\.[0-9]+)*$/.so/')
nm -D --defined-only "$lib" > "$output.nm"
awk -v name="$name" 'NF >= 3 && $3 != "" { print name, $3 }' \
"$output.nm" >> "$output.tmp"
done < "$output.libs"

LC_ALL=C sort -u "$output.tmp" > "$output"
rm -f "$output.tmp" "$output.nm" "$output.libs"

echo "$0: wrote $(wc -l < "$output") symbols from" \
"$(awk '{print $1}' "$output" | LC_ALL=C sort -u | wc -l) libraries to $output"
Loading
Loading