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

Parsing the version from CMakeLists.txt is broken #1589

Closed
asztalosdani opened this issue Jan 22, 2025 · 1 comment · Fixed by #1596
Closed

Parsing the version from CMakeLists.txt is broken #1589

asztalosdani opened this issue Jan 22, 2025 · 1 comment · Fixed by #1596

Comments

@asztalosdani
Copy link
Contributor

Running cdxgen does not extract the version from the CMakeLists.txt correctly.
cdxgen version: 11.1.1

How to reproduce:

  1. Copy the following file to an empty folder, and name it CMakeLists.txt
cmake_minimum_required(VERSION 3.15)

project(MyProject VERSION 2.1.3)

add_executable(myexample example.cpp)
  1. Run cdxgen -t cpp -o bom.json in that folder
  2. Open the generated bom.json
  3. The metadata > component > version attribute should be filled, but it is empty.

Additional info
I noticed in the parseCmakeLikeFile() function it looks for lowercase "version".

cdxgen/lib/helpers/utils.js

Lines 13177 to 13180 in 459dfe1

const versionIndex = tmpB.findIndex((v) => v === "version");
if (versionIndex > -1 && tmpB.length > versionIndex) {
parentVersion = tmpB[versionIndex + 1];
}

So I tried changing project(MyProject VERSION 2.1.3) to project(MyProject version 2.1.3), and it extracted the version correctly, but this is not a valid CMakeLists syntax.

Then in

cdxgen/lib/helpers/utils.js

Lines 13182 to 13187 in 459dfe1

parentComponent = {
group: options.projectGroup || "",
name: parentName,
version: parentVersion || options.projectVersion || "",
type: "application",
};

it says, if the version is empty, it gets it from the options.projectVersion, so I tried running it with --project-version=1.2.4, but it did not do anything.

@prabhu
Copy link
Collaborator

prabhu commented Jan 22, 2025

@asztalosdani can you try this and send a PR if it works.

const versionIndex = tmpB.findIndex((v) => v?.toLowerCase() === "version");

We may have to test with some meson.build projects as well. Bonus points if you could add few more unit tests.

asztalosdani added a commit to asztalosdani/cdxgen that referenced this issue Jan 24, 2025
asztalosdani added a commit to asztalosdani/cdxgen that referenced this issue Jan 24, 2025
prabhu pushed a commit that referenced this issue Jan 24, 2025
* Fix version parsing in CMakeLists files #1589

Signed-off-by: Daniel Asztalos <[email protected]>

* Lint fixes

Signed-off-by: asztalosdani <[email protected]>

---------

Signed-off-by: Daniel Asztalos <[email protected]>
Signed-off-by: asztalosdani <[email protected]>
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 a pull request may close this issue.

2 participants