Skip to content

Commit 8719ccf

Browse files
committed
feat(conan): Ignore Conan files containing Bazel generators
If a Bazel project uses some Conan packages, the corresponding Conan files should not be picked up by the Conan package manager. Therefore, the Conan file is checked to NOT contain the BazelDeps and BazelToolchain generators. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 420b282 commit 8719ccf

File tree

1 file changed

+15
-0
lines changed
  • plugins/package-managers/conan/src/main/kotlin

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 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.alsoIfNull
5960
import org.ossreviewtoolkit.utils.common.masked
6061
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
6162
import org.ossreviewtoolkit.utils.common.stashDirectories
@@ -149,6 +150,20 @@ class Conan(
149150

150151
private fun hasLockfile(file: String) = File(file).isFile
151152

153+
/**
154+
* If a Bazel project uses some Conan packages, the corresponding Conan files should not be picked up by the Conan
155+
* package manager. Therefore, the Conan file is checked to NOT contain the BazelDeps and BazelToolchain generators.
156+
*/
157+
override fun mapDefinitionFiles(analysisRoot: File, definitionFiles: List<File>): List<File> =
158+
definitionFiles.mapNotNull { file ->
159+
file.takeUnless {
160+
val content = it.readText()
161+
"BazelDeps" in content || "BazelToolchain" in content
162+
}.alsoIfNull {
163+
logger.info { "Ignoring definition file '$file' as is used from Bazel." }
164+
}
165+
}
166+
152167
override fun beforeResolution(
153168
analysisRoot: File,
154169
definitionFiles: List<File>,

0 commit comments

Comments
 (0)