Skip to content

Commit f044c97

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 4c98893 commit f044c97

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ class Conan(
202202
config.lockfileName?.let { hasLockfile(workingDir.resolve(it).path) } == true
203203
}
204204

205+
handler.createConanProfileIfNeeded()
206+
205207
val handlerResults = handler.process(definitionFile, config.lockfileName)
206208

207209
val result = with(handlerResults) {

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

+9-1
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

+9-6
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ import org.ossreviewtoolkit.utils.ort.createOrtTempDir
4747
internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
4848
override fun getConanHome(): File = Os.userHomeDirectory.resolve(".conan2")
4949

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

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

55-
// Create a default build profile.
56-
if (!getConanHome().resolve("profiles/default").isFile) {
57-
conan.command.run(workingDir, "profile", "detect")
58-
}
59-
6061
val jsonFile = createOrtTempDir().resolve("info.json")
6162
if (lockfileName != null) {
6263
conan.verifyLockfileBelongsToProject(workingDir, lockfileName)
@@ -83,7 +84,9 @@ internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
8384
"--out-file",
8485
jsonFile.absolutePath,
8586
*DUMMY_COMPILER_SETTINGS,
86-
definitionFile.name
87+
definitionFile.name,
88+
"--profile",
89+
"ort-default"
8790
).requireSuccess()
8891
}
8992

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

+5
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)