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 build being run for non-Bazel projects, causing errors #1370

Open
MCDong opened this issue Sep 10, 2024 · 3 comments
Open

Bazel build being run for non-Bazel projects, causing errors #1370

MCDong opened this issue Sep 10, 2024 · 3 comments

Comments

@MCDong
Copy link

MCDong commented Sep 10, 2024

In here

https://github.com/CycloneDX/cdxgen/blob/master/index.js#L1899-L1902

 const bazelFiles = getAllFiles(
    path,
    `${options.multiProject ? "**/" : ""}BUILD*`,
    options,
  );

Seems to be matching build.gradle files, and so it tries to run bazel build //...

I get the error message

ERROR: The 'build' command is only supported from within a workspace (below a directory having a WORKSPACE file).
See documentation at https://bazel.build/concepts/build-ref#workspace

1. Check if bazel is installed and available in PATH.
2. Try building your app with bazel prior to invoking cdxgen

I think the getAllFiles should be changed, or it should be looking for Bazel WORKSPACE files instead.

This can be replicated by just cloning this repo, and adding an empty build.gradle file in the root of this repo and running

$ touch build.gradle; CDXGEN_DEBUG_MODE=DEBUG npm exec -- cdxgen . --fail-on-error

Executing 'mvn -fn org.cyclonedx:cyclonedx-maven-plugin:2.8.0:makeAggregateBom -DoutputName=bom -DincludeTestScope=true -q' in /Users/mcdong/work/cdxgen/test
Executing gradle --console plain --build-cache properties in .
Executing gradle --console plain --build-cache dependencies in .
Obtained 25 from this gradle project. De-duping this list ...
Executing bazel build //... in /Users/mcdong/cdxgen
 INFO: not looking for project directory .bazelwrc because of error looking up project directory error="couldn't find WORKSPACE file"
WARNING: Invoking Bazel in batch mode since it is not invoked from within a workspace (below a directory having a WORKSPACE file).
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
ERROR: The 'build' command is only supported from within a workspace (below a directory having a WORKSPACE file).
See documentation at https://bazel.build/concepts/build-ref#workspace

1. Check if bazel is installed and available in PATH.
2. Try building your app with bazel prior to invoking cdxgen
@prabhu
Copy link
Contributor

prabhu commented Sep 11, 2024

@MCDong Great find! Could you send a PR to limit the search to only BUILD and BUILD.bazel? Wondering if we should also introduce a parameter to make it case-sensitive here.

heubeck added a commit to heubeck/cdxgen that referenced this issue Sep 11, 2024
heubeck added a commit to heubeck/cdxgen that referenced this issue Sep 11, 2024
…el}`

Signed-off-by: Florian Heubeck <heubeck@mediamarktsaturn.com>
heubeck added a commit to heubeck/cdxgen that referenced this issue Sep 11, 2024
…el}`

Signed-off-by: Florian Heubeck <heubeck@mediamarktsaturn.com>
@MCDong
Copy link
Author

MCDong commented Sep 11, 2024

Heya :) I have to go through legal approval at my company to submit PRs for an open source project that we use internally (yay bureaucracy) so if you guys have the bandwidth to do it, I'd appreciate it, but otherwise it'll probably take like a week to get the legal approvals to do a PR, which I can do if needed.

But also I think it should look for these files to cover the bases

  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.

@prabhu prabhu closed this as completed in 2748c13 Sep 11, 2024
@prabhu prabhu reopened this Sep 11, 2024
@prabhu
Copy link
Contributor

prabhu commented Sep 11, 2024

Thanks @MCDong for trying. I would still suggest to continue trying to become a contributor to have a more active role in the project. I will keep researching about your suggestion to use workspace and modules and share another PR. Thank you for sharing!

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

No branches or pull requests

2 participants