Skip to content

Commit 7706593

Browse files
nnobelissschuberth
authored andcommitted
feat(conan): Add configurable optional path of a Conan profile
Some Conan projects are not compatible with the default build parameters passed by ORT. Additionally, some projects maintain an external profile file to configure the build properties. This commit adds an extra configuration parameter to the Conan package manager to allow passing such profile files. This parameter should contain a relative file path that will be resolved against the analysis root, i.e "analysisRoot/profilePath". Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 26b3611 commit 7706593

File tree

4 files changed

+63
-52
lines changed

4 files changed

+63
-52
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ data class ConanConfig(
9696
* development environment.
9797
*/
9898
@OrtPluginOption(defaultValue = "false")
99-
val useConan2: Boolean
99+
val useConan2: Boolean,
100+
101+
/**
102+
* The path, relative to the root of the analysis, of a Conan profile to use during dependency resolution.
103+
* If not specified, the default profile is used instead.
104+
*/
105+
val conanProfilePath: String?
100106
)
101107

102108
/**
@@ -215,7 +221,11 @@ class Conan(
215221
config.lockfileName?.let { hasLockfile(workingDir.resolve(it).path) } == true
216222
}
217223

218-
val handlerResults = handler.process(definitionFile, config.lockfileName)
224+
val resolvedProfilePath = config.conanProfilePath?.let { profilePath ->
225+
analysisRoot / profilePath
226+
}
227+
228+
val handlerResults = handler.process(definitionFile, config.lockfileName, resolvedProfilePath)
219229

220230
val result = with(handlerResults) {
221231
val scopes = setOfNotNull(dependenciesScope, devDependenciesScope, testDependenciesScope)

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,31 @@ internal class ConanV1Handler(private val conan: Conan) : ConanVersionHandler {
4747

4848
override fun getConanStoragePath(): File = getConanHome().resolve("data")
4949

50-
override fun process(definitionFile: File, lockfileName: String?): HandlerResults {
50+
override fun process(definitionFile: File, lockfileName: String?, conanProfile: File?): HandlerResults {
5151
val workingDir = definitionFile.parentFile
5252
val jsonFile = createOrtTempDir().resolve("info.json")
53-
if (lockfileName != null) {
53+
54+
val extraArgs = when {
55+
conanProfile != null -> arrayOf("-pr", conanProfile.toRelativeString(definitionFile.parentFile))
56+
5457
// Note that none of profile, settings, options, env or conf 'host' can be used with a lockfile.
55-
conan.verifyLockfileBelongsToProject(workingDir, lockfileName)
56-
conan.command.run(
57-
workingDir,
58-
"info", definitionFile.name,
59-
"-l", lockfileName,
60-
"--json", jsonFile.absolutePath
61-
).requireSuccess()
62-
} else {
63-
conan.command.run(
64-
workingDir,
65-
"info",
66-
definitionFile.name,
67-
"--json",
68-
jsonFile.absolutePath,
69-
*DUMMY_COMPILER_SETTINGS
70-
).requireSuccess()
58+
lockfileName != null -> {
59+
conan.verifyLockfileBelongsToProject(workingDir, lockfileName)
60+
arrayOf("-l", lockfileName)
61+
}
62+
63+
else -> DUMMY_COMPILER_SETTINGS
7164
}
7265

66+
conan.command.run(
67+
workingDir,
68+
"info",
69+
definitionFile.name,
70+
"--json",
71+
jsonFile.absolutePath,
72+
*extraArgs
73+
).requireSuccess()
74+
7375
val pkgInfos = parsePackageInfosV1(jsonFile).also { jsonFile.parentFile.safeDeleteRecursively() }
7476

7577
val packageList = removeProjectPackage(pkgInfos, definitionFile.name)

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,43 +51,42 @@ internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
5151

5252
override fun getConanStoragePath(): File = getConanHome().resolve("p")
5353

54-
override fun process(definitionFile: File, lockfileName: String?): HandlerResults {
54+
override fun process(definitionFile: File, lockfileName: String?, conanProfile: File?): HandlerResults {
5555
val workingDir = definitionFile.parentFile
5656

5757
// Create a default build profile.
5858
if (!getConanHome().resolve("profiles/default").isFile) {
5959
conan.command.run(workingDir, "profile", "detect")
6060
}
6161

62+
val extraArgs = buildList {
63+
if (conanProfile != null) {
64+
add("-pr")
65+
add(conanProfile.toRelativeString(definitionFile.parentFile))
66+
} else {
67+
addAll(DUMMY_COMPILER_SETTINGS)
68+
}
69+
70+
if (lockfileName != null) {
71+
conan.verifyLockfileBelongsToProject(workingDir, lockfileName)
72+
add("-l")
73+
add(lockfileName)
74+
}
75+
}.toTypedArray()
76+
6277
val jsonFile = createOrtTempDir().resolve("info.json")
63-
if (lockfileName != null) {
64-
conan.verifyLockfileBelongsToProject(workingDir, lockfileName)
65-
conan.command.run(
66-
workingDir,
67-
"graph",
68-
"info",
69-
"-f",
70-
"json",
71-
"-l",
72-
lockfileName,
73-
"--out-file",
74-
jsonFile.absolutePath,
75-
*DUMMY_COMPILER_SETTINGS,
76-
definitionFile.name
77-
).requireSuccess()
78-
} else {
79-
conan.command.run(
80-
workingDir,
81-
"graph",
82-
"info",
83-
"-f",
84-
"json",
85-
"--out-file",
86-
jsonFile.absolutePath,
87-
*DUMMY_COMPILER_SETTINGS,
88-
definitionFile.name
89-
).requireSuccess()
90-
}
78+
79+
conan.command.run(
80+
workingDir,
81+
"graph",
82+
"info",
83+
"-f",
84+
"json",
85+
"--out-file",
86+
jsonFile.absolutePath,
87+
*extraArgs,
88+
definitionFile.name
89+
).requireSuccess()
9190

9291
val pkgInfosV2 = parsePackageInfosV2(jsonFile).also { jsonFile.parentFile.safeDeleteRecursively() }
9392

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ internal interface ConanVersionHandler {
4242
fun getConanStoragePath(): File
4343

4444
/**
45-
* Resolve the dependencies defined in the [definitionFile] and given the lockfile [lockfileName], and return them
46-
* as [HandlerResults].
45+
* Resolve the dependencies defined in the [definitionFile], with optional [lockfileName] / [conanProfile], and
46+
* return them as [HandlerResults].
4747
*/
48-
fun process(definitionFile: File, lockfileName: String?): HandlerResults
48+
fun process(definitionFile: File, lockfileName: String?, conanProfile: File?): HandlerResults
4949

5050
/**
5151
* Get the Conan data file for a package with the given [name] and [version] from the [conanStorageDir]. This file

0 commit comments

Comments
 (0)