From e571858d48e5311469d489ab4e7b793056751b1a Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Fri, 6 Sep 2024 14:59:58 +0200 Subject: [PATCH] test(bazel): `MODULE.bazel` files from a local registry should be ignored Running the Analyzer on a project depending on packages present in a local registry currently fails with "Unable to create the AnalyzerResult as it contains packages and projects with the same ids". This is because the `MODULE.bazel` files present in the local registry should not be considered as definition files (issue [1]). This commit adds a test for this issue. [1]: https://github.com/oss-review-toolkit/ort/issues/9076 Signed-off-by: Nicolas Nobelis --- .../synthetic/bazel-local-registry2/.bazelrc | 4 ++ .../bazel-local-registry2/.bazelversion | 1 + .../bazel-local-registry2/MODULE.bazel | 1 + .../registry/bazel_registry.json | 3 ++ .../modules/module_a/0.0.1/MODULE.bazel | 6 +++ .../modules/module_a/0.0.1/source.json | 4 ++ .../registry/modules/module_a/metadata.json | 9 ++++ .../modules/module_b/0.0.1/MODULE.bazel | 4 ++ .../modules/module_b/0.0.1/source.json | 4 ++ .../registry/modules/module_b/metadata.json | 9 ++++ .../src/funTest/kotlin/BazelDetectionTest.kt | 46 +++++++++++++++++++ 11 files changed, 91 insertions(+) create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelrc create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelversion create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/MODULE.bazel create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/bazel_registry.json create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/MODULE.bazel create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/source.json create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/metadata.json create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/MODULE.bazel create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/source.json create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/metadata.json create mode 100644 plugins/package-managers/bazel/src/funTest/kotlin/BazelDetectionTest.kt diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelrc b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelrc new file mode 100644 index 0000000000000..4eefef3c024ed --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelrc @@ -0,0 +1,4 @@ +common --registry=file://%workspace%/registry/ + +common --registry=https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/ + diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelversion b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelversion new file mode 100644 index 0000000000000..9fe9ff9d996b3 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelversion @@ -0,0 +1 @@ +7.0.1 diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/MODULE.bazel b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/MODULE.bazel new file mode 100644 index 0000000000000..5e5b6f3be548a --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/MODULE.bazel @@ -0,0 +1 @@ +bazel_dep(name = "module_a", version = "0.0.1") diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/bazel_registry.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/bazel_registry.json new file mode 100644 index 0000000000000..88fa9c17ce3cb --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/bazel_registry.json @@ -0,0 +1,3 @@ +{ + "module_base_path": "../modulesSrc/" +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/MODULE.bazel b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/MODULE.bazel new file mode 100644 index 0000000000000..89a02b88c660a --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/MODULE.bazel @@ -0,0 +1,6 @@ +module( + name = "module_a", + version = "0.0.1", +) + +bazel_dep(name = "module_b", version = "0.0.1") diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/source.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/source.json new file mode 100644 index 0000000000000..09bdd5ef7da4e --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/source.json @@ -0,0 +1,4 @@ +{ + "integrity": "sha256-VixL51B9xvtJl+zWSL+TXYTv4XtUcV+lz73awFJ59mg=", + "url": "https://example.com/module_a-0.0.1.zip" +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/metadata.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/metadata.json new file mode 100644 index 0000000000000..b64d9d1fa7135 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/metadata.json @@ -0,0 +1,9 @@ +{ + "homepage": "", + "maintainers": [], + "repository": [], + "versions": [ + "0.0.1" + ], + "yanked_versions": {} +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/MODULE.bazel b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/MODULE.bazel new file mode 100644 index 0000000000000..f97dd435534fc --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/MODULE.bazel @@ -0,0 +1,4 @@ +module( + name = "module_b", + version = "0.0.1", +) diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/source.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/source.json new file mode 100644 index 0000000000000..bdca86dfe2c1c --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/source.json @@ -0,0 +1,4 @@ +{ + "integrity": "sha256-VixL51B9xvtJl+zWSL+TXYTv4XtUcV+lz73awFJ59mg=", + "url": "https://example.com/module_b-0.0.1.zip" +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/metadata.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/metadata.json new file mode 100644 index 0000000000000..b64d9d1fa7135 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/metadata.json @@ -0,0 +1,9 @@ +{ + "homepage": "", + "maintainers": [], + "repository": [], + "versions": [ + "0.0.1" + ], + "yanked_versions": {} +} diff --git a/plugins/package-managers/bazel/src/funTest/kotlin/BazelDetectionTest.kt b/plugins/package-managers/bazel/src/funTest/kotlin/BazelDetectionTest.kt new file mode 100644 index 0000000000000..fffc46eb9d860 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/kotlin/BazelDetectionTest.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 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.bazel + +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.nulls.shouldNotBeNull +import io.kotest.matchers.string.shouldContain + +import org.ossreviewtoolkit.analyzer.analyze +import org.ossreviewtoolkit.utils.test.getAssetFile + +class BazelDetectionTest : StringSpec({ + "MODULE.bazel files present in a local registry should not be considered as definition files" { + val definitionFile = getAssetFile("projects/synthetic/bazel-local-registry2/MODULE.bazel") + + val exception = shouldThrow { + analyze(definitionFile.parentFile, packageManagers = listOf(Bazel.Factory())) + } + + exception.shouldNotBeNull { + // Running the Analyzer on a project depending on packages present in a local registry currently fails + // with this message (issue #9076). This is because the "MODULE.bazel" files present in the local + // registry should not be considered as definition files. + message shouldContain + "Unable to create the AnalyzerResult as it contains packages and projects with the same ids" + } + } +})