Skip to content

fix(bitbake): resolve layer misidentification with deepest match#1755

Open
bd-spratikbharti wants to merge 2 commits into
masterfrom
IDETECT-5131
Open

fix(bitbake): resolve layer misidentification with deepest match#1755
bd-spratikbharti wants to merge 2 commits into
masterfrom
IDETECT-5131

Conversation

@bd-spratikbharti
Copy link
Copy Markdown
Collaborator

Description

Summary

  • Fixes BitBake layer misidentification when recipe paths include directory names that match known layer names (e.g., wrlinux).
  • Uses deepest path match (lastIndexOf) instead of first (indexOf) to identify the correct layer.
  • Validates parsed layer against bitbake-layers show-recipes output before accepting.
  • Resolves empty BOM issue caused by failed layer validation.

Details

When recipe paths contained directories whose names matched known layer names, the detector previously matched the first occurrence instead of the actual layer directory.

Example

Path: /wrlinux/layers/meta/recipes/zlib.bb

  • Before: matched wrlinux (parent directory) → failed validation → BOM empty
  • After: matched meta (actual layer) → validation passes → BOM populated

Layer Identification Process

  1. Parse the layer name from the recipe path using the deepest match.
  2. Validate the parsed layer against bitbake-layers show-recipes (authoritative source).
  3. If validation passes, use the parsed layer; otherwise fall back to the first layer from show-recipes.

Impact

  • Ensures correct layer identification.
  • Prevents dropped components.
  • Maintains BOM accuracy for downstream analysis.

- Match deepest folder in path instead of first occurrence
- Validate against authoritative show-recipes source
- Add comprehensive test coverage
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Yocto/BitBake layer identification when recipe paths contain parent directories that collide with known layer names, ensuring the detector selects the correct (deepest) layer and avoids dropping components into an empty BOM.

Changes:

  • Update GraphNodeLabelParser to select the deepest (rightmost) matching layer path segment via lastIndexOf.
  • Validate the path-parsed layer against bitbake-layers show-recipes results in BitbakeDependencyGraphTransformer, falling back to the authoritative layer when invalid.
  • Expand GraphNodeLabelParserTest with multiple collision/determinism scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
detectable/src/main/java/com/blackduck/integration/detectable/detectables/bitbake/parse/GraphNodeLabelParser.java Switches layer matching to deepest/rightmost path match to avoid parent-folder collisions.
detectable/src/main/java/com/blackduck/integration/detectable/detectables/bitbake/transform/BitbakeDependencyGraphTransformer.java Validates parsed layer against show-recipes output and falls back when invalid.
detectable/src/test/java/com/blackduck/integration/detectable/detectables/bitbake/unit/GraphNodeLabelParserTest.java Adds unit tests for collision cases and deterministic parsing behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Prevent crash on empty layer lists, validate graph layer against
authoritative source, and cover new fallback paths in tests.
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.

2 participants