From 02440154fb457e481d44aa0a2c2134e1a66e0f4b Mon Sep 17 00:00:00 2001 From: Chuck Atkins Date: Wed, 9 Sep 2015 16:03:04 -0400 Subject: [PATCH 1/2] find_*: Fix search order when the environment duplicates some HINTS Refactoring in the topic merged by commit v3.2.0-rc1~400 (Merge topic 'refactor-search-path-construction', 2014-11-13) introduced a bug that filters out duplicate paths in an incorrect order. Restore the search path to its documented order even when duplicate paths are present. Reported-by: Marc CHEVRIER --- Source/cmFindBase.cxx | 6 ++++-- Source/cmFindPackageCommand.cxx | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index add06a730..e2f86ce89 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -207,6 +207,10 @@ void cmFindBase::ExpandPaths() { this->FillCMakeEnvironmentPath(); } + } + this->FillUserHintsPath(); + if(!this->NoDefaultPath) + { if(!this->NoSystemEnvironmentPath) { this->FillSystemEnvironmentPath(); @@ -216,8 +220,6 @@ void cmFindBase::ExpandPaths() this->FillCMakeSystemVariablePath(); } } - - this->FillUserHintsPath(); this->FillUserGuessPath(); } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 68a6558fe..bf4033ec3 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1133,6 +1133,10 @@ void cmFindPackageCommand::ComputePrefixes() { this->FillPrefixesCMakeEnvironment(); } + } + this->FillPrefixesUserHints(); + if(!this->NoDefaultPath) + { if(!this->NoSystemEnvironmentPath) { this->FillPrefixesSystemEnvironment(); @@ -1150,7 +1154,6 @@ void cmFindPackageCommand::ComputePrefixes() this->FillPrefixesSystemRegistry(); } } - this->FillPrefixesUserHints(); this->FillPrefixesUserGuess(); this->ComputeFinalPaths(); From 7a6e5f06e7a32c894313b3a07c3d3c9abad8d2ca Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Sep 2015 14:49:49 -0400 Subject: [PATCH 2/2] Tests: Cover find_program when the environment duplicate some HINTS Reported-by: Marc CHEVRIER --- Tests/RunCMake/find_program/A/testAandB | 1 + Tests/RunCMake/find_program/B/testAandB | 1 + Tests/RunCMake/find_program/EnvAndHints-stdout.txt | 1 + Tests/RunCMake/find_program/EnvAndHints.cmake | 8 ++++++++ Tests/RunCMake/find_program/RunCMakeTest.cmake | 1 + 5 files changed, 12 insertions(+) create mode 100755 Tests/RunCMake/find_program/A/testAandB create mode 100755 Tests/RunCMake/find_program/B/testAandB create mode 100644 Tests/RunCMake/find_program/EnvAndHints-stdout.txt create mode 100644 Tests/RunCMake/find_program/EnvAndHints.cmake diff --git a/Tests/RunCMake/find_program/A/testAandB b/Tests/RunCMake/find_program/A/testAandB new file mode 100755 index 000000000..1a2485251 --- /dev/null +++ b/Tests/RunCMake/find_program/A/testAandB @@ -0,0 +1 @@ +#!/bin/sh diff --git a/Tests/RunCMake/find_program/B/testAandB b/Tests/RunCMake/find_program/B/testAandB new file mode 100755 index 000000000..1a2485251 --- /dev/null +++ b/Tests/RunCMake/find_program/B/testAandB @@ -0,0 +1 @@ +#!/bin/sh diff --git a/Tests/RunCMake/find_program/EnvAndHints-stdout.txt b/Tests/RunCMake/find_program/EnvAndHints-stdout.txt new file mode 100644 index 000000000..39329b22e --- /dev/null +++ b/Tests/RunCMake/find_program/EnvAndHints-stdout.txt @@ -0,0 +1 @@ +-- PROG='[^']*/Tests/RunCMake/find_program/A/testAandB' diff --git a/Tests/RunCMake/find_program/EnvAndHints.cmake b/Tests/RunCMake/find_program/EnvAndHints.cmake new file mode 100644 index 000000000..14ebd6e2f --- /dev/null +++ b/Tests/RunCMake/find_program/EnvAndHints.cmake @@ -0,0 +1,8 @@ +set(ENV_PATH "$ENV{PATH}") +set(ENV{PATH} ${CMAKE_CURRENT_SOURCE_DIR}/A) +find_program(PROG + NAMES testAandB + HINTS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B + ) +message(STATUS "PROG='${PROG}'") +set(ENV{PATH} "${ENV_PATH}") diff --git a/Tests/RunCMake/find_program/RunCMakeTest.cmake b/Tests/RunCMake/find_program/RunCMakeTest.cmake index 2adec1100..89307c1ae 100644 --- a/Tests/RunCMake/find_program/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_program/RunCMakeTest.cmake @@ -1,5 +1,6 @@ include(RunCMake) +run_cmake(EnvAndHints) run_cmake(DirsPerName) run_cmake(NamesPerDir)