Skip to content

Commit f9645f8

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

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.masked
6061
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
6162
import org.ossreviewtoolkit.utils.common.stashDirectories
@@ -68,7 +69,7 @@ import org.semver4j.RangesList
6869
import org.semver4j.RangesListFactory
6970

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

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

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

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

8492
data class ConanConfig(

0 commit comments

Comments
 (0)