Commit c811cf1d authored by Ross Smyth's avatar Ross Smyth
Browse files

iniparser: use unity-test from nixpkgs

parent db1e62b7
Loading
Loading
Loading
Loading
+35 −32
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@
  ruby,
  validatePkgConfig,
  testers,
  unity-test,
  ctestCheckHook,
}:

stdenv.mkDerivation (finalAttrs: {
@@ -19,56 +21,57 @@ stdenv.mkDerivation (finalAttrs: {
  src = fetchFromGitLab {
    owner = "iniparser";
    repo = "iniparser";
    rev = "v${finalAttrs.version}";
    tag = "v${finalAttrs.version}";
    hash = "sha256-z10S9ODLprd7CbL5Ecgh7H4eOwTetYwFXiWBUm6fIr4=";
  };

  patches = lib.optionals finalAttrs.finalPackage.doCheck [
    (replaceVars ./remove-fetchcontent-usage.patch {
      # Do not let cmake's fetchContent download unity
      unitySrc = symlinkJoin {
        paths = [
          (fetchFromGitHub {
            owner = "throwtheswitch";
            repo = "unity";
            rev = "v2.6.0";
            hash = "sha256-SCcUGNN/UJlu3ALJiZ9bQKxYRZey3cm9QG+NOehp6Ow=";
          })
        ];
        postBuild = ''
          ln -s ${finalAttrs.src}/test/unity_config.h $out/src/unity_config.h
        '';
      };
    })
  ];
  patches = lib.optional finalAttrs.doCheck (
    # 1. Do not fetch the Unity GitHub repository
    # 2. Lookup the Unity pkgconfig file
    # 3. Get the generate_test_runner.rb file from the Unity share directory
    replaceVars ./remove-fetchcontent-usage.patch {
      # Get the test generator
      UNITY-GENERATE-TEST-RUNNER = "${unity-test}/share/generate_test_runner.rb";
    }
  );

  nativeBuildInputs = [
    cmake
    doxygen
    validatePkgConfig
  ] ++ lib.optionals finalAttrs.finalPackage.doCheck [ ruby ];

  cmakeFlags = [ "-DBUILD_TESTING=${if finalAttrs.finalPackage.doCheck then "ON" else "OFF"}" ];
  ];

  cmakeFlags = [
    (lib.cmakeBool "BUILD_TESTING" finalAttrs.doCheck)
  ];
  doCheck = true;
  nativeCheckInputs = [
    ruby
    ctestCheckHook
  ];
  checkInputs = [
    (
      (unity-test.override {
        supportDouble = true;
      }).overrideAttrs
      {
        doCheck = false;
      }
    )
  ];

  postFixup = ''
    ln -sv $out/include/iniparser/*.h $out/include/
  '';

  passthru.tests = {
    pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
    iniparser-with-tests = finalAttrs.overrideAttrs (_: {
      doCheck = true;
    });
  };
  passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;

  meta = with lib; {
  meta = {
    homepage = "https://gitlab.com/iniparser/iniparser";
    description = "Free standalone ini file parsing library";
    changelog = "https://gitlab.com/iniparser/iniparser/-/releases/v${finalAttrs.version}";
    license = licenses.mit;
    platforms = platforms.unix;
    license = lib.licenses.mit;
    platforms = lib.platforms.unix;
    pkgConfigModules = [ "iniparser" ];
    maintainers = [ ];
  };
+43 −8
Original line number Diff line number Diff line
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index b28d151..33a6bcf 100644
index 0735d27..32c5cdb 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -28,10 +28,8 @@ set(FETCHCONTENT_QUIET OFF)
@@ -26,16 +26,8 @@ endif()
 
 FetchContent_Declare(
   unity
 set(FETCHCONTENT_QUIET OFF)
 
-FetchContent_Declare(
-  unity
-  GIT_REPOSITORY "https://github.com/throwtheswitch/unity.git"
-  GIT_PROGRESS TRUE
-  PATCH_COMMAND ${CMAKE_COMMAND} -E copy
-                ${CMAKE_CURRENT_LIST_DIR}/unity_config.h ./src/)
+  SOURCE_DIR @unitySrc@
+)
-
-FetchContent_MakeAvailable(unity)
-target_compile_definitions(unity PUBLIC UNITY_INCLUDE_CONFIG_H
-                                        UNITY_USE_COMMAND_LINE_ARGS)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(UNITY REQUIRED unity)
 
 function(create_test_runner)
   set(options)
@@ -52,7 +44,7 @@ function(create_test_runner)
   add_custom_command(
     OUTPUT test_${TEST_RUNNER_NAME}_runner.c
     COMMAND
-      ${RUBY_EXECUTABLE} ${unity_SOURCE_DIR}/auto/generate_test_runner.rb
+      @UNITY-GENERATE-TEST-RUNNER@
       ${CMAKE_CURRENT_SOURCE_DIR}/test_${TEST_RUNNER_NAME}.c
       test_${TEST_RUNNER_NAME}_runner.c ${CMAKE_CURRENT_LIST_DIR}/unity-config.yml
     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test_${TEST_RUNNER_NAME}.c
@@ -62,10 +54,18 @@ function(create_test_runner)
                                           test_${TEST_RUNNER_NAME}_runner.c)
   foreach(TARGET_TYPE ${TARGET_TYPES})
     # if BUILD_STATIC_LIBS=ON shared takes precedence
+    target_include_directories(
+      test_${TEST_RUNNER_NAME}
+      PUBLIC
+      ${UNITY_INCLUDE_DIRS})
+    target_compile_options(
+      test_${TEST_RUNNER_NAME}
+      PUBLIC
+      ${UNITY_CFLAGS_OTHER})
     target_link_libraries(
       test_${TEST_RUNNER_NAME}
       ${PROJECT_NAME}-${TARGET_TYPE}
-      unity)
+      ${UNITY_LIBRARIES})
   endforeach()
 endfunction()
 
 FetchContent_MakeAvailable(unity)
 target_compile_definitions(unity PUBLIC UNITY_INCLUDE_CONFIG_H)
+18 −0
Original line number Diff line number Diff line
diff --git a/meson.build b/meson.build
index 6585129..9489aef 100644
--- a/meson.build
+++ b/meson.build
@@ -64,10 +64,10 @@ unity_dep = declare_dependency(
 if not meson.is_subproject()
   pkg = import('pkgconfig')
   pkg.generate(
-    name: meson.project_name(),
+    unity_lib,
     version: meson.project_version(),
-    libraries: [ unity_lib ],
-    description: 'C Unit testing framework.'
+    subdirs: 'unity',
+    extra_cflags: unity_args,
   )
 endif
 
+100 −4
Original line number Diff line number Diff line
@@ -2,9 +2,33 @@
  lib,
  stdenv,
  fetchFromGitHub,
  cmake,
}:
  fetchpatch2,
  meson,
  ninja,
  ruby,
  python3Minimal,
  nix-update-script,
  testers,
  iniparser,
  validatePkgConfig,
  # Adds test groups and extra CLI flags.
  buildFixture ? false,
  # Adds the ablilty to track malloc and free calls.
  # Note that if fixtures are enabled, this option is ignored
  # and will always be enabled.
  buildMemory ? buildFixture,
  # Adds double precision floating point assertions
  supportDouble ? false,

}:
let
  # On newer versions of Clang, Weverything is too much of everything.
  ignoredErrors = [
    "-Wno-unsafe-buffer-usage"
    "-Wno-reserved-identifier"
    "-Wno-extra-semi-stmt"
  ];
in
stdenv.mkDerivation (finalAttrs: {
  pname = "unity-test";
  version = "2.6.1";
@@ -16,13 +40,85 @@ stdenv.mkDerivation (finalAttrs: {
    hash = "sha256-g0ubq7RxGQmL1R6vz9RIGJpVWYsgrZhsTWSrL1ySEug=";
  };

  nativeBuildInputs = [ cmake ];
  patches = [
    # The meson file does not have the subdir set correctly
    (fetchpatch2 {
      url = "https://patch-diff.githubusercontent.com/raw/ThrowTheSwitch/Unity/pull/771.patch";
      hash = "sha256-r8ldVb7WrzVwTC2CtGul9Jk4Rzt+6ejk+paYAfFlR5M=";
    })
    # Fix up the shebangs in the auto directory as not all are correct
    (fetchpatch2 {
      url = "https://patch-diff.githubusercontent.com/raw/ThrowTheSwitch/Unity/pull/790.patch";
      hash = "sha256-K+OxMe/ZMXPPjZXjGhgc5ULLN7plBwL0hV5gwmgA3FM=";
    })
  ];

  postPatch = ''
    patchShebangs --build auto
  '';

  outputs = [
    "out"
    "dev"
  ];

  strictDeps = true;
  nativeBuildInputs = [
    meson
    ninja
    python3Minimal
    validatePkgConfig
  ];

  # For the helper shebangs
  buildInputs = [
    python3Minimal
    ruby
  ];

  mesonFlags = [
    (lib.mesonBool "extension_memory" buildMemory)
    (lib.mesonBool "extension_fixture" buildFixture)
    (lib.mesonBool "support_double" supportDouble)
  ];

  doCheck = true;

  checkPhase = ''
    runHook preCheck

    make -C../test -j $NIX_BUILD_CORES ${lib.optionalString stdenv.cc.isClang "CC=clang"} E="-Weverything ${lib.escapeShellArgs ignoredErrors}" test

    runHook postCheck
  '';

  # Various helpers
  postInstall = ''
    mkdir -p "$out/share"
    install -Dm755 ../auto/* -t "$out/share/"
  '';

  passthru = {
    updateScript = nix-update-script { };
    tests = {
      inherit iniparser;
      pkg-config = testers.hasPkgConfigModules {
        package = finalAttrs.finalPackage;
        versionCheck = true;
      };
    };
  };

  meta = {
    description = "Unity Unit Testing Framework";
    homepage = "https://www.throwtheswitch.org/unity";
    changelog = "https://github.com/ThrowTheSwitch/Unity/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.mit;
    maintainers = [ lib.maintainers.i01011001 ];
    platforms = lib.platforms.all;
    pkgConfigModules = [ "unity" ];
    maintainers = with lib.maintainers; [
      i01011001
      RossSmyth
    ];
  };
})