unity-test: refactor, add configuration options, pkg-config output, and check phase (#388787)

authored by Gaétan Lepage and committed by GitHub bf9aa009 a827f607

+196 -44
+35 -32
pkgs/by-name/in/iniparser/package.nix
··· 10 10 ruby, 11 11 validatePkgConfig, 12 12 testers, 13 + unity-test, 14 + ctestCheckHook, 13 15 }: 14 16 15 17 stdenv.mkDerivation (finalAttrs: { ··· 19 21 src = fetchFromGitLab { 20 22 owner = "iniparser"; 21 23 repo = "iniparser"; 22 - rev = "v${finalAttrs.version}"; 24 + tag = "v${finalAttrs.version}"; 23 25 hash = "sha256-z10S9ODLprd7CbL5Ecgh7H4eOwTetYwFXiWBUm6fIr4="; 24 26 }; 25 27 26 - patches = lib.optionals finalAttrs.finalPackage.doCheck [ 27 - (replaceVars ./remove-fetchcontent-usage.patch { 28 - # Do not let cmake's fetchContent download unity 29 - unitySrc = symlinkJoin { 30 - paths = [ 31 - (fetchFromGitHub { 32 - owner = "throwtheswitch"; 33 - repo = "unity"; 34 - rev = "v2.6.0"; 35 - hash = "sha256-SCcUGNN/UJlu3ALJiZ9bQKxYRZey3cm9QG+NOehp6Ow="; 36 - }) 37 - ]; 38 - postBuild = '' 39 - ln -s ${finalAttrs.src}/test/unity_config.h $out/src/unity_config.h 40 - ''; 41 - }; 42 - }) 43 - ]; 28 + patches = lib.optional finalAttrs.doCheck ( 29 + # 1. Do not fetch the Unity GitHub repository 30 + # 2. Lookup the Unity pkgconfig file 31 + # 3. Get the generate_test_runner.rb file from the Unity share directory 32 + replaceVars ./remove-fetchcontent-usage.patch { 33 + # Get the test generator 34 + UNITY-GENERATE-TEST-RUNNER = "${unity-test}/share/generate_test_runner.rb"; 35 + } 36 + ); 44 37 45 38 nativeBuildInputs = [ 46 39 cmake 47 40 doxygen 48 41 validatePkgConfig 49 - ] ++ lib.optionals finalAttrs.finalPackage.doCheck [ ruby ]; 42 + ]; 50 43 51 - cmakeFlags = [ "-DBUILD_TESTING=${if finalAttrs.finalPackage.doCheck then "ON" else "OFF"}" ]; 52 - 53 - doCheck = false; 44 + cmakeFlags = [ 45 + (lib.cmakeBool "BUILD_TESTING" finalAttrs.doCheck) 46 + ]; 47 + doCheck = true; 48 + nativeCheckInputs = [ 49 + ruby 50 + ctestCheckHook 51 + ]; 52 + checkInputs = [ 53 + ( 54 + (unity-test.override { 55 + supportDouble = true; 56 + }).overrideAttrs 57 + { 58 + doCheck = false; 59 + } 60 + ) 61 + ]; 54 62 55 63 postFixup = '' 56 64 ln -sv $out/include/iniparser/*.h $out/include/ 57 65 ''; 58 66 59 - passthru.tests = { 60 - pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 61 - iniparser-with-tests = finalAttrs.overrideAttrs (_: { 62 - doCheck = true; 63 - }); 64 - }; 67 + passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 65 68 66 - meta = with lib; { 69 + meta = { 67 70 homepage = "https://gitlab.com/iniparser/iniparser"; 68 71 description = "Free standalone ini file parsing library"; 69 72 changelog = "https://gitlab.com/iniparser/iniparser/-/releases/v${finalAttrs.version}"; 70 - license = licenses.mit; 71 - platforms = platforms.unix; 73 + license = lib.licenses.mit; 74 + platforms = lib.platforms.unix; 72 75 pkgConfigModules = [ "iniparser" ]; 73 76 maintainers = [ ]; 74 77 };
+43 -8
pkgs/by-name/in/iniparser/remove-fetchcontent-usage.patch
··· 1 1 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt 2 - index b28d151..33a6bcf 100644 2 + index 0735d27..32c5cdb 100644 3 3 --- a/test/CMakeLists.txt 4 4 +++ b/test/CMakeLists.txt 5 - @@ -28,10 +28,8 @@ set(FETCHCONTENT_QUIET OFF) 5 + @@ -26,16 +26,8 @@ endif() 6 + 7 + set(FETCHCONTENT_QUIET OFF) 6 8 7 - FetchContent_Declare( 8 - unity 9 + -FetchContent_Declare( 10 + - unity 9 11 - GIT_REPOSITORY "https://github.com/throwtheswitch/unity.git" 10 12 - GIT_PROGRESS TRUE 11 13 - PATCH_COMMAND ${CMAKE_COMMAND} -E copy 12 14 - ${CMAKE_CURRENT_LIST_DIR}/unity_config.h ./src/) 13 - + SOURCE_DIR @unitySrc@ 14 - +) 15 + - 16 + -FetchContent_MakeAvailable(unity) 17 + -target_compile_definitions(unity PUBLIC UNITY_INCLUDE_CONFIG_H 18 + - UNITY_USE_COMMAND_LINE_ARGS) 19 + +find_package(PkgConfig REQUIRED) 20 + +pkg_check_modules(UNITY REQUIRED unity) 21 + 22 + function(create_test_runner) 23 + set(options) 24 + @@ -52,7 +44,7 @@ function(create_test_runner) 25 + add_custom_command( 26 + OUTPUT test_${TEST_RUNNER_NAME}_runner.c 27 + COMMAND 28 + - ${RUBY_EXECUTABLE} ${unity_SOURCE_DIR}/auto/generate_test_runner.rb 29 + + @UNITY-GENERATE-TEST-RUNNER@ 30 + ${CMAKE_CURRENT_SOURCE_DIR}/test_${TEST_RUNNER_NAME}.c 31 + test_${TEST_RUNNER_NAME}_runner.c ${CMAKE_CURRENT_LIST_DIR}/unity-config.yml 32 + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test_${TEST_RUNNER_NAME}.c 33 + @@ -62,10 +54,18 @@ function(create_test_runner) 34 + test_${TEST_RUNNER_NAME}_runner.c) 35 + foreach(TARGET_TYPE ${TARGET_TYPES}) 36 + # if BUILD_STATIC_LIBS=ON shared takes precedence 37 + + target_include_directories( 38 + + test_${TEST_RUNNER_NAME} 39 + + PUBLIC 40 + + ${UNITY_INCLUDE_DIRS}) 41 + + target_compile_options( 42 + + test_${TEST_RUNNER_NAME} 43 + + PUBLIC 44 + + ${UNITY_CFLAGS_OTHER}) 45 + target_link_libraries( 46 + test_${TEST_RUNNER_NAME} 47 + ${PROJECT_NAME}-${TARGET_TYPE} 48 + - unity) 49 + + ${UNITY_LIBRARIES}) 50 + endforeach() 51 + endfunction() 15 52 16 - FetchContent_MakeAvailable(unity) 17 - target_compile_definitions(unity PUBLIC UNITY_INCLUDE_CONFIG_H)
+18
pkgs/by-name/un/unity-test/meson.patch
··· 1 + diff --git a/meson.build b/meson.build 2 + index 6585129..9489aef 100644 3 + --- a/meson.build 4 + +++ b/meson.build 5 + @@ -64,10 +64,10 @@ unity_dep = declare_dependency( 6 + if not meson.is_subproject() 7 + pkg = import('pkgconfig') 8 + pkg.generate( 9 + - name: meson.project_name(), 10 + + unity_lib, 11 + version: meson.project_version(), 12 + - libraries: [ unity_lib ], 13 + - description: 'C Unit testing framework.' 14 + + subdirs: 'unity', 15 + + extra_cflags: unity_args, 16 + ) 17 + endif 18 +
+100 -4
pkgs/by-name/un/unity-test/package.nix
··· 2 2 lib, 3 3 stdenv, 4 4 fetchFromGitHub, 5 - cmake, 6 - }: 5 + fetchpatch2, 6 + meson, 7 + ninja, 8 + ruby, 9 + python3Minimal, 10 + nix-update-script, 11 + testers, 12 + iniparser, 13 + validatePkgConfig, 14 + # Adds test groups and extra CLI flags. 15 + buildFixture ? false, 16 + # Adds the ablilty to track malloc and free calls. 17 + # Note that if fixtures are enabled, this option is ignored 18 + # and will always be enabled. 19 + buildMemory ? buildFixture, 20 + # Adds double precision floating point assertions 21 + supportDouble ? false, 7 22 23 + }: 24 + let 25 + # On newer versions of Clang, Weverything is too much of everything. 26 + ignoredErrors = [ 27 + "-Wno-unsafe-buffer-usage" 28 + "-Wno-reserved-identifier" 29 + "-Wno-extra-semi-stmt" 30 + ]; 31 + in 8 32 stdenv.mkDerivation (finalAttrs: { 9 33 pname = "unity-test"; 10 34 version = "2.6.1"; ··· 16 40 hash = "sha256-g0ubq7RxGQmL1R6vz9RIGJpVWYsgrZhsTWSrL1ySEug="; 17 41 }; 18 42 19 - nativeBuildInputs = [ cmake ]; 43 + patches = [ 44 + # The meson file does not have the subdir set correctly 45 + (fetchpatch2 { 46 + url = "https://patch-diff.githubusercontent.com/raw/ThrowTheSwitch/Unity/pull/771.patch"; 47 + hash = "sha256-r8ldVb7WrzVwTC2CtGul9Jk4Rzt+6ejk+paYAfFlR5M="; 48 + }) 49 + # Fix up the shebangs in the auto directory as not all are correct 50 + (fetchpatch2 { 51 + url = "https://patch-diff.githubusercontent.com/raw/ThrowTheSwitch/Unity/pull/790.patch"; 52 + hash = "sha256-K+OxMe/ZMXPPjZXjGhgc5ULLN7plBwL0hV5gwmgA3FM="; 53 + }) 54 + ]; 55 + 56 + postPatch = '' 57 + patchShebangs --build auto 58 + ''; 59 + 60 + outputs = [ 61 + "out" 62 + "dev" 63 + ]; 64 + 65 + strictDeps = true; 66 + nativeBuildInputs = [ 67 + meson 68 + ninja 69 + python3Minimal 70 + validatePkgConfig 71 + ]; 72 + 73 + # For the helper shebangs 74 + buildInputs = [ 75 + python3Minimal 76 + ruby 77 + ]; 78 + 79 + mesonFlags = [ 80 + (lib.mesonBool "extension_memory" buildMemory) 81 + (lib.mesonBool "extension_fixture" buildFixture) 82 + (lib.mesonBool "support_double" supportDouble) 83 + ]; 84 + 20 85 doCheck = true; 21 86 87 + checkPhase = '' 88 + runHook preCheck 89 + 90 + make -C../test -j $NIX_BUILD_CORES ${lib.optionalString stdenv.cc.isClang "CC=clang"} E="-Weverything ${lib.escapeShellArgs ignoredErrors}" test 91 + 92 + runHook postCheck 93 + ''; 94 + 95 + # Various helpers 96 + postInstall = '' 97 + mkdir -p "$out/share" 98 + install -Dm755 ../auto/* -t "$out/share/" 99 + ''; 100 + 101 + passthru = { 102 + updateScript = nix-update-script { }; 103 + tests = { 104 + inherit iniparser; 105 + pkg-config = testers.hasPkgConfigModules { 106 + package = finalAttrs.finalPackage; 107 + versionCheck = true; 108 + }; 109 + }; 110 + }; 111 + 22 112 meta = { 23 113 description = "Unity Unit Testing Framework"; 24 114 homepage = "https://www.throwtheswitch.org/unity"; 115 + changelog = "https://github.com/ThrowTheSwitch/Unity/releases/tag/v${finalAttrs.version}"; 25 116 license = lib.licenses.mit; 26 - maintainers = [ lib.maintainers.i01011001 ]; 117 + platforms = lib.platforms.all; 118 + pkgConfigModules = [ "unity" ]; 119 + maintainers = with lib.maintainers; [ 120 + i01011001 121 + RossSmyth 122 + ]; 27 123 }; 28 124 })