diff --git a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt index b4dd4a963b134..e1fe6bc0bfae0 100644 --- a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt +++ b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt @@ -164,10 +164,6 @@ class Cargo( } override fun resolveDependencies(definitionFile: File, labels: Map): List { - // Get the project name and version. If one of them is missing return null, because this is a workspace - // definition file that does not contain a project. - val pkgDefinition = definitionFile.reader().use { toml.decodeFromNativeReader(it) } - val workingDir = definitionFile.parentFile val metadataProcess = run(workingDir, "metadata", "--format-version=1") val metadata = json.decodeFromString(metadataProcess.stdout) @@ -178,8 +174,8 @@ class Cargo( { parsePackage(it, hashes) } ) - val projectId = metadata.workspaceMembers.single { - it.startsWith("${pkgDefinition.pkg.name} ${pkgDefinition.pkg.version}") + val projectId = requireNotNull(metadata.resolve.root) { + "Virtual workspaces are not supported." } val projectNode = metadata.packages.single { it.id == projectId } @@ -190,8 +186,7 @@ class Cargo( val transitiveDependencies = directDependencies .mapNotNull { dependency -> - val version = - getResolvedVersion(pkgDefinition.pkg.name, pkgDefinition.pkg.version, dependency.name, metadata) + val version = getResolvedVersion(projectNode.name, projectNode.version, dependency.name, metadata) version?.let { Pair(dependency.name, it) } } .mapTo(mutableSetOf()) { @@ -207,12 +202,10 @@ class Cargo( getTransitiveDependencies(groupedDependencies["build"], "build-dependencies") ) - val projectPkg = packages.values.single { pkg -> - pkg.id.name == pkgDefinition.pkg.name && pkg.id.version == pkgDefinition.pkg.version - }.let { it.copy(id = it.id.copy(type = managerName)) } + val projectPkg = packages.getValue(projectId).let { it.copy(id = it.id.copy(type = managerName)) } - val homepageUrl = pkgDefinition.pkg.homepage.orEmpty() - val authors = pkgDefinition.pkg.authors.mapNotNullTo(mutableSetOf(), ::parseAuthorString) + val homepageUrl = projectNode.homepage.orEmpty() + val authors = projectNode.authors.mapNotNullTo(mutableSetOf(), ::parseAuthorString) val project = Project( id = projectPkg.id, diff --git a/plugins/package-managers/cargo/src/main/kotlin/CargoManifest.kt b/plugins/package-managers/cargo/src/main/kotlin/CargoManifest.kt deleted file mode 100644 index 249fa79f315db..0000000000000 --- a/plugins/package-managers/cargo/src/main/kotlin/CargoManifest.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2023 The ORT Project Authors (see ) - * - * 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 - */ - -package org.ossreviewtoolkit.plugins.packagemanagers.cargo - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -/** - * See https://doc.rust-lang.org/cargo/reference/manifest.html. - */ -@Serializable -internal data class CargoManifest( - @SerialName("package") - val pkg: Package -) { - /** - * See https://doc.rust-lang.org/cargo/reference/manifest.html#the-package-section. - */ - @Serializable - data class Package( - val name: String, - val version: String, - val authors: List = emptyList(), - val homepage: String? = null - ) -}