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

Fix: #1370 - restrict bazel projects to pattern BUILD{,.bazel} #1373

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

heubeck
Copy link
Contributor

@heubeck heubeck commented Sep 11, 2024

No description provided.

@@ -1898,7 +1898,7 @@ export async function createJavaBom(path, options) {
// NOTE: This can match BUILD files used by perl, so could lead to errors in some projects
const bazelFiles = getAllFiles(
path,
`${options.multiProject ? "**/" : ""}BUILD*`,
`${options.multiProject ? "**/" : ""}BUILD{,.bazel}`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of looking for BUILD and BUILD.bazel files, it should instead:

  1. WORKSPACE - since that defines a Bazel project (and also WORKSPACE.bazel), and only at the root directory of the project
  2. MODULE.bazel - as an alternative to WORKSPACE in newer versions of Bazel

As the error suggests we can only run Bazel build commands from "below a directory having a WORKSPACE file" so even just looking for BUILD and BUILD.bazel will still result in failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so

`(WORKSPACE{,.bazel}|${options.multiProject ? "**/" : ""}BUILD{,.bazel})`

would be the pattern?

or can't it be covered with the pattern at all as it's a conditional thing, depending on a WORKSPACE file to be present or not?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some bazel projects without any workspace files. Not sure since when workspace was introduced

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to find a WORKSPACE or a MODULE.bazel file at the root of the project, so something like
(WORKSPACE{,.bazel}|MODULE.bazel)

Alternatively you can run bazel info and look for the message
ERROR: The 'info' command is only supported from within a workspace (below a directory having a WORKSPACE file).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try this in a new PR

Copy link
Collaborator

@prabhu prabhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This will fix the immediate problem of incorrectly triggering bazel for gradle projects

@prabhu prabhu merged commit 2748c13 into CycloneDX:master Sep 11, 2024
19 of 21 checks passed
@heubeck heubeck deleted the fix/issue-1370 branch September 12, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants