Skip to content

Commit 6892e97

Browse files
committed
fix(conan): Adapt the Conan package manager to use the virtual environments
Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 1775838 commit 6892e97

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

plugins/package-managers/conan/src/funTest/kotlin/ConanFunTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ import org.ossreviewtoolkit.utils.test.matchExpectedResult
3030
import org.ossreviewtoolkit.utils.test.patchActualResult
3131

3232
/**
33-
* This test class performs tests with both Conan 1 and Conan 2. For it to be successful, it needs both a "conan"
34-
* command for Conan 1 and a "conan2" command for Conan 2 in the PATH environment variable (as in ORT Docker image).
33+
* This test class performs tests with both Conan 1 and Conan 2. To be able to run it locally, it needs to have access
34+
* to some Conan installations as it is done in the ORT Docker image:
35+
* - prerequisites: bash, pyenv, pyenv virtualenv.
36+
* - a directory ~/bin/ort-conan containing the file 'setup_conan.sh' renamed 'conan' and made executable.
37+
* - two pyenv venvs 'conan' and 'conan2' containing respectively the conan 1 and conan 2 installations.
38+
* Then the test can be run with PATH set to ~/bin/ort-conan:$PATH (and the PATH of the pyenv installation).
3539
*
3640
* A word of caution about Conan 2 tests: If there is no lockfile, when Conan resolves the dependencies it read its
3741
* cache and relies on the package name, ignoring the version. This means, for instance, that if a test reported

plugins/package-managers/conan/src/main/kotlin/Conan.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import org.ossreviewtoolkit.plugins.api.OrtPlugin
5656
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
5757
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
5858
import org.ossreviewtoolkit.utils.common.CommandLineTool
59+
import org.ossreviewtoolkit.utils.common.ProcessCapture
5960
import org.ossreviewtoolkit.utils.common.alsoIfNull
6061
import org.ossreviewtoolkit.utils.common.masked
6162
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
@@ -69,7 +70,7 @@ import org.semver4j.RangesList
6970
import org.semver4j.RangesListFactory
7071

7172
internal class ConanCommand(private val useConan2: Boolean = false) : CommandLineTool {
72-
override fun command(workingDir: File?) = if (useConan2) "conan2" else "conan"
73+
override fun command(workingDir: File?) = "conan"
7374

7475
override fun transformVersion(output: String) =
7576
// Conan could report version strings like:
@@ -78,8 +79,15 @@ internal class ConanCommand(private val useConan2: Boolean = false) : CommandLin
7879

7980
override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=1.44.0 <3.0")
8081

81-
override fun run(vararg args: CharSequence, workingDir: File?, environment: Map<String, String>) =
82-
super.run(args = args, workingDir, environment + mapOf("CONAN_NON_INTERACTIVE" to "1", "CONAN_SERIES" to "1"))
82+
override fun run(vararg args: CharSequence, workingDir: File?, environment: Map<String, String>): ProcessCapture =
83+
super.run(
84+
args = args,
85+
workingDir,
86+
environment + mapOf(
87+
"CONAN_NON_INTERACTIVE" to "1",
88+
"CONAN_SERIES" to if (useConan2) "2" else "1"
89+
)
90+
)
8391
}
8492

8593
data class ConanConfig(

0 commit comments

Comments
 (0)