Skip to content

Commit

Permalink
fix(bazel): Maintain the version also in case of archive overrides
Browse files Browse the repository at this point in the history
Sometimes archive overrides just provides alternative URLs for a given
version. In these cases it is beneficial to maintain the version instead
of removing it.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Aug 26, 2024
1 parent 05d9658 commit 4e887f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project:
dependencies: []
- name: "main"
dependencies:
- id: "Bazel::rules_cuda:"
- id: "Bazel::rules_cuda:0.1.1"
linkage: "STATIC"
dependencies:
- id: "Bazel::bazel_skylib:1.3.0"
Expand Down Expand Up @@ -86,8 +86,8 @@ packages:
url: "https://github.com/bazelbuild/platforms.git"
revision: ""
path: ""
- id: "Bazel::rules_cuda:"
purl: "pkg:generic/rules_cuda@"
- id: "Bazel::rules_cuda:0.1.1"
purl: "pkg:generic/rules_cuda@0.1.1"
declared_licenses: []
declared_licenses_processed: {}
description: ""
Expand Down
9 changes: 3 additions & 6 deletions plugins/package-managers/bazel/src/main/kotlin/Bazel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class Bazel(
}

Package(
id = it.copy(version = ""),
id = it,
declaredLicenses = emptySet(),
description = "",
homepageUrl = "",
Expand Down Expand Up @@ -385,14 +385,11 @@ class Bazel(
}

/**
* Convert a [BazelModule] to a [PackageReference]. If an archive override is present in [archiveOverrides], the
* version of the package will be removed as Bazel does in the output of "mod graph".
* Convert a [BazelModule] to a [PackageReference].
*/
private fun BazelModule.toPackageReference(archiveOverrides: Map<String, ArchiveOverride>): PackageReference {
val packageRefName = name ?: key.substringBefore("@", "")
val packageRefVersion = archiveOverrides.takeUnless {
packageRefName in it
}?.let { version ?: key.substringAfter("@", "") }.orEmpty()
val packageRefVersion = version ?: key.substringAfter("@", "")

return PackageReference(
id = Identifier(
Expand Down

0 comments on commit 4e887f2

Please sign in to comment.