From 46ec69a483576ce095f1fde14583f174cdee2e8c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 27 Jun 2024 18:09:32 -0400 Subject: [PATCH] Everything builds in the dev shell now --- flake.nix | 4 ++ packaging/components.nix | 8 +-- src/libexpr-c/package.nix | 2 +- src/libexpr-test/meson.build | 3 + src/libexpr/package.nix | 2 +- src/libfetchers-test/package.nix | 111 +++++++++++++++++++++++++++++++ src/libflake-test/package.nix | 111 +++++++++++++++++++++++++++++++ src/libstore-c/package.nix | 2 +- src/libstore-test/meson.build | 3 + 9 files changed, 238 insertions(+), 8 deletions(-) create mode 100644 src/libfetchers-test/package.nix create mode 100644 src/libflake-test/package.nix diff --git a/flake.nix b/flake.nix index ba526a9b8..fc46ef940 100644 --- a/flake.nix +++ b/flake.nix @@ -334,6 +334,10 @@ ++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) pkgs.buildPackages.clang-tools; buildInputs = attrs.buildInputs or [] + ++ [ + pkgs.gtest + pkgs.rapidcheck + ] ++ lib.optional havePerl pkgs.perl ; }); diff --git a/packaging/components.nix b/packaging/components.nix index 97b989f1f..5576877cb 100644 --- a/packaging/components.nix +++ b/packaging/components.nix @@ -8,28 +8,26 @@ in nix = callPackage ../package.nix { }; nix-util = callPackage ../src/libutil/package.nix { }; + nix-util-c = callPackage ../src/libutil-c/package.nix { }; nix-util-test-support = callPackage ../src/libutil-test-support/package.nix { }; nix-util-test = callPackage ../src/libutil-test/package.nix { }; - nix-util-c = callPackage ../src/libutil-c/package.nix { }; nix-store = callPackage ../src/libstore/package.nix { }; + nix-store-c = callPackage ../src/libstore-c/package.nix { }; nix-store-test-support = callPackage ../src/libstore-test-support/package.nix { }; nix-store-test = callPackage ../src/libstore-test/package.nix { }; - nix-store-c = callPackage ../src/libstore-c/package.nix { }; nix-fetchers = callPackage ../src/libfetchers/package.nix { }; nix-fetchers-test = callPackage ../src/libfetchers-test/package.nix { }; - nix-fetchers-c = callPackage ../src/libfetchers-c/package.nix { }; nix-expr = callPackage ../src/libexpr/package.nix { }; + nix-expr-c = callPackage ../src/libexpr-c/package.nix { }; nix-expr-test-support = callPackage ../src/libexpr-test-support/package.nix { }; nix-expr-test = callPackage ../src/libexpr-test/package.nix { }; - nix-expr-c = callPackage ../src/libexpr-c/package.nix { }; nix-flake = callPackage ../src/libflake/package.nix { }; nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { }; - nix-external-api-docs = callPackage ../src/external-api-docs/package.nix { }; nix-perl-bindings = callPackage ../src/perl/package.nix { }; diff --git a/src/libexpr-c/package.nix b/src/libexpr-c/package.nix index ce86780c1..542be064d 100644 --- a/src/libexpr-c/package.nix +++ b/src/libexpr-c/package.nix @@ -41,7 +41,7 @@ mkDerivation (finalAttrs: { root = ./.; fileset = fileset.unions [ ./meson.build - ./meson.options + # ./meson.options (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) (fileset.fileFilter (file: file.hasExt "h") ./.) diff --git a/src/libexpr-test/meson.build b/src/libexpr-test/meson.build index e5bb771e3..cc32b0a1a 100644 --- a/src/libexpr-test/meson.build +++ b/src/libexpr-test/meson.build @@ -39,6 +39,9 @@ deps_private += rapidcheck gtest = dependency('gtest', main : true) deps_private += gtest +gtest = dependency('gmock') +deps_private += gtest + add_project_arguments( # TODO(Qyriad): Yes this is how the autoconf+Make system did it. # It would be nice for our headers to be idempotent instead. diff --git a/src/libexpr/package.nix b/src/libexpr/package.nix index 799368ee9..14fbf0a06 100644 --- a/src/libexpr/package.nix +++ b/src/libexpr/package.nix @@ -85,7 +85,7 @@ mkDerivation (finalAttrs: { ''; mesonFlags = [ - (lib.mesonFeature "gc" enableGC) + (lib.mesonEnable "gc" enableGC) ]; env = { diff --git a/src/libfetchers-test/package.nix b/src/libfetchers-test/package.nix new file mode 100644 index 000000000..f4d3f3b73 --- /dev/null +++ b/src/libfetchers-test/package.nix @@ -0,0 +1,111 @@ +{ lib +, stdenv +, releaseTools + +, meson +, ninja +, pkg-config + +, nix-fetchers +, nix-store-test-support + +, rapidcheck +, gtest +, runCommand + +# Configuration Options + +, versionSuffix ? "" + +# Check test coverage of Nix. Probably want to use with at least +# one of `doCheck` or `doInstallCheck` enabled. +, withCoverageChecks ? false +}: + +let + inherit (lib) fileset; + + version = lib.fileContents ./.version + versionSuffix; + + mkDerivation = + if withCoverageChecks + then + # TODO support `finalAttrs` args function in + # `releaseTools.coverageAnalysis`. + argsFun: + releaseTools.coverageAnalysis (let args = argsFun args; in args) + else stdenv.mkDerivation; +in + +mkDerivation (finalAttrs: { + pname = "nix-fetchers-test"; + inherit version; + + src = fileset.toSource { + root = ./.; + fileset = fileset.unions [ + ./meson.build + # ./meson.options + (fileset.fileFilter (file: file.hasExt "cc") ./.) + (fileset.fileFilter (file: file.hasExt "hh") ./.) + ]; + }; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ + meson + ninja + pkg-config + ]; + + buildInputs = [ + nix-fetchers + nix-store-test-support + rapidcheck + gtest + ]; + + preConfigure = + # "Inline" .version so it's not a symlink, and includes the suffix + '' + echo ${version} > .version + ''; + + mesonFlags = [ + ]; + + env = lib.optionalAttrs (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")) { + LDFLAGS = "-fuse-ld=gold"; + }; + + enableParallelBuilding = true; + + separateDebugInfo = !stdenv.hostPlatform.isStatic; + + # TODO Always true after https://github.com/NixOS/nixpkgs/issues/318564 + strictDeps = !withCoverageChecks; + + hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie"; + + passthru = { + tests = { + run = runCommand "${finalAttrs.pname}-run" { + } '' + PATH="${lib.makeBinPath [ finalAttrs.finalPackage ]}:$PATH" + export _NIX_TEST_UNIT_DATA=${./data} + nix-fetchers-test + touch $out + ''; + }; + }; + + meta = { + platforms = lib.platforms.unix ++ lib.platforms.windows; + }; + +} // lib.optionalAttrs withCoverageChecks { + lcovFilter = [ "*/boost/*" "*-tab.*" ]; + + hardeningDisable = [ "fortify" ]; +}) diff --git a/src/libflake-test/package.nix b/src/libflake-test/package.nix new file mode 100644 index 000000000..f03f58619 --- /dev/null +++ b/src/libflake-test/package.nix @@ -0,0 +1,111 @@ +{ lib +, stdenv +, releaseTools + +, meson +, ninja +, pkg-config + +, nix-flake +, nix-expr-test-support + +, rapidcheck +, gtest +, runCommand + +# Configuration Options + +, versionSuffix ? "" + +# Check test coverage of Nix. Probably want to use with at least +# one of `doCheck` or `doInstallCheck` enabled. +, withCoverageChecks ? false +}: + +let + inherit (lib) fileset; + + version = lib.fileContents ./.version + versionSuffix; + + mkDerivation = + if withCoverageChecks + then + # TODO support `finalAttrs` args function in + # `releaseTools.coverageAnalysis`. + argsFun: + releaseTools.coverageAnalysis (let args = argsFun args; in args) + else stdenv.mkDerivation; +in + +mkDerivation (finalAttrs: { + pname = "nix-flake-test"; + inherit version; + + src = fileset.toSource { + root = ./.; + fileset = fileset.unions [ + ./meson.build + # ./meson.options + (fileset.fileFilter (file: file.hasExt "cc") ./.) + (fileset.fileFilter (file: file.hasExt "hh") ./.) + ]; + }; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ + meson + ninja + pkg-config + ]; + + buildInputs = [ + nix-flake + nix-expr-test-support + rapidcheck + gtest + ]; + + preConfigure = + # "Inline" .version so it's not a symlink, and includes the suffix + '' + echo ${version} > .version + ''; + + mesonFlags = [ + ]; + + env = lib.optionalAttrs (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")) { + LDFLAGS = "-fuse-ld=gold"; + }; + + enableParallelBuilding = true; + + separateDebugInfo = !stdenv.hostPlatform.isStatic; + + # TODO Always true after https://github.com/NixOS/nixpkgs/issues/318564 + strictDeps = !withCoverageChecks; + + hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie"; + + passthru = { + tests = { + run = runCommand "${finalAttrs.pname}-run" { + } '' + PATH="${lib.makeBinPath [ finalAttrs.finalPackage ]}:$PATH" + export _NIX_TEST_UNIT_DATA=${./data} + nix-flake-test + touch $out + ''; + }; + }; + + meta = { + platforms = lib.platforms.unix ++ lib.platforms.windows; + }; + +} // lib.optionalAttrs withCoverageChecks { + lcovFilter = [ "*/boost/*" "*-tab.*" ]; + + hardeningDisable = [ "fortify" ]; +}) diff --git a/src/libstore-c/package.nix b/src/libstore-c/package.nix index aedbad4a2..2ed78a760 100644 --- a/src/libstore-c/package.nix +++ b/src/libstore-c/package.nix @@ -41,7 +41,7 @@ mkDerivation (finalAttrs: { root = ./.; fileset = fileset.unions [ ./meson.build - ./meson.options + # ./meson.options (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) (fileset.fileFilter (file: file.hasExt "h") ./.) diff --git a/src/libstore-test/meson.build b/src/libstore-test/meson.build index cb561977c..2cdbfa7b5 100644 --- a/src/libstore-test/meson.build +++ b/src/libstore-test/meson.build @@ -36,6 +36,9 @@ deps_private += rapidcheck gtest = dependency('gtest', main : true) deps_private += gtest +gtest = dependency('gmock') +deps_private += gtest + add_project_arguments( # TODO(Qyriad): Yes this is how the autoconf+Make system did it. # It would be nice for our headers to be idempotent instead.