Skip to content

Commit d47c6c5

Browse files
committed
fix(conan)!: Use a Conan profile named ort-default instead of the default
This new profile is created with `-detect` therefore it will contains the compilation flags. This is cleaner as it allows to remove the passing of the compilation flags from the package manager. It also fix the usage of Conan on non-Linux plaforms. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 6892e97 commit d47c6c5

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ class Conan(
222222
config.lockfileName?.let { hasLockfile(workingDir.resolve(it).path) } == true
223223
}
224224

225+
handler.createConanProfileIfNeeded()
226+
225227
val handlerResults = handler.process(definitionFile, config.lockfileName)
226228

227229
val result = with(handlerResults) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ import org.ossreviewtoolkit.utils.ort.createOrtTempDir
4444
internal class ConanV1Handler(private val conan: Conan) : ConanVersionHandler {
4545
override fun getConanHome(): File = Os.userHomeDirectory.resolve(".conan")
4646

47+
override fun createConanProfileIfNeeded() {
48+
if (!getConanHome().resolve("profiles/ort-default").isFile) {
49+
conan.command.run("profile", "new", "ort-default", "--detect").requireSuccess()
50+
}
51+
}
52+
4753
override fun getConanStoragePath(): File = getConanHome().resolve("data")
4854

4955
override fun process(definitionFile: File, lockfileName: String?): HandlerResults {
@@ -64,7 +70,9 @@ internal class ConanV1Handler(private val conan: Conan) : ConanVersionHandler {
6470
definitionFile.name,
6571
"--json",
6672
jsonFile.absolutePath,
67-
*DUMMY_COMPILER_SETTINGS
73+
*DUMMY_COMPILER_SETTINGS,
74+
"--profile",
75+
"ort-default"
6876
).requireSuccess()
6977
}
7078

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ import org.ossreviewtoolkit.utils.ort.createOrtTempDir
4848
internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
4949
override fun getConanHome(): File = Os.userHomeDirectory.resolve(".conan2")
5050

51+
override fun createConanProfileIfNeeded() {
52+
if (!getConanHome().resolve("profiles/ort-default").isFile) {
53+
conan.command.run("profile", "detect", "--name", "ort-default").requireSuccess()
54+
}
55+
}
56+
5157
override fun getConanStoragePath(): File = getConanHome().resolve("p")
5258

5359
override fun process(definitionFile: File, lockfileName: String?): HandlerResults {
5460
val workingDir = definitionFile.parentFile
5561

56-
// Create a default build profile.
57-
if (!getConanHome().resolve("profiles/default").isFile) {
58-
conan.command.run(workingDir, "profile", "detect")
59-
}
60-
6162
val jsonFile = createOrtTempDir().resolve("info.json")
6263
if (lockfileName != null) {
6364
conan.verifyLockfileBelongsToProject(workingDir, lockfileName)
@@ -71,6 +72,8 @@ internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
7172
lockfileName,
7273
"--out-file",
7374
jsonFile.absolutePath,
75+
"--profile:all",
76+
"ort-default",
7477
*DUMMY_COMPILER_SETTINGS,
7578
definitionFile.name
7679
).requireSuccess()
@@ -83,6 +86,8 @@ internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
8386
"json",
8487
"--out-file",
8588
jsonFile.absolutePath,
89+
"--profile:all",
90+
"ort-default",
8691
*DUMMY_COMPILER_SETTINGS,
8792
definitionFile.name
8893
).requireSuccess()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ internal interface ConanVersionHandler {
3535
*/
3636
fun getConanHome(): File
3737

38+
/**
39+
* Create a default ORT Conan profile if it does not exist yet. This profile will contain the complication flags.
40+
*/
41+
fun createConanProfileIfNeeded()
42+
3843
/**
3944
* Get the Conan storage path, i.e. the location where Conan caches downloaded packages.
4045
*/

0 commit comments

Comments
 (0)