-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
testers.hasCmakeConfigModules: init #410516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
pkgs/build-support/testers/hasCmakeConfigModules/tester.nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Static arguments | ||
| { | ||
| lib, | ||
| runCommandCC, | ||
| cmake, | ||
| }: | ||
|
|
||
| # Tester arguments | ||
| { | ||
| package, | ||
| moduleNames, | ||
| # Extra nativeBuildInputs needed to pass the cmake find_package test, e.g. pkg-config. | ||
| nativeBuildInputs ? [ ], | ||
| # buildInputs is used to help pass the cmake find_package test. | ||
| # The purpose of buildInputs here is to allow us to iteratively add | ||
| # any missing dependencies required by the *Config.cmake module | ||
| # during testing. This allows us to test and fix the CMake setup | ||
| # without rebuilding the finalPackage each time. Once all required | ||
| # packages are properly added to the finalPackage's propagateBuildInputs, | ||
| # this buildInputs should be set to an empty list []. | ||
| buildInputs ? [ ], | ||
| # Extra cmakeFlags needed to pass the cmake find_package test. | ||
| # Can be used to set verbose/debug flags. | ||
| cmakeFlags ? [ ], | ||
| testName ? "check-cmake-config-${package.pname or package.name}", | ||
| version ? package.version or null, | ||
| versionCheck ? false, | ||
| }: | ||
|
|
||
| runCommandCC testName | ||
| { | ||
| inherit moduleNames versionCheck cmakeFlags; | ||
| version = if versionCheck then version else null; | ||
| nativeBuildInputs = [ | ||
| cmake | ||
| ] ++ nativeBuildInputs; | ||
| buildInputs = [ package ] ++ buildInputs; | ||
| meta = | ||
| { | ||
| description = "Test whether ${package.name} exposes cmake-config modules ${lib.concatStringsSep ", " moduleNames}"; | ||
| } | ||
| # Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org, | ||
| # as hydra can't check this meta info in dependencies. | ||
| # The test itself is just Nixpkgs, with MIT license. | ||
| // builtins.intersectAttrs { | ||
| available = throw "unused"; | ||
| broken = throw "unused"; | ||
| insecure = throw "unused"; | ||
| license = throw "unused"; | ||
| maintainers = throw "unused"; | ||
| teams = throw "unused"; | ||
| platforms = throw "unused"; | ||
| unfree = throw "unused"; | ||
| unsupported = throw "unused"; | ||
| } package.meta; | ||
| } | ||
| '' | ||
| touch "$out" | ||
| notFound=0 | ||
| for moduleName in $moduleNames; do | ||
| echo "checking cmake-config module $moduleName" | ||
|
|
||
| cat <<EOF > CMakeLists.txt | ||
| cmake_minimum_required(VERSION 3.14) | ||
| project(CheckCmakeModule) | ||
|
|
||
| find_package($moduleName $version EXACT NO_MODULE REQUIRED) | ||
| EOF | ||
|
|
||
| echoCmd 'cmake flags' $cmakeFlags | ||
| set +e | ||
| cmake . $cmakeFlags | ||
| r=$? | ||
| set -e | ||
| if [[ $r = 0 ]]; then | ||
| echo "✅ cmake-config module $moduleName exists" | ||
| else | ||
| echo "❌ cmake-config module $moduleName was not found" | ||
| ((notFound+=1)) | ||
| fi | ||
| done | ||
|
|
||
| if [[ $notFound -ne 0 ]]; then | ||
| exit 1 | ||
| fi | ||
| '' |
73 changes: 73 additions & 0 deletions
73
pkgs/build-support/testers/hasCmakeConfigModules/tests.nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # cd nixpkgs | ||
| # nix-build -A tests.testers.hasCmakeConfigModules | ||
| { | ||
| lib, | ||
| testers, | ||
| boost, | ||
| mpi, | ||
| eigen, | ||
| runCommand, | ||
| }: | ||
|
|
||
| lib.recurseIntoAttrs { | ||
|
|
||
| boost-versions-match = testers.hasCmakeConfigModules { | ||
| package = boost; | ||
| moduleNames = [ | ||
| "Boost" | ||
| "boost_math" | ||
| ]; | ||
| versionCheck = true; | ||
| }; | ||
|
|
||
| boost-versions-mismatch = testers.testBuildFailure ( | ||
| testers.hasCmakeConfigModules { | ||
| package = boost; | ||
| moduleNames = [ | ||
| "Boost" | ||
| "boost_math" | ||
| ]; | ||
| version = "1.2.3"; # Deliberately-incorrect version number | ||
| versionCheck = true; | ||
| } | ||
| ); | ||
|
|
||
| boost-no-versionCheck = testers.hasCmakeConfigModules { | ||
| package = boost; | ||
| moduleNames = [ | ||
| "Boost" | ||
| "boost_math" | ||
| ]; | ||
| version = "1.2.3"; # Deliberately-incorrect version number | ||
| versionCheck = false; | ||
| }; | ||
|
|
||
| boost-has-boost_mpi = testers.hasCmakeConfigModules { | ||
| package = boost.override { useMpi = true; }; | ||
| moduleNames = [ | ||
| "boost_mpi" | ||
| ]; | ||
| buildInputs = [ mpi ]; | ||
| }; | ||
|
|
||
| boost_mpi-does-not-have-mpi = testers.testBuildFailure ( | ||
| testers.hasCmakeConfigModules { | ||
| package = boost.override { useMpi = true; }; | ||
| moduleNames = [ | ||
| "boost_mpi" | ||
| ]; | ||
| } | ||
| ); | ||
|
|
||
| eigen-has-Eigen = testers.hasCmakeConfigModules { | ||
| package = eigen; | ||
| moduleNames = [ "Eigen3" ]; | ||
| }; | ||
|
|
||
| eigen-does-not-have-eigen = testers.testBuildFailure ( | ||
| testers.hasCmakeConfigModules { | ||
| package = eigen; | ||
| moduleNames = [ "eigen3" ]; | ||
| } | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.