Skip to content

Commit

Permalink
Fix version parsing in CMakeLists files (#1596)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
asztalosdani authored Jan 24, 2025
1 parent e07b12f commit ea63d5c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13188,7 +13188,9 @@ export function parseCmakeLikeFile(cmakeListFile, pkgType, options = {}) {
let parentVersion = undefined;
// In case of meson.build we can find the version number after the word version
// thanks to our replaces and splits
const versionIndex = tmpB.findIndex((v) => v === "version");
const versionIndex = tmpB.findIndex(
(v) => v?.toLowerCase() === "version",
);
if (versionIndex > -1 && tmpB.length > versionIndex) {
parentVersion = tmpB[versionIndex + 1];
}
Expand Down
12 changes: 12 additions & 0 deletions lib/helpers/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5734,6 +5734,18 @@ test("parseCmakeLikeFile tests", () => {
type: "application",
version: "",
});
retMap = parseCmakeLikeFile(
"./test/data/cmakes/CMakeLists-version.txt",
"generic",
);
expect(retMap.parentComponent).toEqual({
"bom-ref": "pkg:generic/[email protected]",
group: "",
name: "MyProject",
purl: "pkg:generic/[email protected]",
type: "application",
version: "2.1.3",
});
retMap = parseCmakeLikeFile(
"./test/data/cmakes/CMakeLists-tpl.txt",
"generic",
Expand Down
5 changes: 5 additions & 0 deletions test/data/cmakes/CMakeLists-version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.15)

project(MyProject VERSION 2.1.3)

add_executable(myexample example.cpp)
2 changes: 1 addition & 1 deletion types/lib/helpers/utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea63d5c

Please sign in to comment.