-
Notifications
You must be signed in to change notification settings - Fork 352
refactor: Use environments to install Conan #10127
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
base: main
Are you sure you want to change the base?
Changes from all commits
bfb8a2c
321ae2a
6f90359
76b591b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ import org.ossreviewtoolkit.plugins.api.OrtPlugin | |
import org.ossreviewtoolkit.plugins.api.OrtPluginOption | ||
import org.ossreviewtoolkit.plugins.api.PluginDescriptor | ||
import org.ossreviewtoolkit.utils.common.CommandLineTool | ||
import org.ossreviewtoolkit.utils.common.ProcessCapture | ||
import org.ossreviewtoolkit.utils.common.alsoIfNull | ||
import org.ossreviewtoolkit.utils.common.masked | ||
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively | ||
|
@@ -69,7 +70,7 @@ import org.semver4j.RangesList | |
import org.semver4j.RangesListFactory | ||
|
||
internal class ConanCommand(private val useConan2: Boolean = false) : CommandLineTool { | ||
override fun command(workingDir: File?) = if (useConan2) "conan2" else "conan" | ||
override fun command(workingDir: File?) = "conan" | ||
|
||
override fun transformVersion(output: String) = | ||
// Conan could report version strings like: | ||
|
@@ -78,8 +79,15 @@ internal class ConanCommand(private val useConan2: Boolean = false) : CommandLin | |
|
||
override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=1.44.0 <3.0") | ||
|
||
override fun run(vararg args: CharSequence, workingDir: File?, environment: Map<String, String>) = | ||
super.run(args = args, workingDir, environment + ("CONAN_NON_INTERACTIVE" to "1")) | ||
override fun run(vararg args: CharSequence, workingDir: File?, environment: Map<String, String>): ProcessCapture = | ||
super.run( | ||
args = args, | ||
workingDir, | ||
environment + mapOf( | ||
"CONAN_NON_INTERACTIVE" to "1", | ||
"CONAN_MAJOR_VERSION" to if (useConan2) "2" else "1" | ||
) | ||
) | ||
} | ||
|
||
data class ConanConfig( | ||
|
@@ -114,12 +122,6 @@ class Conan( | |
private val config: ConanConfig | ||
) : PackageManager("Conan") { | ||
companion object { | ||
internal val DUMMY_COMPILER_SETTINGS = arrayOf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine (and even less confusing) to squash this to the previous commit, saying to replace hard-coded dummy compiler settings with proper ones. Otherwise there's an intermediate commit with both dummy and detected settings, which does not make sense. |
||
"-s", "compiler=gcc", | ||
"-s", "compiler.libcxx=libstdc++", | ||
"-s", "compiler.version=11.1" | ||
) | ||
|
||
internal const val SCOPE_NAME_DEPENDENCIES = "requires" | ||
internal const val SCOPE_NAME_DEV_DEPENDENCIES = "build_requires" | ||
internal const val SCOPE_NAME_TEST_DEPENDENCIES = "test_requires" | ||
|
@@ -214,6 +216,8 @@ class Conan( | |
config.lockfileName?.let { hasLockfile(workingDir.resolve(it).path) } == true | ||
} | ||
|
||
handler.createConanProfileIfNeeded() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit message: s/-detect/--detect/ |
||
|
||
val handlerResults = handler.process(definitionFile, config.lockfileName) | ||
|
||
val result = with(handlerResults) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ import org.ossreviewtoolkit.model.PackageReference | |
import org.ossreviewtoolkit.model.RemoteArtifact | ||
import org.ossreviewtoolkit.model.Scope | ||
import org.ossreviewtoolkit.model.VcsInfo | ||
import org.ossreviewtoolkit.plugins.packagemanagers.conan.Conan.Companion.DUMMY_COMPILER_SETTINGS | ||
import org.ossreviewtoolkit.plugins.packagemanagers.conan.Conan.Companion.SCOPE_NAME_DEPENDENCIES | ||
import org.ossreviewtoolkit.plugins.packagemanagers.conan.Conan.Companion.SCOPE_NAME_DEV_DEPENDENCIES | ||
import org.ossreviewtoolkit.utils.common.Os | ||
|
@@ -44,6 +43,12 @@ import org.ossreviewtoolkit.utils.ort.createOrtTempDir | |
internal class ConanV1Handler(private val conan: Conan) : ConanVersionHandler { | ||
override fun getConanHome(): File = Os.userHomeDirectory.resolve(".conan") | ||
|
||
override fun createConanProfileIfNeeded() { | ||
if (!getConanHome().resolve("profiles/ort-default").isFile) { | ||
conan.command.run("profile", "new", "ort-default", "--detect").requireSuccess() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "ort-default" should only be added to the script in this commit which makes use of it. |
||
} | ||
} | ||
|
||
override fun getConanStoragePath(): File = getConanHome().resolve("data") | ||
|
||
override fun process(definitionFile: File, lockfileName: String?): HandlerResults { | ||
|
@@ -64,7 +69,8 @@ internal class ConanV1Handler(private val conan: Conan) : ConanVersionHandler { | |
definitionFile.name, | ||
"--json", | ||
jsonFile.absolutePath, | ||
*DUMMY_COMPILER_SETTINGS | ||
"--profile", | ||
"ort-default" | ||
).requireSuccess() | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2025 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
# | ||
|
||
conan_option=${CONAN_MAJOR_VERSION:-2} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about making this
and then below simply call
once? However, that would require to rename the venv from "conan" to "conan1", but maybe it's not a bad ideal to be explicit anyway. |
||
|
||
# Since this script is installed with the name "conan", there is a risk of infinite recursion if pyenv is not available | ||
# on the PATH, which can occur when setting up a development environment. To prevent this, check for recursive calls. | ||
if [[ "$CONAN_RECURSIVE_CALL" -eq 1 ]]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A simpler check could be to compare |
||
echo "Recursive call detected. Exiting." | ||
exit 1 | ||
fi | ||
|
||
# Setup pyenv | ||
eval "$(pyenv init - --no-rehash bash)" | ||
eval "$(pyenv virtualenv-init -)" | ||
|
||
# Setting up Conan 1.x | ||
if [[ "$conan_option" -eq 1 ]]; then # Setting up Conan 1.x series | ||
pyenv activate conan | ||
# Docker has modern libc | ||
CONAN_RECURSIVE_CALL=1 conan profile update settings.compiler.libcxx=libstdc++11 ort-default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this only need to be done for Conan 1? |
||
elif [[ "$conan_option" -eq 2 ]]; then # Setting up Conan 2.x series | ||
pyenv activate conan2 | ||
fi | ||
|
||
# Runs conan from activated profile | ||
CONAN_RECURSIVE_CALL=1 conan "$@" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the commit message needs to be reworked. To me, using dashes for a list / an enumeration is always an alarm sign that probably too much work has been crammed into a single commit.
I propose something like: