Skip to content

Commit b75e750

Browse files
nnobelissschuberth
authored andcommitted
fix(bazel): Accept module statements without version
The Bazel module specification ([1]) allows `module` statements without a version. This commit modifies ORT's module files parser to allow missing versions and to use the project VCS revision when there is no version defined. [1]: https://bazel.build/rules/lib/globals/module#module Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
1 parent 1873575 commit b75e750

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-7.0-no-version-expected-output.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
project:
3-
id: "Bazel::my_bazel_module:1.0.0"
3+
id: "Bazel::my_bazel_module:<REPLACE_REVISION>"
44
definition_file_path: "<REPLACE_DEFINITION_FILE_PATH>"
55
declared_licenses: []
66
declared_licenses_processed: {}

plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-7.0_modules_without_versions/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module(name = "my_bazel_module", version = "1.0.0")
1+
module(name = "my_bazel_module")
22

33
bazel_dep(name = "nanopb", dev_dependency=True)
44

plugins/package-managers/bazel/src/funTest/kotlin/BazelFunTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class BazelFunTest : StringSpec({
8181
result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
8282
}
8383

84-
"Dependencies are detected correctly with Bazel when a dependency has no version" {
84+
"Dependencies are detected correctly with Bazel when a module or a dependency has no version" {
8585
val definitionFile = getAssetFile("projects/synthetic/bazel-7.0_modules_without_versions/MODULE.bazel")
8686
val expectedResultFile = getAssetFile("projects/synthetic/bazel-7.0-no-version-expected-output.yml")
8787

plugins/package-managers/bazel/src/main/kotlin/Bazel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class Bazel(
257257
type = projectType,
258258
namespace = "",
259259
name = moduleMetadata.module?.name ?: VersionControlSystem.getPathInfo(definitionFile).path,
260-
version = moduleMetadata.module?.version.orEmpty()
260+
version = moduleMetadata.module?.version?.ifEmpty { projectVcs.revision }.orEmpty()
261261
),
262262
definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path,
263263
declaredLicenses = emptySet(),

plugins/package-managers/bazel/src/main/kotlin/StarlarkParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ internal class Parser(input: String) {
247247

248248
return ModuleDirective(
249249
name = params["name"] ?: throw IllegalArgumentException("Missing name in 'module' directive"),
250-
version = params["version"] ?: throw IllegalArgumentException("Missing version in 'module' directive"),
250+
version = params["version"].orEmpty(),
251251
compatibilityLevel = params["compatibility_level"]?.toInt() ?: 0
252252
)
253253
}

0 commit comments

Comments
 (0)