Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel: MODULE.bazel files present in a local registry should not be considered as managed files #9076

Closed
nnobelis opened this issue Sep 4, 2024 · 3 comments · Fixed by #9162
Assignees
Labels
analyzer About the analyzer tool bug Issues that are considered to be bugs

Comments

@nnobelis
Copy link
Member

nnobelis commented Sep 4, 2024

I have the following Bazel project:

project/
├─ registry/
│  ├─ modules/
│  │  ├─ A/
│  │  │  ├─ 1.0/
│  │  │  │  ├─ MODULE.bazel
│  │  │  │  ├─ source.json
│  │  │  ├─ metadata.json
│  │  ├─ B/
│  │  │  ├─ 1.0/
│  │  │  │  ├─ MODULE.bazel
│  │  │  │  ├─ source.json
│  │  │  ├─ metadata.json
├─ .bazelrc
├─ MODULE.bazel

The directory registry is a local registry defined in .bazelrc:
common --registry=file://%workspace%/registry/

In %workspace%/MODULE.bazel, a dependency to A is defined:
bazel_dep(name = "A", version = "1.0")

In %workspace%/registry/modules/A/1.0/MODULE:bazel, a dependency to B is defined:
bazel_dep(name = "B", version = "1.0")

With such a setup, ORT Analyzer throws the following error:

o.o.analyzer.PackageManager - Using Bazel to resolve dependencies for path 'registry/modules/A/1.0/MODULE.bazel'...
o.o.utils.common.ProcessCapture - Running 'bazel mod graph --output json --disk_cache=' in 'registry/modules/A/1.0'...ERROR: in module dependency chain <root> -> B@1.0.0: module not found in registries: B@1.0.0. Type 'bazel help mod' for syntax and help.

The problem is that the Bazel package manager collects all MODULE.bazels in the project directory and considers them all as managed files. The MODULES.bazels present in a (registry) should not be picked up by the package manager as there are not "really" sub dependency trees.
The dependency of A to B is picked by ORT by calling bazel mod graph on the top level MODULE.bazel.

Is there a mechanism in ORT to exclude managed files during a package manager run ?

I will create a test for this ASAP.

@nnobelis nnobelis added bug Issues that are considered to be bugs to triage Issues that need triaging labels Sep 4, 2024
@nnobelis
Copy link
Member Author

nnobelis commented Sep 4, 2024

I mean the obvious solution to this problem is to create an exclude for registry/**/MODULE.bazel.
However I wonder if ORT, knowing that the folder is a local registry, could do it automatically?

@sschuberth
Copy link
Member

Is there a mechanism in ORT to exclude managed files during a package manager run ?

Sounds like a use-case for

/**
* Optional mapping of found [definitionFiles] before dependency resolution.
*/
open fun mapDefinitionFiles(definitionFiles: List<File>): List<File> = definitionFiles

@sschuberth sschuberth added analyzer About the analyzer tool and removed to triage Issues that need triaging labels Sep 4, 2024
nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 6, 2024
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 managed files (issue [1]).
This commit adds a test for this issue.

[1]: oss-review-toolkit#9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 6, 2024
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 managed files (issue [1]).
This commit adds a test for this issue.

[1]: oss-review-toolkit#9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 6, 2024
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 managed files (issue [1]).
This commit adds a test for this issue.

[1]: oss-review-toolkit#9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 6, 2024
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 managed files (issue [1]).
This commit adds a test for this issue.

[1]: oss-review-toolkit#9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
@nnobelis
Copy link
Member Author

nnobelis commented Sep 6, 2024

I created #9090 as a test for this issue.

However I think the issue is more severe as what is described here.

There is first:

ERROR org.ossreviewtoolkit.analyzer.PackageManager - Bazel failed to resolve dependencies for path 'registry/modules/module_a/0.0.1/MODULE.bazel': IOException: Running 'bazel mod graph --output json --disk_cache=' in /plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1' failed with exit code 2:
ERROR: in module dependency chain <root> -> module_b@0.0.1: module not found in registries: module_b@0.0.1. Type 'bazel help mod' for syntax and help

But afterwards comes this exception:

Unable to create the AnalyzerResult as it contains packages and projects with the same ids: [[Package(id=Identifier(type=Bazel, namespace=, name=module_b, version=0.0.1), purl=pkg:generic/module_b@0.0.1
[...]
	at org.ossreviewtoolkit.analyzer.AnalyzerResultBuilder.build(AnalyzerResultBuilder.kt:44)
	at org.ossreviewtoolkit.analyzer.AnalyzerState.buildResult(Analyzer.kt:257)
	at org.ossreviewtoolkit.analyzer.Analyzer.analyzeInParallel(Analyzer.kt:182)
	at org.ossreviewtoolkit.analyzer.Analyzer.analyze(Analyzer.kt:134)
	at org.ossreviewtoolkit.analyzer.Analyzer.analyze$default(Analyzer.kt:126)
	at org.ossreviewtoolkit.analyzer.TestUtilsKt.analyze(TestUtils.kt:133)
	at org.ossreviewtoolkit.analyzer.TestUtilsKt.analyze$default(TestUtils.kt:124)
	at org.ossreviewtoolkit.plugins.packagemanagers.bazel.BazelDetectionTest$1$1.invokeSuspend(BazelDetectionTest.kt:33)
	at org.ossreviewtoolkit.plugins.packagemanagers.bazel.BazelDetectionTest$1$1.invoke(BazelDetectionTest.kt)
	at org.ossreviewtoolkit.plugins.packagemanagers.bazel.BazelDetectionTest$1$1.invoke(BazelDetectionTest.kt)

nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 11, 2024
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]: oss-review-toolkit#9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 11, 2024
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]: oss-review-toolkit#9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 11, 2024
…ored

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]: oss-review-toolkit#9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
sschuberth pushed a commit that referenced this issue Sep 11, 2024
…ored

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]: #9076

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
@nnobelis nnobelis self-assigned this Sep 18, 2024
nnobelis added a commit to boschglobal/oss-review-toolkit that referenced this issue Sep 18, 2024
`MODULE.bazel` files present in the local registry should not be considered
as definition files.

Fixes oss-review-toolkit#9076.

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer About the analyzer tool bug Issues that are considered to be bugs
Projects
None yet
2 participants